[svn] gcry - r1146 - trunk/cipher

svn author wk cvs at cvs.gnupg.org
Mon Mar 13 09:57:48 CET 2006


Author: wk
Date: 2006-03-13 09:57:47 +0100 (Mon, 13 Mar 2006)
New Revision: 1146

Modified:
   trunk/cipher/ChangeLog
   trunk/cipher/md.c
Log:
Fixed hmac for larger blocksizes algorithms


Modified: trunk/cipher/ChangeLog
===================================================================
--- trunk/cipher/ChangeLog	2006-03-10 10:23:52 UTC (rev 1145)
+++ trunk/cipher/ChangeLog	2006-03-13 08:57:47 UTC (rev 1146)
@@ -1,3 +1,8 @@
+2006-03-12  Brad Hards  <bradh at frogmouth.net>  (wk)
+
+	* md.c (md_open): Use new variable macpads_Bsize instead of
+	hardwiring the block size.  Changed at all places.
+
 2006-03-10  Brad Hards  <bradh at frogmouth.net>  (wk, patch 2005-04-22)
 
 	* md.c, sha256.c:  Add support for SHA-224.

Modified: trunk/cipher/md.c
===================================================================
--- trunk/cipher/md.c	2006-03-10 10:23:52 UTC (rev 1145)
+++ trunk/cipher/md.c	2006-03-13 08:57:47 UTC (rev 1146)
@@ -1,5 +1,5 @@
 /* md.c  -  message digest dispatcher
- * Copyright (C) 1998, 1999, 2002, 2003 Free Software Foundation, Inc.
+ * Copyright (C) 1998, 1999, 2002, 2003, 2006 Free Software Foundation, Inc.
  *
  * This file is part of Libgcrypt.
  *
@@ -101,6 +101,7 @@
   int finalized;
   GcryDigestEntry *list;
   byte *macpads;
+  int macpads_Bsize;             /* Blocksize as used for the HMAC pads. */
 };
 
 
@@ -430,7 +431,13 @@
 
       if (hmac)
 	{
-	  ctx->macpads = gcry_malloc_secure (128);
+	  if ( (GCRY_MD_SHA384 == algo) || (GCRY_MD_SHA512 == algo) ) {
+	    ctx->macpads_Bsize = 128;
+	    ctx->macpads = gcry_malloc_secure (2*(ctx->macpads_Bsize));
+	  } else {
+	    ctx->macpads_Bsize = 64;
+	    ctx->macpads = gcry_malloc_secure (2*(ctx->macpads_Bsize));
+	  }
 	  if (! ctx->macpads)
 	    {
 	      md_close (hd);
@@ -592,14 +599,14 @@
       b->debug = NULL;
       if (a->macpads)
 	{
-	  b->macpads = gcry_malloc_secure (128);
+	  b->macpads = gcry_malloc_secure (2*(a->macpads_Bsize));
 	  if (! b->macpads)
 	    {
 	      md_close (bhd);
 	      err = gpg_err_code_from_errno (errno);
 	    }
 	  else
-	    memcpy (b->macpads, a->macpads, 128);
+	    memcpy (b->macpads, a->macpads, (2*(a->macpads_Bsize)));
 	}
     }
 
@@ -662,7 +669,7 @@
       (*r->digest->init) (&r->context.c);
     }
   if (a->ctx->macpads)
-    md_write (a, a->ctx->macpads, 64); /* inner pad */
+    md_write (a, a->ctx->macpads, a->ctx->macpads_Bsize); /* inner pad */
 }
 
 static void
@@ -686,7 +693,7 @@
 
   if (a->ctx->macpads)
     {
-      wipememory (a->ctx->macpads, 128);
+      wipememory (a->ctx->macpads, 2*(a->ctx->macpads_Bsize));
       gcry_free(a->ctx->macpads);
     }
 
@@ -755,7 +762,7 @@
 
       if (err)
 	_gcry_fatal_error (err, NULL);
-      md_write (om, a->ctx->macpads+64, 64);
+      md_write (om, (a->ctx->macpads)+(a->ctx->macpads_Bsize), a->ctx->macpads_Bsize);
       md_write (om, p, dlen);
       md_final (om);
       /* Replace our digest with the mac (they have the same size). */
@@ -786,12 +793,12 @@
       assert ( keylen <= 64 );
     }
 
-  memset ( hd->ctx->macpads, 0, 128 );
+  memset ( hd->ctx->macpads, 0, 2*(hd->ctx->macpads_Bsize) );
   ipad = hd->ctx->macpads;
-  opad = hd->ctx->macpads+64;
+  opad = (hd->ctx->macpads)+(hd->ctx->macpads_Bsize);
   memcpy ( ipad, key, keylen );
   memcpy ( opad, key, keylen );
-  for (i=0; i < 64; i++ ) 
+  for (i=0; i < (hd->ctx->macpads_Bsize); i++ ) 
     {
       ipad[i] ^= 0x36;
       opad[i] ^= 0x5c;




More information about the Gnupg-commits mailing list