svn rev #23386: trunk/src/lib/crypto/ builtin/hash_provider/ crypto_tests/ krb/crc32/ ...

ghudson@MIT.EDU ghudson at MIT.EDU
Mon Nov 30 11:12:36 EST 2009


http://src.mit.edu/fisheye/changelog/krb5/?cs=23386
Commit By: ghudson
Log Message:
Make the crc32 hash provider correctly chain multiple input buffers,
so that it returns the same result if you pass it one big buffer or
many small buffers containing the same data.  To do this, change the
contract of mit_crc32 so that the cksum parameter is in-out.



Changed Files:
U   trunk/src/lib/crypto/builtin/hash_provider/hash_crc32.c
U   trunk/src/lib/crypto/crypto_tests/t_crc.c
U   trunk/src/lib/crypto/krb/crc32/crc-32.h
U   trunk/src/lib/crypto/krb/crc32/crc32.c
U   trunk/src/lib/crypto/openssl/hash_provider/hash_crc32.c
Modified: trunk/src/lib/crypto/builtin/hash_provider/hash_crc32.c
===================================================================
--- trunk/src/lib/crypto/builtin/hash_provider/hash_crc32.c	2009-11-30 14:17:06 UTC (rev 23385)
+++ trunk/src/lib/crypto/builtin/hash_provider/hash_crc32.c	2009-11-30 16:12:36 UTC (rev 23386)
@@ -33,17 +33,15 @@
 k5_crc32_hash(unsigned int icount, const krb5_data *input,
               krb5_data *output)
 {
-    unsigned long c, cn;
+    unsigned long c;
     unsigned int i;
 
     if (output->length != CRC32_CKSUM_LENGTH)
         return(KRB5_CRYPTO_INTERNAL);
 
     c = 0;
-    for (i=0; i<icount; i++) {
-        mit_crc32(input[i].data, input[i].length, &cn);
-        c ^= cn;
-    }
+    for (i=0; i<icount; i++)
+        mit_crc32(input[i].data, input[i].length, &c);
 
     store_32_le(c, output->data);
     return(0);

Modified: trunk/src/lib/crypto/crypto_tests/t_crc.c
===================================================================
--- trunk/src/lib/crypto/crypto_tests/t_crc.c	2009-11-30 14:17:06 UTC (rev 23385)
+++ trunk/src/lib/crypto/crypto_tests/t_crc.c	2009-11-30 16:12:36 UTC (rev 23386)
@@ -121,6 +121,7 @@
         block[i] = i % 256;
     times(&before);
     for (i = 0; i < nblk; i++) {
+        cksum = 0;
         mit_crc32(block + i * blksiz, blksiz, &cksum);
     }
 
@@ -136,6 +137,7 @@
 #ifdef CRC32_SHIFT4
     times(&before);
     for (i = 0; i < nblk; i++) {
+        cksum = 0;
         mit_crc32_shift4(block + i * blksiz, blksiz, &cksum);
     }
     times(&after);
@@ -185,11 +187,13 @@
         case STR:
             len = strlen(trial.data);
             typestr = "STR";
+            cksum = 0;
             mit_crc32(trial.data, len, &cksum);
             break;
         case HEX:
             typestr = "HEX";
             gethexstr(trial.data, &len, buf, 4);
+            cksum = 0;
             mit_crc32(buf, len, &cksum);
             break;
         default:

Modified: trunk/src/lib/crypto/krb/crc32/crc-32.h
===================================================================
--- trunk/src/lib/crypto/krb/crc32/crc-32.h	2009-11-30 14:17:06 UTC (rev 23385)
+++ trunk/src/lib/crypto/krb/crc32/crc-32.h	2009-11-30 16:12:36 UTC (rev 23386)
@@ -60,6 +60,7 @@
 
 #define CRC32_CKSUM_LENGTH      4
 
+/* c is in-out to allow chaining; initialize to 0. */
 void
 mit_crc32 (krb5_pointer in, size_t in_length, unsigned long *c);
 

Modified: trunk/src/lib/crypto/krb/crc32/crc32.c
===================================================================
--- trunk/src/lib/crypto/krb/crc32/crc32.c	2009-11-30 14:17:06 UTC (rev 23385)
+++ trunk/src/lib/crypto/krb/crc32/crc32.c	2009-11-30 16:12:36 UTC (rev 23386)
@@ -151,7 +151,7 @@
 mit_crc32(krb5_pointer in, size_t in_length, unsigned long *cksum)
 {
     register u_char *data;
-    register u_long c = 0;
+    register u_long c = *cksum;
     register int idx;
     size_t i;
 
@@ -178,7 +178,7 @@
 mit_crc32_shift4(krb5_pointer in, size_t in_length, unsigned long *cksum)
 {
     register unsigned char *data, b;
-    register unsigned long c = 0;
+    register unsigned long c = *cksum;
     size_t i;
 
     data = (u_char *)in;

Modified: trunk/src/lib/crypto/openssl/hash_provider/hash_crc32.c
===================================================================
--- trunk/src/lib/crypto/openssl/hash_provider/hash_crc32.c	2009-11-30 14:17:06 UTC (rev 23385)
+++ trunk/src/lib/crypto/openssl/hash_provider/hash_crc32.c	2009-11-30 16:12:36 UTC (rev 23386)
@@ -33,17 +33,15 @@
 k5_crc32_hash(unsigned int icount, const krb5_data *input,
               krb5_data *output)
 {
-    unsigned long c, cn;
+    unsigned long c;
     unsigned int i;
 
     if (output->length != CRC32_CKSUM_LENGTH)
         return(KRB5_CRYPTO_INTERNAL);
 
     c = 0;
-    for (i=0; i<icount; i++) {
-        mit_crc32(input[i].data, input[i].length, &cn);
-        c ^= cn;
-    }
+    for (i=0; i<icount; i++)
+        mit_crc32(input[i].data, input[i].length, &c);
 
     store_32_le(c, output->data);
     return(0);




More information about the cvs-krb5 mailing list