]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
minor fixes and cleanups
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Tue, 7 Nov 2000 20:41:25 +0000 (20:41 +0000)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Tue, 7 Nov 2000 20:41:25 +0000 (20:41 +0000)
lib/Makefile.am
lib/gnutls.c
lib/gnutls_cipher.c
lib/gnutls_hash_int.c
lib/gnutls_kx.c

index 4e4e92a1c5d61c0e0a4712c71e24313450812277..7b13218908aae6579c041f0ce6a7dd149460de11 100644 (file)
@@ -9,4 +9,4 @@ libgnutls_la_SOURCES = gnutls.c gnutls_compress.c debug.c gnutls_plaintext.c \
        gnutls_cipher.c gnutls_buffers.c gnutls_handshake.c gnutls_num.c \
        gnutls_errors.c gnutls_algorithms.c gnutls_dh.c gnutls_kx.c \
        gnutls_priority.c gnutls_hash_int.c gnutls_cipher_int.c gnutls_der.c
-libgnutls_la_LDFLAGS = -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)  -ldmalloc
+libgnutls_la_LDFLAGS = -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)
index 775039bab9c981740e2a5a70b34e2696dc4fffdd..075cc64ce532b1f1c9f97a754e25f2849cdb0161 100644 (file)
@@ -133,15 +133,12 @@ int gnutls_deinit(GNUTLS_STATE * state)
 void *_gnutls_cal_PRF_A(MACAlgorithm algorithm, void *secret, int secret_size, void *seed, int seed_size)
 {
        GNUTLS_MAC_HANDLE td1;
-       void *A;
 
        td1 = gnutls_hmac_init(algorithm, secret, secret_size);
 
        gnutls_hmac(td1, seed, seed_size);
 
-       A = gnutls_hmac_deinit(td1);
-
-       return A;
+       return gnutls_hmac_deinit(td1);
 }
 
 
