Index: b/Python/pyhash.c =================================================================== --- a/Python/pyhash.c +++ b/Python/pyhash.c @@ -328,20 +328,21 @@ static PyHash_FuncDef PyHash_Func = {fnv * the hash values' least significant bits. */ #if PY_LITTLE_ENDIAN -# define _le64toh(x) ((uint64_t)(x)) +# define _le64toh(v, x) memcpy(&v, x, sizeof(v)) #elif defined(__APPLE__) -# define _le64toh(x) OSSwapLittleToHostInt64(x) +# define _le64toh(v, x) v = OSSwapLittleToHostInt64(*x) #elif defined(HAVE_LETOH64) -# define _le64toh(x) le64toh(x) +# define _le64toh(v, x) v = le64toh(*x) #else -# define _le64toh(x) (((uint64_t)(x) << 56) | \ - (((uint64_t)(x) << 40) & 0xff000000000000ULL) | \ - (((uint64_t)(x) << 24) & 0xff0000000000ULL) | \ - (((uint64_t)(x) << 8) & 0xff00000000ULL) | \ - (((uint64_t)(x) >> 8) & 0xff000000ULL) | \ - (((uint64_t)(x) >> 24) & 0xff0000ULL) | \ - (((uint64_t)(x) >> 40) & 0xff00ULL) | \ - ((uint64_t)(x) >> 56)) +# define _le64toh(v, x) v = \ + (((uint64_t)(*x) << 56) | \ + (((uint64_t)(*x) << 40) & 0xff000000000000ULL) | \ + (((uint64_t)(*x) << 24) & 0xff0000000000ULL) | \ + (((uint64_t)(*x) << 8) & 0xff00000000ULL) | \ + (((uint64_t)(*x) >> 8) & 0xff000000ULL) | \ + (((uint64_t)(*x) >> 24) & 0xff0000ULL) | \ + (((uint64_t)(*x) >> 40) & 0xff00ULL) | \ + ((uint64_t)(*x) >> 56)) #endif @@ -366,22 +367,24 @@ static PyHash_FuncDef PyHash_Func = {fnv static Py_hash_t siphash24(const void *src, Py_ssize_t src_sz) { - uint64_t k0 = _le64toh(_Py_HashSecret.siphash.k0); - uint64_t k1 = _le64toh(_Py_HashSecret.siphash.k1); + uint64_t k0, k1, v0, v1, v2, v3; uint64_t b = (uint64_t)src_sz << 56; const uint64_t *in = (uint64_t*)src; - uint64_t v0 = k0 ^ 0x736f6d6570736575ULL; - uint64_t v1 = k1 ^ 0x646f72616e646f6dULL; - uint64_t v2 = k0 ^ 0x6c7967656e657261ULL; - uint64_t v3 = k1 ^ 0x7465646279746573ULL; - - uint64_t t; + uint64_t t, t2; uint8_t *pt; uint8_t *m; + _le64toh(k0, &(_Py_HashSecret.siphash.k0)); + _le64toh(k1, &(_Py_HashSecret.siphash.k1)); + v0 = k0 ^ 0x736f6d6570736575ULL; + v1 = k1 ^ 0x646f72616e646f6dULL; + v2 = k0 ^ 0x6c7967656e657261ULL; + v3 = k1 ^ 0x7465646279746573ULL; + while (src_sz >= 8) { - uint64_t mi = _le64toh(*in); + uint64_t mi; + _le64toh(mi, in); in += 1; src_sz -= 8; v3 ^= mi; @@ -401,7 +404,8 @@ siphash24(const void *src, Py_ssize_t sr case 2: pt[1] = m[1]; case 1: pt[0] = m[0]; } - b |= _le64toh(t); + _le64toh(t2, &t); + b |= t2; v3 ^= b; DOUBLE_ROUND(v0,v1,v2,v3);