diff lib/md5.c @ 16860:a3feab896112

crypto: fix bug in large buffer handling Problem reported by Serge Belyshev for glibc in <http://sourceware.org/bugzilla/show_bug.cgi?id=14090> and for gnulib in <http://lists.gnu.org/archive/html/bug-gnulib/2012-05/msg00226.html>. * lib/md4.c (md4_process_block): * lib/md5.c (md5_process_block): * lib/sha1.c (sha1_process_block): * lib/sha256.c (sha256_process_block): Don't assume the buffer length is less than 2**32.
author Paul Eggert <eggert@cs.ucla.edu>
date Fri, 18 May 2012 13:10:42 -0700
parents bb182ee4a09d
children f3fa9d9507c7
line wrap: on
line diff
--- a/lib/md5.c
+++ b/lib/md5.c
@@ -312,13 +312,13 @@
   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.  */