From 9430b6ff4a58adb69ef4cf74f1245fd5b3b313dd Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sat, 19 May 2012 14:50:15 +1000 Subject: [PATCH] Fix md5 calculaton on blocks larger then 2^32. Bug reproduced and debugged by Serge Belyshev. Patch by Paul Eggert. --- md5.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/md5.c b/md5.c index 665ed3b..72d4fcd 100644 --- a/md5.c +++ b/md5.c @@ -322,13 +322,13 @@ md5_process_block (const void *buffer, size_t len, struct md5_ctx *ctx) uint32_t B = ctx->B; uint32_t C = ctx->C; uint32_t D = ctx->D; + uint32_t lolen = len; /* First increment the byte count. RFC 1321 specifies the possible length of the file up to 2^64 bits. Here we only compute the number of bytes. Do a double word increment. */ - ctx->total[0] += len; - if (ctx->total[0] < len) - ++ctx->total[1]; + ctx->total[0] += lolen; + ctx->total[1] += (len >> 31 >> 1) + (ctx->total[0] < lolen); /* Process all bytes in the buffer with 64 bytes in each round of the loop. */