From: Nikos Mavrogiannopoulos Date: Sun, 12 Nov 2000 09:31:39 +0000 (+0000) Subject: added hooks for both mhash and mcrypt X-Git-Tag: gnutls0-0-4~18 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=61d9dae537e5cd96f70d459edbc03f45f83d2556;p=thirdparty%2Fgnutls.git added hooks for both mhash and mcrypt --- diff --git a/Makefile.am b/Makefile.am index 6499cf7e8f..c75c46cf2e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,5 @@ ## Process this file with automake to produce Makefile.in -EXTRA_DIST = gcrypt.m4 +EXTRA_DIST = SUBDIRS = lib src doc \ No newline at end of file diff --git a/acconfig.h b/acconfig.h index 2098c23e2d..b0c9660f6f 100644 --- a/acconfig.h +++ b/acconfig.h @@ -3,6 +3,9 @@ #undef NAME_OF_DEV_URANDOM #undef HAVE_DEV_RANDOM +#undef USE_MHASH +#undef USE_MCRYPT + #undef PACKAGE #undef VERSION diff --git a/configure.in b/configure.in index 6f9919f8c8..3b312fbfaf 100644 --- a/configure.in +++ b/configure.in @@ -66,6 +66,25 @@ AC_ARG_ENABLE(maintainer-mode, opt_maintainer_mode=$enableval) AC_MSG_RESULT($opt_maintainer_mode) +AC_ARG_WITH( mcrypt, [ --with-mcrypt enable mcrypt support], + [ AC_CHECK_LIB(dl, dlopen) + AC_CHECK_LIB(mcrypt, mcrypt_module_open, + LIBS="${LIBS} -lmcrypt" + AC_DEFINE(USE_MCRYPT), + [ + AC_CHECK_LIB(dld, dld_init) + AC_CHECK_LIB(ltdl, lt_dlinit) + AC_CHECK_LIB(mcrypt, mcrypt_enc_get_key_size, + LIBS="${LIBS} -lmcrypt" + AC_DEFINE(USE_MCRYPT), + AC_MSG_ERROR("You need libmcrypt 2.4.x or libmcrypt-nm to compile this program. http://mcrypt.hellug.gr")) + ]) + ] + +) + +AC_ARG_WITH( mhash, [ --with-mhash enable mhash support], + [AC_CHECK_LIB(mhash, mhash_init_m, AC_DEFINE(USE_MHASH))]) if test $ac_cv_prog_gcc != no; then CFLAGS="${CFLAGS} -O2 -g -ffast-math" 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 -#include "gnutls_int.h" -#include "gnutls_errors.h" +#include +#include +#include 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 +# define GNUTLS_CIPHER_HANDLE MCRYPT +# define GNUTLS_CIPHER_FAILED MCRYPT_FAILED +#else +# include +# 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 + #define GNUTLS_MPI MPI #define gnutls_mpi_release mpi_release @@ -108,6 +105,7 @@ typedef enum MACAlgorithm MACAlgorithm; typedef enum CompressionMethod CompressionMethod; #include +#include typedef struct { ConnectionEnd entity;