forked from lix-project/lix
* 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.
This commit is contained in:
parent
9efad76595
commit
4d21cda0cd
25
src/md5.c
25
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
|
||||
|
|
Loading…
Reference in a new issue