@@ -31,10 +31,23 @@ #define F4(x, y, z) (y ^ (x | ~z)) /* This is the central step in the MD5 algorithm. */ #define MD5STEP(f, w, x, y, z, data, s) \ (w += f(x, y, z) + data, w = w << s | w >> (32 - s), w += x) + +#ifdef OF_BIG_ENDIAN +static OF_INLINE void +BSWAP32_VEC_IF_BE(uint32_t *buffer, size_t length) +{ + while (length--) { + *buffer = OF_BSWAP32(*buffer); + buffer++; + } +} +#else +# define BSWAP32_VEC_IF_BE(buffer, length) +#endif static void md5_transform(uint32_t buffer[4], const uint32_t in[16]) { register uint32_t a, b, c, d; @@ -175,21 +188,21 @@ memcpy(p, buffer_, length); return; } memcpy(p, buffer_, t); - of_bswap32_vec_if_be(in.u32, 16); + BSWAP32_VEC_IF_BE(in.u32, 16); md5_transform(buffer, in.u32); buffer_ += t; length -= t; } /* Process data in 64-byte chunks */ while (length >= 64) { memcpy(in.u8, buffer_, 64); - of_bswap32_vec_if_be(in.u32, 16); + BSWAP32_VEC_IF_BE(in.u32, 16); md5_transform(buffer, in.u32); buffer_ += 64; length -= 64; } @@ -221,28 +234,28 @@ /* Pad out to 56 mod 64 */ if (count < 8) { /* Two lots of padding: Pad the first block to 64 bytes */ memset(p, 0, count); - of_bswap32_vec_if_be(in.u32, 16); + BSWAP32_VEC_IF_BE(in.u32, 16); md5_transform(buffer, in.u32); /* Now fill the next block with 56 bytes */ memset(in.u8, 0, 56); } else { /* Pad block to 56 bytes */ memset(p, 0, count - 8); } - of_bswap32_vec_if_be(in.u32, 14); + BSWAP32_VEC_IF_BE(in.u32, 14); /* Append length in bits and transform */ in.u32[14] = bits[0]; in.u32[15] = bits[1]; md5_transform(buffer, in.u32); - of_bswap32_vec_if_be(buffer, 4); + BSWAP32_VEC_IF_BE(buffer, 4); calculated = YES; return (uint8_t*)buffer; } @end