commit 5491644e85480586da58e881e6a9bae1c4be947b
parent de33d4594ea8b0e933c82c7f9108a43945870f97
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date: Mon, 5 Feb 2024 00:05:42 +0100
Fixed SHA-512/256 calculation for unrealistically large volumes
Fixed loss of one bit when 2 EiB (exabytes) or more processed by
a single step after previously processing more then 2 EiB.
Diffstat:
1 file changed, 4 insertions(+), 0 deletions(-)
diff --git a/src/microhttpd/sha512_256.c b/src/microhttpd/sha512_256.c
@@ -475,6 +475,10 @@ MHD_SHA512_256_update (struct Sha512_256Ctx *ctx,
equals (count % SHA512_256_BLOCK_SIZE) for this block size. */
bytes_have = (unsigned int) (ctx->count & (SHA512_256_BLOCK_SIZE - 1));
ctx->count += length;
+#if SIZEOF_SIZE_T > 7
+ if (length > ctx->count)
+ ctx->count_bits_hi += 1U << 3; /* Value wrap */
+#endif /* SIZEOF_SIZE_T > 7 */
count_hi = ctx->count >> 61;
if (0 != count_hi)
{