From 11fdc4d4960ae648e9f921f007dcc2f239abd22b Mon Sep 17 00:00:00 2001 From: Simon Josefsson Date: Thu, 11 May 2006 07:33:27 +0000 Subject: [PATCH] 2006-05-10 Paul Eggert * 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 | 6 ++++++ lib/md4.c | 2 +- lib/sha1.c | 10 +++++----- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/ChangeLog b/lib/ChangeLog index 87dcee997..28118c9d0 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,6 +1,12 @@ 2006-05-10 Paul Eggert * 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 diff --git a/lib/md4.c b/lib/md4.c index 2d943b9f8..061d3e3d5 100644 --- 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); diff --git a/lib/sha1.c b/lib/sha1.c index 0bc29b4e2..061502082 100644 --- a/lib/sha1.c +++ b/lib/sha1.c @@ -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] \ -- 2.11.0