]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
avoid using malloc for small buffers.
authorNikos Mavrogiannopoulos <nmav@crystal.(none)>
Sat, 27 Sep 2008 21:40:11 +0000 (00:40 +0300)
committerNikos Mavrogiannopoulos <nmav@crystal.(none)>
Sat, 27 Sep 2008 21:40:11 +0000 (00:40 +0300)
lib/gnutls_algorithms.c
lib/gnutls_constate.c
lib/gnutls_int.h

index 124774ffaecd2b28c90d689134a39a17fda92526..d37d494470477da6d437867c9971c6ff741e61f7 100644 (file)
@@ -156,6 +156,8 @@ typedef struct gnutls_cipher_entry gnutls_cipher_entry;
  * Do not add any algorithms in other modes (avoid modified algorithms).
  * View first: "The order of encryption and authentication for
  * protecting communications" by Hugo Krawczyk - CRYPTO 2001
+ *
+ * Make sure to updated MAX_CIPHER_BLOCK_SIZE and MAX_CIPHER_KEY_SIZE as well.
  */
 static const gnutls_cipher_entry algorithms[] = {
   {"AES-256-CBC", GNUTLS_CIPHER_AES_256_CBC, 16, 32, CIPHER_BLOCK, 16, 0},
index 946e59ad8a756faa86ad1c9fb7917d406e8a46bf..5252643b5c1e29867b69d13f2624374c2ab2cb64 100644 (file)
@@ -63,6 +63,8 @@ _gnutls_set_keys (gnutls_session_t session, int hash_size, int IV_size,
   int pos, ret;
   int block_size;
   char buf[65];
+  /* avoid using malloc */
+  opaque key_block[2 * MAX_HASH_SIZE + 2 * MAX_CIPHER_KEY_SIZE + 2 * MAX_CIPHER_BLOCK_SIZE];
 
   if (session->cipher_specs.generated_keys != 0)
     {
@@ -77,9 +79,6 @@ _gnutls_set_keys (gnutls_session_t session, int hash_size, int IV_size,
   if (export_flag == 0)
     block_size += 2 * IV_size;
 
-  /* avoid using malloc */
-  opaque key_block[block_size];
-
   memcpy (rnd, session->security_parameters.server_random,
          GNUTLS_RANDOM_SIZE);
   memcpy (&rnd[GNUTLS_RANDOM_SIZE],
@@ -294,7 +293,7 @@ _gnutls_set_keys (gnutls_session_t session, int hash_size, int IV_size,
     }
   else if (IV_size > 0 && export_flag != 0)
     {
-      opaque iv_block[IV_size * 2];
+      opaque iv_block[MAX_CIPHER_BLOCK_SIZE * 2];
 
       if (session->security_parameters.version == GNUTLS_SSL3)
        {                       /* SSL 3 */
index 0dba6510941768f5a34715416830bbbb1e157c4c..cc7a3256a16cfe77cf0813c0b7523631f3be76fb 100644 (file)
@@ -82,6 +82,8 @@ typedef struct
 /* The maximum digest size of hash algorithms. 
  */
 #define MAX_HASH_SIZE 64
+#define MAX_CIPHER_BLOCK_SIZE 16
+#define MAX_CIPHER_KEY_SIZE 32
 
 #define MAX_LOG_SIZE 1024      /* maximum size of log message */
 #define MAX_SRP_USERNAME 128