This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: sha512.c 32-bit warning
> ctx->total[TOTAL128_high] += ((len >> 63 >> 1)
> + (ctx->total[TOTAL128_low] < lolen));
>
> and total is uint64_t.
But LEN is size_t, which is what matters. I fixed it thusly. But either
version is completely bizarre, since LEN>>64 is always going to be zero.
This looks like it was written to support a size_t of larger than 64 bits,
which seems utterly pointless.
Thanks,
Roland
2012-08-15 Roland McGrath <roland@hack.frob.com>
* crypt/sha512.c (sha512_process_block) [!USE_TOTAL128]: Avoid
shifting LEN more than 31 bits at once.
diff --git a/crypt/sha512.c b/crypt/sha512.c
index bec7bb3..0675c94 100644
--- a/crypt/sha512.c
+++ b/crypt/sha512.c
@@ -125,7 +125,7 @@ sha512_process_block (const void *buffer, size_t len, struct sha512_ctx *ctx)
#else
uint64_t lolen = len;
ctx->total[TOTAL128_low] += lolen;
- ctx->total[TOTAL128_high] += ((len >> 63 >> 1)
+ ctx->total[TOTAL128_high] += ((len >> 31 >> 31 >> 2)
+ (ctx->total[TOTAL128_low] < lolen));
#endif