Fix endianness issues in unit test

This commit is contained in:
cpq committed 2022-09-28 20:22:09 +01:00
1 parent b5355307a3
commit 88097f1829
7 files changed
+41 -73

No files matched your search

+11 -13
View File
@@ -1,21 +1,19 @@
#include "md5.h"
#include "arch.h"
#include "md5.h"
#if defined(MG_ENABLE_MD5) && MG_ENABLE_MD5
static void mg_byte_reverse(unsigned char *buf, unsigned longs) {
/* Forrest: MD5 expect LITTLE_ENDIAN, swap if BIG_ENDIAN */
#if BYTE_ORDER == BIG_ENDIAN
do {
uint32_t t = (uint32_t) ((unsigned) buf[3] << 8 | buf[2]) << 16 |
((unsigned) buf[1] << 8 | buf[0]);
*(uint32_t *) buf = t;
buf += 4;
} while (--longs);
#else
(void) buf;
(void) longs;
#endif
if (MG_BIG_ENDIAN) {
do {
uint32_t t = (uint32_t) ((unsigned) buf[3] << 8 | buf[2]) << 16 |
((unsigned) buf[1] << 8 | buf[0]);
*(uint32_t *) buf = t;
buf += 4;
} while (--longs);
} else {
(void) buf, (void) longs; // Little endian. Do nothing
}
}
#define F1(x, y, z) (z ^ (x & (y ^ z)))