* lib/sha1.c (sha1_process_block):
* lib/sha256.c (sha256_process_block):
Don't assume the buffer length is less than 2**32.
+ * lib/sha512.c (sha512_process_block): Likewise.
+ Here, the bug is present only in the rare case where the host does
+ not support uint64_t; use u64size to work around the problem.
+ * lib/u64.h (u64size): New macro.
2012-05-15 Pádraig Brady <P@draigBrady.com>
u64 f = ctx->state[5];
u64 g = ctx->state[6];
u64 h = ctx->state[7];
+ u64 len64 = u64size (len);
/* First increment the byte count. FIPS PUB 180-2 specifies the possible
length of the file up to 2^128 bits. Here we only compute the
number of bytes. Do a double word increment. */
- ctx->total[0] = u64plus (ctx->total[0], u64lo (len));
- if (u64lt (ctx->total[0], u64lo (len)))
+ ctx->total[0] = u64plus (ctx->total[0], len64);
+ if (u64lt (ctx->total[0], len64))
ctx->total[1] = u64plus (ctx->total[1], u64lo (1));
#define S0(x) u64xor (u64rol(x, 63), u64xor (u64rol (x, 56), u64shr (x, 7)))
# define u64hilo(hi, lo) ((u64) (((u64) (hi) << 32) + (lo)))
# define u64init(hi, lo) u64hilo (hi, lo)
# define u64lo(x) ((u64) (x))
+# define u64size(x) u64lo (x)
# define u64lt(x, y) ((x) < (y))
# define u64and(x, y) ((x) & (y))
# define u64or(x, y) ((x) | (y))
return r;
}
+/* Return a u64 value representing SIZE. */
+static inline u64
+u64size (size_t size)
+{
+ u64 r;
+ r.hi = size >> 31 >> 1;
+ r.lo = size;
+ return r;
+}
+
/* Return X < Y. */
static inline int
u64lt (u64 x, u64 y)