about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2003-05-27T09·55+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2003-05-27T09·55+0000
commit4d21cda0cd44db75f6b9f5942440a07303c06b4a (patch)
tree3e3df817fb4fa844c9380b096d77529731b7279a
parent9efad7659568ad2eeee5e2cf9cf1df9322d9eb33 (diff)
* 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.

-rw-r--r--src/md5.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/md5.c b/src/md5.c
index 64ade3c6f268..fa67ebfcdbdf 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