* md4.c, md4.c: Simplify buffer handling visavi alignment,
authorSimon Josefsson <simon@josefsson.org>
Sat, 22 Oct 2005 16:32:14 +0000 (16:32 +0000)
committerSimon Josefsson <simon@josefsson.org>
Sat, 22 Oct 2005 16:32:14 +0000 (16:32 +0000)
suggested by Bruno Haible <bruno@clisp.org>.

lib/ChangeLog
lib/md4.c
lib/md4.h

index 2683822..a35c4c5 100644 (file)
@@ -1,5 +1,10 @@
 2005-10-22  Simon Josefsson  <jas@extundo.com>
 
+       * md4.c, md4.c: Simplify buffer handling visavi alignment,
+       suggested by Bruno Haible <bruno@clisp.org>.
+
+2005-10-22  Simon Josefsson  <jas@extundo.com>
+
        * crc.h: Include stddef.h, for size_t.
 
 2005-10-21  Simon Josefsson  <jas@extundo.com>
index 5c72430..e5f5d54 100644 (file)
--- a/lib/md4.c
+++ b/lib/md4.c
@@ -100,12 +100,12 @@ md4_finish_ctx (struct md4_ctx *ctx, void *resbuf)
     ++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.  */
   md4_process_block (ctx->buffer, bytes + pad + 8, ctx);
@@ -208,7 +208,7 @@ md4_process_bytes (const void *buffer, size_t len, struct md4_ctx *ctx)
       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)
@@ -217,7 +217,7 @@ md4_process_bytes (const void *buffer, size_t len, struct md4_ctx *ctx)
 
          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);
        }
 
@@ -258,13 +258,13 @@ md4_process_bytes (const void *buffer, size_t len, struct md4_ctx *ctx)
     {
       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)
        {
          md4_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;
     }
index 24dec79..b4f5955 100644 (file)
--- a/lib/md4.h
+++ b/lib/md4.h
@@ -22,7 +22,7 @@
 # include <stdio.h>
 # include <stdint.h>
 
-#define MD4_DIGEST_SIZE 16
+# define MD4_DIGEST_SIZE 16
 
 /* Structure to save state of computation between the single steps.  */
 struct md4_ctx
@@ -34,7 +34,7 @@ struct md4_ctx
 
   uint32_t total[2];
   uint32_t buflen;
-  char buffer[128] __attribute__ ((__aligned__ (__alignof__ (uint32_t))));
+  uint32_t buffer[128];
 };