2006-05-10 Paul Eggert <eggert@cs.ucla.edu>
authorSimon Josefsson <simon@josefsson.org>
Thu, 11 May 2006 07:33:27 +0000 (07:33 +0000)
committerSimon Josefsson <simon@josefsson.org>
Thu, 11 May 2006 07:33:27 +0000 (07:33 +0000)
* md4.c (rol): Cast right-shift arg to uint32_t to prevent
unwanted sign propagation, e.g., on hosts with 64-bit int.
There still are some problems with reeelly weird theoretical hosts
(e.g., 33-bit int) but it's not worth worrying about now.
* sha1.c (rol): Likewise.
(K1, K2, K3, K4): Remove unnecessary L suffix.

lib/ChangeLog
lib/md4.c
lib/sha1.c

index 87dcee9..28118c9 100644 (file)
@@ -1,6 +1,12 @@
 2006-05-10  Paul Eggert  <eggert@cs.ucla.edu>
 
        * crc.c (crc32_update): Remove unnecessary L suffix.
+       * md4.c (rol): Cast right-shift arg to uint32_t to prevent
+       unwanted sign propagation, e.g., on hosts with 64-bit int.
+       There still are some problems with reeelly weird theoretical hosts
+       (e.g., 33-bit int) but it's not worth worrying about now.
+       * sha1.c (rol): Likewise.
+       (K1, K2, K3, K4): Remove unnecessary L suffix.
 
 2006-05-10  Bruno Haible  <bruno@clisp.org>
 
index 2d943b9..061d3e3 100644 (file)
--- a/lib/md4.c
+++ b/lib/md4.c
@@ -280,7 +280,7 @@ md4_process_bytes (const void *buffer, size_t len, struct md4_ctx *ctx)
 #define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
 #define G(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
 #define H(x, y, z) ((x) ^ (y) ^ (z))
-#define rol(x,n) ( ((x) << (n)) | ((x) >> (32-(n))) )
+#define rol(x, n) (((x) << (n)) | ((uint32_t) (x) >> (32 - (n))))
 #define R1(a,b,c,d,k,s) a=rol(a+F(b,c,d)+x[k],s);
 #define R2(a,b,c,d,k,s) a=rol(a+G(b,c,d)+x[k]+K1,s);
 #define R3(a,b,c,d,k,s) a=rol(a+H(b,c,d)+x[k]+K2,s);
index 0bc29b4..0615020 100644 (file)
@@ -270,10 +270,10 @@ sha1_process_bytes (const void *buffer, size_t len, struct sha1_ctx *ctx)
 /* --- Code below is the primary difference between md5.c and sha1.c --- */
 
 /* SHA1 round constants */
-#define K1 0x5a827999L
-#define K2 0x6ed9eba1L
-#define K3 0x8f1bbcdcL
-#define K4 0xca62c1d6L
+#define K1 0x5a827999
+#define K2 0x6ed9eba1
+#define K3 0x8f1bbcdc
+#define K4 0xca62c1d6
 
 /* Round functions.  Note that F2 is the same as F4.  */
 #define F1(B,C,D) ( D ^ ( B & ( C ^ D ) ) )
@@ -305,7 +305,7 @@ sha1_process_block (const void *buffer, size_t len, struct sha1_ctx *ctx)
   if (ctx->total[0] < len)
     ++ctx->total[1];
 
-#define rol(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
+#define rol(x, n) (((x) << (n)) | ((uint32_t) (x) >> (32 - (n))))
 
 #define M(I) ( tm =   x[I&0x0f] ^ x[(I-14)&0x0f] \
                    ^ x[(I-8)&0x0f] ^ x[(I-3)&0x0f] \