bug-gnulib
[Top][All Lists]
Advanced

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

md5 cleanup


From: Simon Josefsson
Subject: md5 cleanup
Date: Sun, 23 Oct 2005 16:40:24 +0200
User-agent: Gnus/5.110004 (No Gnus v0.4) Emacs/22.0.50 (gnu/linux)

How about this?  Similar to the md4 fix.

Caveat: I had md5 self test failures on x86-solaris recently, but
could not figure out what the reason was.  I replaced the md5.?  files
with the files from coreutils 4.5.5 to see if any changes we have
applied to gnulib recently caused the problem, but I got the same
error.  So I doubt the md5 code itself was the problem.

2005-10-23  Simon Josefsson  <address@hidden>

        * md5.h, md5.c: Simplify buffer handling visavi alignment, same as
        recent md4 change.

Index: lib/md5.h
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/md5.h,v
retrieving revision 1.19
diff -u -p -r1.19 md5.h
--- lib/md5.h   17 Oct 2005 12:55:00 -0000      1.19
+++ lib/md5.h   23 Oct 2005 14:39:36 -0000
@@ -70,7 +70,7 @@ struct md5_ctx
 
   uint32_t total[2];
   uint32_t buflen;
-  char buffer[128] __attribute__ ((__aligned__ (__alignof__ (uint32_t))));
+  uint32_t buffer[32];
 };
 
 /*
Index: lib/md5.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/md5.c,v
retrieving revision 1.21
diff -u -p -r1.21 md5.c
--- lib/md5.c   17 Oct 2005 12:55:00 -0000      1.21
+++ lib/md5.c   23 Oct 2005 14:39:36 -0000
@@ -116,12 +116,12 @@ md5_finish_ctx (struct md5_ctx *ctx, voi
     ++ctx->total[1];
 
   pad = bytes >= 56 ? 64 + 56 - bytes : 56 - bytes;
-  memcpy (&ctx->buffer[bytes], fillbuf, pad);
+  memcpy (&((char*)ctx->buffer)[bytes], fillbuf, pad);
 
   /* Put the 64-bit file length in *bits* at the end of the buffer.  */
-  *(uint32_t *) &ctx->buffer[bytes + pad] = SWAP (ctx->total[0] << 3);
-  *(uint32_t *) &ctx->buffer[bytes + pad + 4] = SWAP ((ctx->total[1] << 3) |
-                                                       (ctx->total[0] >> 29));
+  ctx->buffer[(bytes + pad) / 4] = SWAP (ctx->total[0] << 3);
+  ctx->buffer[(bytes + pad) / 4 + 1] = SWAP ((ctx->total[1] << 3) |
+                                            (ctx->total[0] >> 29));
 
   /* Process last bytes.  */
   md5_process_block (ctx->buffer, bytes + pad + 8, ctx);
@@ -225,7 +225,7 @@ md5_process_bytes (const void *buffer, s
       size_t left_over = ctx->buflen;
       size_t add = 128 - left_over > len ? len : 128 - left_over;
 
-      memcpy (&ctx->buffer[left_over], buffer, add);
+      memcpy (&((char*)ctx->buffer)[left_over], buffer, add);
       ctx->buflen += add;
 
       if (ctx->buflen > 64)
@@ -234,7 +234,7 @@ md5_process_bytes (const void *buffer, s
 
          ctx->buflen &= 63;
          /* The regions in the following copy operation cannot overlap.  */
-         memcpy (ctx->buffer, &ctx->buffer[(left_over + add) & ~63],
+         memcpy (ctx->buffer, &((char*)ctx->buffer)[(left_over + add) & ~63],
                  ctx->buflen);
        }
 
@@ -275,13 +275,13 @@ md5_process_bytes (const void *buffer, s
     {
       size_t left_over = ctx->buflen;
 
-      memcpy (&ctx->buffer[left_over], buffer, len);
+      memcpy (&((char*)ctx->buffer)[left_over], buffer, len);
       left_over += len;
       if (left_over >= 64)
        {
          md5_process_block (ctx->buffer, 64, ctx);
          left_over -= 64;
-         memcpy (ctx->buffer, &ctx->buffer[64], left_over);
+         memcpy (ctx->buffer, &ctx->buffer[16], left_over);
        }
       ctx->buflen = left_over;
     }




reply via email to

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