bug-glibc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bug in md5.c for glibc 2.2.1 through 2.2.4?


From: Eric Sharkey
Subject: Re: bug in md5.c for glibc 2.2.1 through 2.2.4?
Date: Wed, 26 Sep 2001 11:10:23 -0400

> Eric Sharkey <address@hidden> writes:
> 
> > I'm having a problem using the md5sum code in md5.c when processing data
> > in odd-sized chunks.
> 
> Then please provide a test case and create a diff with the current
> version of the source file.  Sending code always has the problem that
> the code in question might differ here.

This is a diff -cb:

***************
*** 226,234 ****
        size_t left_over = ctx->buflen;
        size_t add = 128 - left_over > len ? len : 128 - left_over;
  
-       /* Only put full words in the buffer.  */
-       add -= add % __alignof__ (md5_uint32);
- 
        memcpy (&ctx->buffer[left_over], buffer, add);
        ctx->buflen += add;
  
--- 423,428 ----
***************
*** 249,258 ****
--- 443,466 ----
    /* Process available complete blocks.  */
    if (len > 64)
      {
+       /* check to see if we're properly aligned */
+       if (((unsigned int)buffer)%__alignof__(md5_uint32))
+         {
+           while (len > 64)
+             {
+               memcpy(ctx->buffer,buffer,64);
+               md5_process_block (ctx->buffer, 64, ctx);
+               buffer = (const char *) buffer + 64;
+               len -= 64;
+             }
+         }
+       else
+         {
            md5_process_block (buffer, len & ~63, ctx);
            buffer = (const char *) buffer + (len & ~63);
            len &= 63;
          }
+     }
  
    /* Move remaining bytes in internal buffer.  */
    if (len > 0)


Test program source code is attached.  To compile:

gcc -o md5test md5test.c /usr/lib/libcrypt.a

You need to have md5.h.

The program computes the md5sum of a text buffer three times.  First with
the libcrypt vervsion in one chunk, again with the libcrypt version in two
chunks of odd size, and finally with the fixed version in two chunks.

Results:

c287305c7981aabe7dc3c4a5b43e5535
dc0b60ad6870ef4d7f9d4adf61754d3d
c287305c7981aabe7dc3c4a5b43e5535

Eric Sharkey
<address@hidden>
<address@hidden>

Attachment: md5test.c
Description: md5test.c


reply via email to

[Prev in Thread] Current Thread [Next in Thread]