summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2000-11-12 09:31:39 +0000
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2000-11-12 09:31:39 +0000
commit61d9dae537e5cd96f70d459edbc03f45f83d2556 (patch)
treec22cecfe46e6e70ba5d6d7fc78b488c24457bb1b /lib
parent54dde0394e0222a8177f4d81af7efe12c3e8c879 (diff)
downloadgnutls-61d9dae537e5cd96f70d459edbc03f45f83d2556.tar.gz
added hooks for both mhash and mcrypt
Diffstat (limited to 'lib')
-rw-r--r--lib/gnutls_algorithms.c2
-rw-r--r--lib/gnutls_cipher.c4
-rw-r--r--lib/gnutls_cipher_int.c37
-rw-r--r--lib/gnutls_cipher_int.h15
-rw-r--r--lib/gnutls_hash_int.c17
-rw-r--r--lib/gnutls_int.h10
6 files changed, 66 insertions, 19 deletions
diff --git a/lib/gnutls_algorithms.c b/lib/gnutls_algorithms.c
index 8b19372878..bd3c57b086 100644
--- a/lib/gnutls_algorithms.c
+++ b/lib/gnutls_algorithms.c
@@ -38,7 +38,7 @@ typedef struct gnutls_cipher_entry gnutls_cipher_entry;
static gnutls_cipher_entry algorithms[] = {
GNUTLS_CIPHER_ENTRY(GNUTLS_3DES, 8, 24, 1, 8, -1),
- GNUTLS_CIPHER_ENTRY(GNUTLS_ARCFOUR, 1, 16, 0, 0, -2),
+ GNUTLS_CIPHER_ENTRY(GNUTLS_ARCFOUR, 1, 16, 0, 0, -1),
GNUTLS_CIPHER_ENTRY(GNUTLS_NULL, 1, 0, 0, 0, -1),
{0}
};
diff --git a/lib/gnutls_cipher.c b/lib/gnutls_cipher.c
index 716ef51b76..e82d4156fa 100644
--- a/lib/gnutls_cipher.c
+++ b/lib/gnutls_cipher.c
@@ -146,11 +146,11 @@ int _gnutls_connection_state_init(GNUTLS_STATE state)
gnutls_free(state->connection_state.read_mac_secret);
if (state->connection_state.read_cipher_state != NULL)
- gcry_cipher_close(state->
+ gnutls_cipher_deinit(state->
connection_state.read_cipher_state);
if (state->connection_state.write_cipher_state != NULL)
- gcry_cipher_close(state->
+ gnutls_cipher_deinit(state->
connection_state.write_cipher_state);
gnutls_free(state->connection_state.read_compression_state);
diff --git a/lib/gnutls_cipher_int.c b/lib/gnutls_cipher_int.c
index 8cfd039000..8c6345c2aa 100644
--- a/lib/gnutls_cipher_int.c
+++ b/lib/gnutls_cipher_int.c
@@ -19,8 +19,9 @@
*/
#include <defines.h>
-#include "gnutls_int.h"
-#include "gnutls_errors.h"
+#include <gnutls_int.h>
+#include <gnutls_errors.h>
+#include <gnutls_cipher_int.h>
GNUTLS_CIPHER_HANDLE gnutls_cipher_init( BulkCipherAlgorithm cipher, void* key, int keysize, void* iv, int ivsize)
{
@@ -31,14 +32,32 @@ GNUTLS_CIPHER_HANDLE ret;
ret = GNUTLS_CIPHER_FAILED;
break;
case GNUTLS_3DES:
+#ifdef USE_MCRYPT
+ ret = mcrypt_module_open( "tripledes", NULL, "cbc", NULL);
+#else
ret = gcry_cipher_open(GCRY_CIPHER_3DES, GCRY_CIPHER_MODE_CBC, 0);
+#endif
+ break;
+ case GNUTLS_ARCFOUR:
+#ifdef USE_MCRYPT
+ ret = mcrypt_module_open( "arcfour", NULL, "stream", NULL);
+#else
+ ret = GNUTLS_CIPHER_FAILED;
+#endif
break;
default:
ret = GNUTLS_CIPHER_FAILED;
}
- if (ret!=NULL) {
+ if (ret!=GNUTLS_CIPHER_FAILED) {
+#ifdef USE_MCRYPT
+ /* ivsize is assumed to be blocksize */
+ if ( mcrypt_generic_init( ret, key, keysize, iv) < 0) {
+ return GNUTLS_CIPHER_FAILED;
+ };
+#else
gcry_cipher_setkey(ret, key, keysize);
gcry_cipher_setiv(ret, iv, ivsize);
+#endif
}
return ret;
@@ -46,20 +65,32 @@ return ret;
int gnutls_cipher_encrypt(GNUTLS_CIPHER_HANDLE handle, void* text, int textlen) {
if (handle!=NULL) {
+#ifdef USE_MCRYPT
+ mcrypt_generic( handle, text, textlen);
+#else
gcry_cipher_encrypt( handle, text, textlen, text, textlen);
+#endif
}
return 0;
}
int gnutls_cipher_decrypt(GNUTLS_CIPHER_HANDLE handle, void* ciphertext, int ciphertextlen) {
if (handle!=NULL) {
+#ifdef USE_MCRYPT
+ mdecrypt_generic( handle, ciphertext, ciphertextlen);
+#else
gcry_cipher_decrypt( handle, ciphertext, ciphertextlen, ciphertext, ciphertextlen);
+#endif
}
return 0;
}
void gnutls_cipher_deinit(GNUTLS_CIPHER_HANDLE handle) {
if (handle!=NULL) {
+#ifdef USE_MCRYPT
+ mcrypt_generic_end( handle);
+#else
gcry_cipher_close(handle);
+#endif
}
}
diff --git a/lib/gnutls_cipher_int.h b/lib/gnutls_cipher_int.h
index d3eab5d489..6cba6eca0f 100644
--- a/lib/gnutls_cipher_int.h
+++ b/lib/gnutls_cipher_int.h
@@ -1,4 +1,19 @@
+#ifndef GNUTLS_CIPHER_INT
+# define GNUTLS_CIPHER_INT
+
+#ifdef USE_MCRYPT
+# include <mcrypt.h>
+# define GNUTLS_CIPHER_HANDLE MCRYPT
+# define GNUTLS_CIPHER_FAILED MCRYPT_FAILED
+#else
+# include <gcrypt.h>
+# define GNUTLS_CIPHER_HANDLE GCRY_CIPHER_HD
+# define GNUTLS_CIPHER_FAILED NULL
+#endif
+
GNUTLS_CIPHER_HANDLE gnutls_cipher_init( BulkCipherAlgorithm cipher, void* key, int keysize, void* iv, int ivsize);
int gnutls_cipher_encrypt(GNUTLS_CIPHER_HANDLE handle, void* text, int textlen);
int gnutls_cipher_decrypt(GNUTLS_CIPHER_HANDLE handle, void* ciphertext, int ciphertextlen);
void gnutls_cipher_deinit(GNUTLS_CIPHER_HANDLE handle);
+
+#endif /* GNUTLS_CIPHER_INT */
diff --git a/lib/gnutls_hash_int.c b/lib/gnutls_hash_int.c
index f071500bcf..a2856c173b 100644
--- a/lib/gnutls_hash_int.c
+++ b/lib/gnutls_hash_int.c
@@ -37,7 +37,7 @@ GNUTLS_HASH_HANDLE ret;
break;
case GNUTLS_MAC_SHA:
#ifdef USE_MHASH
- ret = mhash_init( MHASH_SHA1);
+ ret = mhash_init_m( MHASH_SHA1, gnutls_malloc);
#else
ret = gcry_md_open( GCRY_MD_SHA1, 0);
#endif
@@ -45,7 +45,7 @@ GNUTLS_HASH_HANDLE ret;
break;
case GNUTLS_MAC_MD5:
#ifdef USE_MHASH
- ret = mhash_init( MHASH_SHA1);
+ ret = mhash_init_m( MHASH_MD5, gnutls_malloc);
#else
ret = gcry_md_open( GCRY_MD_MD5, 0);
#endif
@@ -74,7 +74,7 @@ int ret;
break;
case GNUTLS_MAC_MD5:
#ifdef USE_MHASH
- ret = mhash_get_block_size(MHASH_SHA1);
+ ret = mhash_get_block_size(MHASH_MD5);
#else
ret = gcry_md_get_algo_dlen( GCRY_MD_MD5);
#endif
@@ -88,8 +88,11 @@ return ret;
}
int gnutls_hash(GNUTLS_HASH_HANDLE handle, void* text, int textlen) {
-
+#ifdef USE_MHASH
+ mhash( handle, text, textlen);
+#else
gcry_md_write( handle, text, textlen);
+#endif
return 0;
}
@@ -122,7 +125,7 @@ GNUTLS_MAC_HANDLE ret;
break;
case GNUTLS_MAC_SHA:
#ifdef USE_MHASH
- ret = mhash_hmac_init( MHASH_SHA1, key, keylen, 0);
+ ret = mhash_hmac_init_m( MHASH_SHA1, key, keylen, 0, gnutls_malloc);
#else
ret = gcry_md_open( GCRY_MD_SHA1, GCRY_MD_FLAG_HMAC);
#endif
@@ -130,7 +133,7 @@ GNUTLS_MAC_HANDLE ret;
break;
case GNUTLS_MAC_MD5:
#ifdef USE_MHASH
- ret = mhash_hmac_init( MHASH_SHA1, key, keylen, 0);
+ ret = mhash_hmac_init_m( MHASH_MD5, key, keylen, 0, gnutls_malloc);
#else
ret = gcry_md_open( GCRY_MD_MD5, GCRY_MD_FLAG_HMAC);
#endif
@@ -162,7 +165,7 @@ int ret;
break;
case GNUTLS_MAC_MD5:
#ifdef USE_MHASH
- ret = mhash_get_block_size(MHASH_SHA1);
+ ret = mhash_get_block_size(MHASH_MD5);
#else
ret = gcry_md_get_algo_dlen( GCRY_MD_MD5);
#endif
diff --git a/lib/gnutls_int.h b/lib/gnutls_int.h
index 432f047e5f..6632f41e7c 100644
--- a/lib/gnutls_int.h
+++ b/lib/gnutls_int.h
@@ -2,7 +2,7 @@
#define GNUTLS_INT_H
-#undef HARD_DEBUG
+#define HARD_DEBUG
#undef READ_DEBUG
#undef WRITE_DEBUG
#define DEBUG
@@ -11,12 +11,9 @@
#define MAX24 16777215
#define MAX16 65535
-
-/* for symmetric ciphers */
-#define GNUTLS_CIPHER_HANDLE GCRY_CIPHER_HD
-#define GNUTLS_CIPHER_FAILED NULL
-
/* for big numbers support */ /* FIXME */
+#include <gcrypt.h>
+
#define GNUTLS_MPI MPI
#define gnutls_mpi_release mpi_release
@@ -108,6 +105,7 @@ typedef enum MACAlgorithm MACAlgorithm;
typedef enum CompressionMethod CompressionMethod;
#include <gnutls_hash_int.h>
+#include <gnutls_cipher_int.h>
typedef struct {
ConnectionEnd entity;