Separate sha1 from md5. Use stdint.h in both modules.
authorSimon Josefsson <simon@josefsson.org>
Mon, 17 Oct 2005 12:55:00 +0000 (12:55 +0000)
committerSimon Josefsson <simon@josefsson.org>
Mon, 17 Oct 2005 12:55:00 +0000 (12:55 +0000)
ChangeLog
lib/ChangeLog
lib/md5.c
lib/md5.h
lib/sha1.c
lib/sha1.h
m4/ChangeLog
m4/md5.m4
modules/md5
modules/sha1

index c1a4685425ed659d99af2e5b5207a6512a2c01d3..7a8d0b1713f49f32a55b24b9c6ec156c80ce303c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2005-10-17  Simon Josefsson  <jas@extundo.com>
+
+       * modules/sha1: Depend on stdint instead of md5.
+
+       * modules/md5: Depend on stdint, remove uint32_t.
+
 2005-10-16  Bruno Haible  <bruno@clisp.org>
 
        * gnulib-tool (func_emit_tests_Makefile_am): Also define
index e7c794549b63af5f5ead2284e9935948c3d56e65..18846459020beb3079ddb19b9c0f9e175aa333e7 100644 (file)
@@ -1,3 +1,14 @@
+2005-10-17  Simon Josefsson  <jas@extundo.com>
+
+       * sha1.c: Use uint32_t instead of md5_uint32.t
+
+       * sha1.h: Use stdint.h and uint32_t instead of md5_uint32 from
+       md5.h.
+
+       * md5.c: Use uin32_t.  Fix non-gcc UNALIGNED_P macro.
+
+       * md5.h: Use stdint.h and uint32_t.  Doc fix.
+
 2005-10-15  Simon Josefsson  <jas@extundo.com>
 
        * rijndael-api-fst.h, rijndael-api-fst.c: New files.
index 87db8f956c6f8fa9d6722d81a1dbfee96d542217..511a029d1388063477fd410095bb8144f16a9be0 100644 (file)
--- a/lib/md5.c
+++ b/lib/md5.c
@@ -1,8 +1,8 @@
-/* md5.c - Functions to compute MD5 message digest of files or memory blocks
+/* Functions to compute MD5 message digest of files or memory blocks.
    according to the definition of MD5 in RFC 1321 from April 1992.
-   Copyright (C) 1995, 1996, 2001, 2003, 2004, 2005 Free Software Foundation, Inc.
-   NOTE: The canonical source of this file is maintained with the GNU C
-   Library.  Bugs can be reported to bug-glibc@prep.ai.mit.edu.
+   Copyright (C) 1995,1996,1997,1999,2000,2001,2005
+       Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
 
    This program is free software; you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by the
@@ -27,7 +27,9 @@
 #include "md5.h"
 
 #include <stddef.h>
+#include <stdlib.h>
 #include <string.h>
+#include <sys/types.h>
 
 #if USE_UNLOCKED_IO
 # include "unlocked-io.h"
@@ -88,10 +90,10 @@ md5_init_ctx (struct md5_ctx *ctx)
 void *
 md5_read_ctx (const struct md5_ctx *ctx, void *resbuf)
 {
-  ((md5_uint32 *) resbuf)[0] = SWAP (ctx->A);
-  ((md5_uint32 *) resbuf)[1] = SWAP (ctx->B);
-  ((md5_uint32 *) resbuf)[2] = SWAP (ctx->C);
-  ((md5_uint32 *) resbuf)[3] = SWAP (ctx->D);
+  ((uint32_t *) resbuf)[0] = SWAP (ctx->A);
+  ((uint32_t *) resbuf)[1] = SWAP (ctx->B);
+  ((uint32_t *) resbuf)[2] = SWAP (ctx->C);
+  ((uint32_t *) resbuf)[3] = SWAP (ctx->D);
 
   return resbuf;
 }
@@ -105,7 +107,7 @@ void *
 md5_finish_ctx (struct md5_ctx *ctx, void *resbuf)
 {
   /* Take yet unprocessed bytes into account.  */
-  md5_uint32 bytes = ctx->buflen;
+  uint32_t bytes = ctx->buflen;
   size_t pad;
 
   /* Now count remaining bytes.  */
@@ -117,8 +119,8 @@ md5_finish_ctx (struct md5_ctx *ctx, void *resbuf)
   memcpy (&ctx->buffer[bytes], fillbuf, pad);
 
   /* Put the 64-bit file length in *bits* at the end of the buffer.  */
-  *(md5_uint32 *) &ctx->buffer[bytes + pad] = SWAP (ctx->total[0] << 3);
-  *(md5_uint32 *) &ctx->buffer[bytes + pad + 4] = SWAP ((ctx->total[1] << 3) |
+  *(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));
 
   /* Process last bytes.  */
