siphash-c
siphash-c copied to clipboard
Works badly in little endian systems unless unaligned access is allowed
Precisely, it does nothing then.
The reason is:
#if BYTE_ORDER == LITTLE_ENDIAN && UNALIGNED_WORD_ACCESS
{
uint64_t *data64 = (uint64_t *)data;
while (data64 != (uint64_t *) end) {
m = *data64++;
SIP_2_ROUND(m, v0, v1, v2, v3);
}
}
#elif BYTE_ORDER == BIG_ENDIAN
for (; data != end; data += sizeof(uint64_t)) {
m = U8TO64_LE(data);
SIP_2_ROUND(m, v0, v1, v2, v3);
}
#endif
Which should be:
#if BYTE_ORDER == LITTLE_ENDIAN && UNALIGNED_WORD_ACCESS
{
uint64_t *data64 = (uint64_t *)data;
while (data64 != (uint64_t *) end) {
m = *data64++;
SIP_2_ROUND(m, v0, v1, v2, v3);
}
}
#else
for (; data != end; data += sizeof(uint64_t)) {
m = U8TO64_LE(data);
SIP_2_ROUND(m, v0, v1, v2, v3);
}
#endif