Index: src/OFHashes.m ================================================================== --- src/OFHashes.m +++ src/OFHashes.m @@ -168,21 +168,21 @@ memcpy(p, buffer, size); return self; } memcpy(p, buffer, t); - OF_BSWAP32_V((uint32_t*)in, 16); + OF_BSWAP32_V_IF_BE((uint32_t*)in, 16); md5_transform(buf, (uint32_t*)in); buffer += t; size -= t; } /* Process data in 64-byte chunks */ while (size >= 64) { memcpy(in, buffer, 64); - OF_BSWAP32_V((uint32_t*)in, 16); + OF_BSWAP32_V_IF_BE((uint32_t*)in, 16); md5_transform(buf, (uint32_t*)in); buffer += 64; size -= 64; } @@ -216,27 +216,27 @@ /* 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_V((uint32_t*)in, 16); + OF_BSWAP32_V_IF_BE((uint32_t*)in, 16); md5_transform(buf, (uint32_t*)in); /* Now fill the next block with 56 bytes */ memset(in, 0, 56); } else { /* Pad block to 56 bytes */ memset(p, 0, count - 8); } - OF_BSWAP32_V((uint32_t*)in, 14); + OF_BSWAP32_V_IF_BE((uint32_t*)in, 14); /* Append length in bits and transform */ ((uint32_t*)in)[14] = bits[0]; ((uint32_t*)in)[15] = bits[1]; md5_transform(buf, (uint32_t*)in); - OF_BSWAP32_V(buf, 4); + OF_BSWAP32_V_IF_BE(buf, 4); calculated = YES; return (uint8_t*)buf; } Index: src/OFMacros.h ================================================================== --- src/OFMacros.h +++ src/OFMacros.h @@ -56,21 +56,35 @@ (i & UINT64_C(0x000000000000FF00)) << 40 | (i & UINT64_C(0x00000000000000FF)) << 56; return i; } -#ifdef OF_BIG_ENDIAN static OF_INLINE void OF_BSWAP32_V(uint32_t *buf, size_t len) { while (len--) { *buf = OF_BSWAP32(*buf); buf++; } } + +#ifdef OF_BIG_ENDIAN +#define OF_BSWAP16_IF_BE(i) OF_BSWAP16(i) +#define OF_BSWAP32_IF_BE(i) OF_BSWAP32(i) +#define OF_BSWAP64_IF_BE(i) OF_BSWAP64(i) +#define OF_BSWAP16_IF_LE(i) i +#define OF_BSWAP32_IF_LE(i) i +#define OF_BSWAP64_IF_LE(i) i +#define OF_BSWAP32_V_IF_BE(buf, len) OF_BSWAP32_V(buf, len) #else -#define OF_BSWAP32_V(buf, len) +#define OF_BSWAP16_IF_BE(i) i +#define OF_BSWAP32_IF_BE(i) i +#define OF_BSWAP64_IF_BE(i) i +#define OF_BSWAP16_IF_LE(i) OF_BSWAP16(i) +#define OF_BSWAP32_IF_LE(i) OF_BSWAP32(i) +#define OF_BSWAP64_IF_LE(i) OF_BSWAP64(i) +#define OF_BSWAP32_V_IF_BE(buf, len) #endif #define OF_ROL(val, bits) \ (((val) << (bits)) | ((val) >> (32 - (bits)))) Index: src/OFTCPSocket.m ================================================================== --- src/OFTCPSocket.m +++ src/OFTCPSocket.m @@ -104,11 +104,11 @@ service: service]; } if ((se = getservbyname([service cString], "TCP")) != NULL) port = se->s_port; - else if ((port = htons(atoi([service cString]))) == 0) { + else if ((port = OF_BSWAP16_IF_LE(atoi([service cString]))) == 0) { [mutex unlock]; @throw [OFAddressTranslationFailedException newWithClass: isa node: node service: service]; @@ -210,11 +210,11 @@ service: service]; } if ((se = getservbyname([service cString], "TCP")) != NULL) port = se->s_port; - else if ((port = htons(atoi([service cString]))) == 0) { + else if ((port = OF_BSWAP16_IF_LE(atoi([service cString]))) == 0) { [mutex unlock]; @throw [OFAddressTranslationFailedException newWithClass: isa node: node service: service];