@@ -154,7 +151,7 @@ svoid *gnutls_P_hash(MACAlgorithm algorithm, opaque * secret, int secret_size, o
        GNUTLS_MAC_HANDLE td2;
        opaque *ret;
        void *A, *Atmp;
-       int i = 0, times, copy_bytes = 0, how, blocksize, A_size;
+       int i = 0, times, how, blocksize, A_size;
        void *final;
 
        ret = secure_calloc(1, total_bytes);
@@ -171,6 +168,7 @@ svoid *gnutls_P_hash(MACAlgorithm algorithm, opaque * secret, int secret_size, o
        for (i = 0; i < times; i++) {
                td2 = gnutls_hmac_init(algorithm, secret, secret_size);
 
+               /* here we calculate A[i+1] */
                Atmp = _gnutls_cal_PRF_A(algorithm, secret, secret_size, A, A_size);
                gnutls_free(A);
                A = Atmp;
@@ -179,15 +177,14 @@ svoid *gnutls_P_hash(MACAlgorithm algorithm, opaque * secret, int secret_size, o
                gnutls_hmac(td2, seed, seed_size);
                final = gnutls_hmac_deinit(td2);
 
-               copy_bytes = blocksize;
-               if ((i + 1) * copy_bytes < total_bytes) {
+               if ( (1+i) * blocksize < total_bytes) {
                        how = blocksize;
                } else {
-                       how = total_bytes - (i) * copy_bytes;
+                       how = total_bytes - (i) * blocksize;
                }
 
                if (how > 0) {
-                       memmove(&ret[i * copy_bytes], final, how);
+                       memmove(&ret[i * blocksize], final, how);
                }
                gnutls_free(final);
        }
@@ -230,7 +227,7 @@ svoid *gnutls_PRF(opaque * secret, int secret_size, uint8 * label, int label_siz
        ret = secure_calloc(1, total_bytes);
        gnutls_free(s_seed);
        for (i = 0; i < total_bytes; i++) {
-               ret[i] = o1[i]; //^ o2[i];
+               ret[i] = o1[i] ^ o2[i];
        }
 
        secure_free(o1);
index bf41af06faffa40c6b76aba550a857444e5dca60..7eb55f01a4287ed2d1c2fedcfddafe0b26840725 100644 (file)
@@ -447,7 +447,6 @@ int _gnutls_TLSCiphertext2TLSCompressed(GNUTLS_STATE state,
                            ciphertext->version.minor;
                break;
        case CIPHER_BLOCK:
-
                        if ( (ciphertext->length < blocksize) || (ciphertext->length % blocksize != 0) ) {
                                gnutls_assert();
                                return GNUTLS_E_DECRYPTION_FAILED;
index ca835fcc295667c03b35352d90bd2921162cc52d..c68ac2a201ed3cd5c9e6109342e6e70edd341e77 100644 (file)
 
 #include <defines.h>
 #include <gnutls_int.h>
+#include <mhash.h>
 
+#ifdef USE_MHASH
+/* This file handles all the internal functions that cope with hashes
+ * and hmacs. Currently it uses the functions provided by
+ * the gcrypt library that this can be easily changed.
+ */
+
+MHASH gnutls_hash_init(MACAlgorithm algorithm) {
+
+MHASH ret;
+
+       switch (algorithm) {
+               case GNUTLS_MAC_NULL:
+                       ret = GNUTLS_HASH_FAILED;
+                       break;
+               case GNUTLS_MAC_SHA:
+                       ret = mhash_init( MHASH_SHA1);
+                       if (!ret) return GNUTLS_HASH_FAILED;
+                       break;
+               case GNUTLS_MAC_MD5:
+                       ret = mhash_init( MHASH_MD5);
+                       if (!ret) return GNUTLS_HASH_FAILED;
+                       break;
+               default:
+                       ret = GNUTLS_HASH_FAILED;
+       }
+       
+       return ret;
+}
+
+int gnutls_hash_get_algo_len(MACAlgorithm algorithm) {
+int ret;
+
+       switch (algorithm) {
+               case GNUTLS_MAC_NULL:
+                       ret = 0;
+                       break;
+               case GNUTLS_MAC_SHA:
+                       ret = mhash_get_block_size(MHASH_SHA1);
+                       break;
+               case GNUTLS_MAC_MD5:
+                       ret = mhash_get_block_size(MHASH_MD5);
+                       break;
+               default:
+                       ret = 0;
+       }
+
+return ret;
+
+}
+
+int gnutls_hash(GNUTLS_HASH_HANDLE handle, void* text, int textlen) {
+
+       mhash( handle, text, textlen);
+       return 0;
+}
+
+void* gnutls_hash_deinit(GNUTLS_HASH_HANDLE handle) {
+char* mac;
+int maclen;
+char* ret;
+
+    ret = mhash_end(handle);
+    
+    return ret;
+}
+
+
+GNUTLS_MAC_HANDLE gnutls_hmac_init(MACAlgorithm algorithm, char* key, int keylen) {
+GNUTLS_MAC_HANDLE ret;
+
+       switch (algorithm) {
+               case GNUTLS_MAC_NULL:
+                       ret = GNUTLS_MAC_FAILED;
+                       break;
+               case GNUTLS_MAC_SHA:
+                       ret = mhash_hmac_init( MHASH_SHA1, key, keylen, 0);
+                       if (!ret) ret = GNUTLS_MAC_FAILED;
+                       break;
+               case GNUTLS_MAC_MD5:
+                       ret = mhash_hmac_init( MHASH_MD5, key, keylen, 0);
+                       if (!ret) ret = GNUTLS_MAC_FAILED;
+                       break;
+               default:
+                       ret = GNUTLS_MAC_FAILED;
+       }
+       
+       return ret;
+}
+
+int gnutls_hmac_get_algo_len(MACAlgorithm algorithm) {
+int ret;
+
+       switch (algorithm) {
+               case GNUTLS_MAC_NULL:
+                       ret = 0;
+                       break;
+               case GNUTLS_MAC_SHA:
+                       ret = mhash_get_hash_pblock(MHASH_SHA1);
+                       break;
+               case GNUTLS_MAC_MD5:
+                       ret = mhash_get_hash_pblock(MHASH_MD5);
+                       break;
+               default:
+                       ret = 0;
+       }
+
+return ret;
+
+}
+
+int gnutls_hmac(GNUTLS_MAC_HANDLE handle, void* text, int textlen) {
+
+       mhash( handle, text, textlen);
+       return 0;
+
+}
+
+void* gnutls_hmac_deinit(GNUTLS_MAC_HANDLE handle) {
+char* mac;
+int maclen;
+char* ret;
+
+    ret = mhash_hmac_end(handle);
+    
+    return ret;
+}
+
+#else
 /* This file handles all the internal functions that cope with hashes
  * and hmacs. Currently it uses the functions provided by
  * the gcrypt library that this can be easily changed.
@@ -159,3 +288,4 @@ char* ret;
     return ret;
 }
 
+#endif /* MHASH */
index 0f7de47b76ff427dba0f07767f7a7861abcca234..8da9e3127e9de032557f1c64a985a0ea41e14db0 100644 (file)
@@ -37,7 +37,7 @@ int _gnutls_send_server_kx_message(int cd, GNUTLS_STATE state)
 {
        KXAlgorithm algorithm;
        GNUTLS_MPI x, X, g, p;
-       int n_X, n_g, n_p;
+       size_t n_X, n_g, n_p;
        uint16 _n_X, _n_g, _n_p;
        uint8 *data = NULL;
        uint8 *data_p;
@@ -122,7 +122,7 @@ int _gnutls_send_client_kx_message(int cd, GNUTLS_STATE state)
 {
        KXAlgorithm algorithm;
        GNUTLS_MPI x, X;
-       int n_X;
+       size_t n_X;
        uint16 _n_X;
        uint8 *data;
        int ret = 0;
@@ -130,9 +130,12 @@ int _gnutls_send_client_kx_message(int cd, GNUTLS_STATE state)
        int premaster_size = 0;
        svoid *master;
        char *random = gnutls_malloc(64);
+
 #ifdef HARD_DEBUG
        fprintf(stderr, "Sending client KX message\n");
 #endif
+
+
        memmove(random, state->security_parameters.client_random, 32);
        memmove(&random[32], state->security_parameters.server_random, 32);
        algorithm =
@@ -173,12 +176,14 @@ int _gnutls_send_client_kx_message(int cd, GNUTLS_STATE state)
                    _gnutls_calc_dh_key(state->gnutls_internals.client_Y,
                                        x,
                                        state->gnutls_internals.client_p);
+
                gcry_mpi_print(GCRYMPI_FMT_USG, NULL, &premaster_size,
                               state->gnutls_internals.KEY);
                premaster = secure_malloc(premaster_size);
                gcry_mpi_print(GCRYMPI_FMT_USG, premaster,
                               &premaster_size,
                               state->gnutls_internals.KEY);
+
                /* THIS SHOULD BE DISCARDED */
                gnutls_mpi_release(state->gnutls_internals.KEY);
                gnutls_mpi_release(state->gnutls_internals.client_Y);
@@ -255,13 +260,16 @@ int _gnutls_recv_server_kx_message(int cd, GNUTLS_STATE state)
 {
        KXAlgorithm algorithm;
        uint16 n_Y, n_g, n_p;
-       int _n_Y, _n_g, _n_p;
+       size_t _n_Y, _n_g, _n_p;
        uint8 *data;
        int datasize;
        uint8 *data_p;
        uint8 *data_g;
        uint8 *data_Y;
        int ret = 0, i;
+unsigned char tmpy[2048];
+int ii;
+
 #ifdef HARD_DEBUG
        fprintf(stderr, "Receiving Server KX message\n");
 #endif
@@ -356,7 +364,7 @@ int _gnutls_recv_client_kx_message(int cd, GNUTLS_STATE state)
 {
        KXAlgorithm algorithm;
        uint16 n_Y;
-       int _n_Y;
+       size_t _n_Y;
        uint8 *data;
        int datasize;
        int ret = 0;
@@ -399,8 +407,11 @@ int _gnutls_recv_client_kx_message(int cd, GNUTLS_STATE state)
                        n_Y = byteswap16(n_Y);
 #endif
                        _n_Y = n_Y;
-                       gcry_mpi_scan(&state->gnutls_internals.client_Y,
-                                     GCRYMPI_FMT_USG, &data[2], &_n_Y);
+                       if (gcry_mpi_scan(&state->gnutls_internals.client_Y,
+                                     GCRYMPI_FMT_USG, &data[2], &_n_Y)) {
+                               gnutls_assert();
+                               return GNUTLS_E_MPI_SCAN_FAILED;
+                       }
                        state->gnutls_internals.KEY =
                            gnutls_calc_dh_key(state->
                                               gnutls_internals.client_Y,