@@ -244,8 +246,14 @@ md5_process_bytes (const void *buffer, size_t len, struct md5_ctx *ctx)
   if (len >= 64)
     {
 #if !_STRING_ARCH_unaligned
-# define alignof(type) offsetof (struct { char c; type x; }, x)
-# define UNALIGNED_P(p) (((size_t) p) % alignof (md5_uint32) != 0)
+/* To check alignment gcc has an appropriate operator.  Other
+   compilers don't.  */
+# if __GNUC__ >= 2
+#  define UNALIGNED_P(p) (((uintptr_t) p) % __alignof__ (uint32_t) != 0)
+# else
+#  define alignof(type) offsetof (struct { char c; type x; }, x)
+#  define UNALIGNED_P(p) (((size_t) p) % alignof (uint32_t) != 0)
+# endif
       if (UNALIGNED_P (buffer))
        while (len > 64)
          {
@@ -295,14 +303,14 @@ md5_process_bytes (const void *buffer, size_t len, struct md5_ctx *ctx)
 void
 md5_process_block (const void *buffer, size_t len, struct md5_ctx *ctx)
 {
-  md5_uint32 correct_words[16];
-  const md5_uint32 *words = buffer;
-  size_t nwords = len / sizeof (md5_uint32);
-  const md5_uint32 *endp = words + nwords;
-  md5_uint32 A = ctx->A;
-  md5_uint32 B = ctx->B;
-  md5_uint32 C = ctx->C;
-  md5_uint32 D = ctx->D;
+  uint32_t correct_words[16];
+  const uint32_t *words = buffer;
+  size_t nwords = len / sizeof (uint32_t);
+  const uint32_t *endp = words + nwords;
+  uint32_t A = ctx->A;
+  uint32_t B = ctx->B;
+  uint32_t C = ctx->C;
+  uint32_t D = ctx->D;
 
   /* First increment the byte count.  RFC 1321 specifies the possible
      length of the file up to 2^64 bits.  Here we only compute the
@@ -315,11 +323,11 @@ md5_process_block (const void *buffer, size_t len, struct md5_ctx *ctx)
      the loop.  */
   while (words < endp)
     {
-      md5_uint32 *cwp = correct_words;
-      md5_uint32 A_save = A;
-      md5_uint32 B_save = B;
-      md5_uint32 C_save = C;
-      md5_uint32 D_save = D;
+      uint32_t *cwp = correct_words;
+      uint32_t A_save = A;
+      uint32_t B_save = B;
+      uint32_t C_save = C;
+      uint32_t D_save = D;
 
       /* First round: using the given function, the context and a constant
         the next context is computed.  Because the algorithms processing
@@ -375,7 +383,7 @@ md5_process_block (const void *buffer, size_t len, struct md5_ctx *ctx)
         argument specifying the function to use.  */
 #undef OP
 #define OP(f, a, b, c, d, k, s, T)                                     \
-      do                                                               \
+      do                                                               \
        {                                                               \
          a += f (b, c, d) + correct_words[k] + T;                      \
          CYCLIC (a, s);                                                \
index 969f7a0a952f2ce9266e0472a96bee870d7e3d2f..b636e1f89d9e32aaebcee2e95680c57ec05acb5f 100644 (file)
--- a/lib/md5.h
+++ b/lib/md5.h
@@ -1,9 +1,8 @@
 /* Declaration of functions and data types used for MD5 sum computing
    library functions.
-   Copyright (C) 1995-1997,1999-2005 Free Software Foundation, Inc.
-
-   NOTE: The canonical source of this file is maintained with the GNU C
-   Library.  Bugs can be reported to bug-glibc@prep.ai.mit.edu.
+   Copyright (C) 1995-1997,1999,2000,2001,2004,2005
+      Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
 
    This program is free software; you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by the
 #define _MD5_H 1
 
 #include <stdio.h>
+#include <stdint.h>
 
-#if HAVE_INTTYPES_H
-# include <inttypes.h>
-#endif
-#if HAVE_STDINT_H || _LIBC
-# include <stdint.h>
-#endif
+#define MD5_DIGEST_SIZE 16
+#define MD5_BLOCK_SIZE 64
 
 #ifndef __GNUC_PREREQ
 # if defined __GNUC__ && defined __GNUC_MINOR__
-#  define __GNUC_PREREQ(maj, min) \
-       ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
+#  define __GNUC_PREREQ(maj, min)                                      \
+  ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
 # else
 #  define __GNUC_PREREQ(maj, min) 0
 # endif
 # define __md5_stream md5_stream
 #endif
 
-#define MD5_DIGEST_SIZE 16
-#define MD5_BLOCK_SIZE 64
-
-typedef uint32_t md5_uint32;
-
 /* Structure to save state of computation between the single steps.  */
 struct md5_ctx
 {
-  md5_uint32 A;
-  md5_uint32 B;
-  md5_uint32 C;
-  md5_uint32 D;
-
-  md5_uint32 total[2];
-  md5_uint32 buflen;
-  char buffer[128] __attribute__ ((__aligned__ (__alignof__ (md5_uint32))));
+  uint32_t A;
+  uint32_t B;
+  uint32_t C;
+  uint32_t D;
+
+  uint32_t total[2];
+  uint32_t buflen;
+  char buffer[128] __attribute__ ((__aligned__ (__alignof__ (uint32_t))));
 };
 
 /*
@@ -110,8 +101,8 @@ extern void __md5_process_bytes (const void *buffer, size_t len,
    endian byte order, so that a byte-wise output yields to the wanted
    ASCII representation of the message digest.
 
-   IMPORTANT: On some systems it is required that RESBUF be correctly
-   aligned for a 32 bits value.  */
+   IMPORTANT: On some systems, RESBUF must be aligned to a 32-bit
+   boundary. */
 extern void *__md5_finish_ctx (struct md5_ctx *ctx, void *resbuf) __THROW;
 
 
@@ -119,8 +110,8 @@ extern void *__md5_finish_ctx (struct md5_ctx *ctx, void *resbuf) __THROW;
    always in little endian byte order, so that a byte-wise output yields
    to the wanted ASCII representation of the message digest.
 
-   IMPORTANT: On some systems it is required that RESBUF is correctly
-   aligned for a 32 bits value.  */
+   IMPORTANT: On some systems, RESBUF must be aligned to a 32-bit
+   boundary. */
 extern void *__md5_read_ctx (const struct md5_ctx *ctx, void *resbuf) __THROW;
 
 
index 556d9ca1a4c964dbdd2fc5c1a6f4a27cbb34340e..4cc5512a4a87461861d47d6bea29d7dad79712ea 100644 (file)
@@ -81,11 +81,11 @@ sha1_init_ctx (struct sha1_ctx *ctx)
 void *
 sha1_read_ctx (const struct sha1_ctx *ctx, void *resbuf)
 {
-  ((md5_uint32 *) resbuf)[0] = SWAP (ctx->A);
-  ((md5_uint32 *) resbuf)[1] = SWAP (ctx->B);
-  ((md5_uint32 *) resbuf)[2] = SWAP (ctx->C);
-  ((md5_uint32 *) resbuf)[3] = SWAP (ctx->D);
-  ((md5_uint32 *) resbuf)[4] = SWAP (ctx->E);
+  ((uint32_t *) resbuf)[0] = SWAP (ctx->A);
+  ((uint32_t *) resbuf)[1] = SWAP (ctx->B);
+  ((uint32_t *) resbuf)[2] = SWAP (ctx->C);
+  ((uint32_t *) resbuf)[3] = SWAP (ctx->D);
+  ((uint32_t *) resbuf)[4] = SWAP (ctx->E);
 
   return resbuf;
 }
@@ -99,7 +99,7 @@ void *
 sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf)
 {
   /* Take yet unprocessed bytes into account.  */
-  md5_uint32 bytes = ctx->buflen;
+  uint32_t bytes = ctx->buflen;
   size_t pad;
 
   /* Now count remaining bytes.  */
@@ -111,8 +111,8 @@ sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf)
   memcpy (&ctx->buffer[bytes], fillbuf, pad);
 
   /* Put the 64-bit file length in *bits* at the end of the buffer.  */
-  *(md5_uint32 *) &ctx->buffer[bytes + pad + 4] = SWAP (ctx->total[0] << 3);
-  *(md5_uint32 *) &ctx->buffer[bytes + pad] = SWAP ((ctx->total[1] << 3) |
+  *(uint32_t *) &ctx->buffer[bytes + pad + 4] = SWAP (ctx->total[0] << 3);
+  *(uint32_t *) &ctx->buffer[bytes + pad] = SWAP ((ctx->total[1] << 3) |
                                                    (ctx->total[0] >> 29));
 
   /* Process last bytes.  */
@@ -238,7 +238,7 @@ sha1_process_bytes (const void *buffer, size_t len, struct sha1_ctx *ctx)
     {
 #if !_STRING_ARCH_unaligned
 # define alignof(type) offsetof (struct { char c; type x; }, x)
-# define UNALIGNED_P(p) (((size_t) p) % alignof (md5_uint32) != 0)
+# define UNALIGNED_P(p) (((size_t) p) % alignof (uint32_t) != 0)
       if (UNALIGNED_P (buffer))
        while (len > 64)
          {
@@ -293,15 +293,15 @@ sha1_process_bytes (const void *buffer, size_t len, struct sha1_ctx *ctx)
 void
 sha1_process_block (const void *buffer, size_t len, struct sha1_ctx *ctx)
 {
-  const md5_uint32 *words = buffer;
-  size_t nwords = len / sizeof (md5_uint32);
-  const md5_uint32 *endp = words + nwords;
-  md5_uint32 x[16];
-  md5_uint32 a = ctx->A;
-  md5_uint32 b = ctx->B;
-  md5_uint32 c = ctx->C;
-  md5_uint32 d = ctx->D;
-  md5_uint32 e = ctx->E;
+  const uint32_t *words = buffer;
+  size_t nwords = len / sizeof (uint32_t);
+  const uint32_t *endp = words + nwords;
+  uint32_t x[16];
+  uint32_t a = ctx->A;
+  uint32_t b = ctx->B;
+  uint32_t c = ctx->C;
+  uint32_t d = ctx->D;
+  uint32_t e = ctx->E;
 
   /* First increment the byte count.  RFC 1321 specifies the possible
      length of the file up to 2^64 bits.  Here we only compute the
@@ -325,7 +325,7 @@ sha1_process_block (const void *buffer, size_t len, struct sha1_ctx *ctx)
 
   while (words < endp)
     {
-      md5_uint32 tm;
+      uint32_t tm;
       int t;
       for (t = 0; t < 16; t++)
        {
index bb48855b8da8b694f33bdcd8b03edf692789c786..a3ab132e8117a5b3f119080b35349ed226fa26e0 100644 (file)
 # define SHA1_H 1
 
 # include <stdio.h>
-# include "md5.h"
+# include <stdint.h>
 
 /* Structure to save state of computation between the single steps.  */
 struct sha1_ctx
 {
-  md5_uint32 A;
-  md5_uint32 B;
-  md5_uint32 C;
-  md5_uint32 D;
-  md5_uint32 E;
-
-  md5_uint32 total[2];
-  md5_uint32 buflen;
-  char buffer[128] __attribute__ ((__aligned__ (__alignof__ (md5_uint32))));
+  uint32_t A;
+  uint32_t B;
+  uint32_t C;
+  uint32_t D;
+  uint32_t E;
+
+  uint32_t total[2];
+  uint32_t buflen;
+  char buffer[128] __attribute__ ((__aligned__ (__alignof__ (uint32_t))));
 };
 
 
index c6e703f371f39b1aefe599897a502eb841576e5f..4e60082379831bd7b5136be381205527545f63a9 100644 (file)
@@ -1,3 +1,7 @@
+2005-10-11  Simon Josefsson  <jas@extundo.com>
+
+       * md5.m4: Remove call to uint32_t.m4.
+
 2005-10-15  Simon Josefsson  <jas@extundo.com>
 
        * rijndael.m4: New file.
index 729b6563c5fc936ea7bb7a6c725a39b82c7c8b58..0c4d86b591248e3495b4170f419119fcbd497b3e 100644 (file)
--- a/m4/md5.m4
+++ b/m4/md5.m4
@@ -1,4 +1,4 @@
-# md5.m4 serial 7
+# md5.m4 serial 8
 dnl Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -9,9 +9,6 @@ AC_DEFUN([gl_MD5],
   AC_LIBSOURCES([md5.c, md5.h])
   AC_LIBOBJ([md5])
 
-  dnl Prerequisites of lib/md5.h.
-  AC_REQUIRE([gl_AC_TYPE_UINT32_T])
-
   dnl Prerequisites of lib/md5.c.
   AC_REQUIRE([AC_C_BIGENDIAN])
   :
index 3be5bf6cfb6499e84e4271ceed1c93c4ad7aa7ed..250c94f6282df846b88ee5b6ba0479eba540f8af 100644 (file)
@@ -5,9 +5,9 @@ Files:
 lib/md5.h
 lib/md5.c
 m4/md5.m4
-m4/uint32_t.m4
 
 Depends-on:
+stdint
 
 configure.ac:
 gl_MD5
index a528d0521ee6b78bdb575948270533ec481da07f..d41e1f2c3262f2005ad0e8719d6c3279d5e02e52 100644 (file)
@@ -7,7 +7,7 @@ lib/sha1.c
 m4/sha1.m4
 
 Depends-on:
-md5
+stdint
 
 configure.ac:
 gl_SHA1