From 4d21cda0cd44db75f6b9f5942440a07303c06b4a Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 27 May 2003 09:55:47 +0000 Subject: [PATCH] * Fix for big-endian platforms: check for endianness in MD5 computations. This is done at runtime, which is inefficient, but I can't be bothered to write an Autoconf test right now. --- src/md5.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/md5.c b/src/md5.c index 64ade3c6f2..fa67ebfcdb 100644 --- a/src/md5.c +++ b/src/md5.c @@ -31,12 +31,25 @@ #include "md5.h" -#ifdef WORDS_BIGENDIAN -# define SWAP(n) \ - (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24)) -#else -# define SWAP(n) (n) -#endif + +static md5_uint32 SWAP(md5_uint32 n) +{ + static int checked = 0; + static int bigendian = 0; + static md5_uint32 test; + + if (!checked) { + test = 1; + if (* (char *) &test == 0) + bigendian = 1; + checked = 1; + } + + if (bigendian) + return (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24)); + else + return n; +} /* This array contains the bytes used to pad the buffer to the next