Here's a simple patch to remove crypto/md5's dependence on stdint. It complicates the code in md5.h a bit, but the result is closer to what's already in glibc. This will make it quite a bit easier for Emacs to use crypto/md5.
I haven't pushed this yet. * lib/md5.h, lib/md5.c: All uses of uint32_t changed to md5_uint32, as the glibc version does. * lib/md5.h: Do not include <stdint.h> unconditionally. (md5_uint32): New typedef (actually, resurrected from libc). On ordinary hosts, if not _LIBC, deduce it from <limits.h>. Default it to <stdint.h> uint32_t on weird hosts. * modules/crypto/md5 (Depends-on): Remove stdint. --- ChangeLog | 12 +++++++++++ lib/md5.c | 34 ++++++++++++++++---------------- lib/md5.h | 53 +++++++++++++++++++++++++++++++++++++++++++-------- modules/crypto/md5 | 1 - 4 files changed, 73 insertions(+), 27 deletions(-) diff --git a/ChangeLog b/ChangeLog index c2c1946..9022e14 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2011-02-18 Paul Eggert <egg...@cs.ucla.edu> + + crypto/md5: don't depend on stdint + * lib/md5.h, lib/md5.c: + All uses of uint32_t changed to md5_uint32, as the glibc + version does. + * lib/md5.h: Do not include <stdint.h> unconditionally. + (md5_uint32): New typedef (actually, resurrected from libc). + On ordinary hosts, if not _LIBC, deduce it from <limits.h>. + Default it to <stdint.h> uint32_t on weird hosts. + * modules/crypto/md5 (Depends-on): Remove stdint. + 2011-02-17 Paul Eggert <egg...@cs.ucla.edu> * NEWS: Mention 2011-02-08 change to stdlib. diff --git a/lib/md5.c b/lib/md5.c index d37ca72..e30f0c3 100644 --- a/lib/md5.c +++ b/lib/md5.c @@ -82,9 +82,9 @@ md5_init_ctx (struct md5_ctx *ctx) /* Copy the 4 byte value from v into the memory location pointed to by *cp, If your architecture allows unaligned access this is equivalent to - * (uint32_t *) cp = v */ + * (md5_uint32 *) cp = v */ static inline void -set_uint32 (char *cp, uint32_t v) +set_uint32 (char *cp, md5_uint32 v) { memcpy (cp, &v, sizeof v); } @@ -109,7 +109,7 @@ void * md5_finish_ctx (struct md5_ctx *ctx, void *resbuf) { /* Take yet unprocessed bytes into account. */ - uint32_t bytes = ctx->buflen; + md5_uint32 bytes = ctx->buflen; size_t size = (bytes < 56) ? 64 / 4 : 64 * 2 / 4; /* Now count remaining bytes. */ @@ -255,7 +255,7 @@ md5_process_bytes (const void *buffer, size_t len, struct md5_ctx *ctx) { #if !_STRING_ARCH_unaligned # define alignof(type) offsetof (struct { char c; type x; }, x) -# define UNALIGNED_P(p) (((size_t) p) % alignof (uint32_t) != 0) +# define UNALIGNED_P(p) (((size_t) p) % alignof (md5_uint32) != 0) if (UNALIGNED_P (buffer)) while (len > 64) { @@ -305,14 +305,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) { - 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; + 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; /* 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,11 +325,11 @@ md5_process_block (const void *buffer, size_t len, struct md5_ctx *ctx) the loop. */ while (words < endp) { - 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; + 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; /* First round: using the given function, the context and a constant the next context is computed. Because the algorithms processing diff --git a/lib/md5.h b/lib/md5.h index 8b06466..98bcdfc 100644 --- a/lib/md5.h +++ b/lib/md5.h @@ -22,7 +22,6 @@ #define _MD5_H 1 #include <stdio.h> -#include <stdint.h> #define MD5_DIGEST_SIZE 16 #define MD5_BLOCK_SIZE 64 @@ -58,17 +57,53 @@ extern "C" { # endif +/* The following contortions are an attempt to use the C preprocessor + to determine an unsigned integral type that is 32 bits wide. An + alternative approach is to use autoconf's AC_CHECK_SIZEOF macro, but + doing that would require that the configure script compile and *run* + the resulting executable. Locally running cross-compiled executables + is usually not possible. */ + +#if defined _LIBC +# include <stdint.h> +typedef uint32_t md5_uint32; +#else +# if defined __STDC__ && __STDC__ +# define UINT_MAX_32_BITS 4294967295U +# else +# define UINT_MAX_32_BITS 0xFFFFFFFF +# endif + +# include <limits.h> + +# if UINT_MAX == UINT_MAX_32_BITS + typedef unsigned int md5_uint32; +# else +# if USHRT_MAX == UINT_MAX_32_BITS + typedef unsigned short md5_uint32; +# else +# if ULONG_MAX == UINT_MAX_32_BITS + typedef unsigned long md5_uint32; +# else + /* A machine this weird should have <stdint.h>. */ +# include <stdint.h> + typedef uint32_t md5_uint32; +# endif +# endif +# endif +#endif + /* Structure to save state of computation between the single steps. */ struct md5_ctx { - uint32_t A; - uint32_t B; - uint32_t C; - uint32_t D; - - uint32_t total[2]; - uint32_t buflen; - uint32_t buffer[32]; + md5_uint32 A; + md5_uint32 B; + md5_uint32 C; + md5_uint32 D; + + md5_uint32 total[2]; + md5_uint32 buflen; + md5_uint32 buffer[32]; }; /* diff --git a/modules/crypto/md5 b/modules/crypto/md5 index 7e529e7..33dd4b6 100644 --- a/modules/crypto/md5 +++ b/modules/crypto/md5 @@ -7,7 +7,6 @@ lib/md5.c m4/md5.m4 Depends-on: -stdint configure.ac: gl_MD5 -- 1.7.4