Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4e3e156

Browse files
authored
bpo-32260: don't byte swap siphash keys (#4771)
Reference siphash takes the keys as a bytes, so it makes sense to byte swap when reifying the keys as 64-bit integers. However, Python's siphash takes host integers in to start with.
1 parent 42aa93b commit 4e3e156

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Don't byte swap the input keys to the SipHash algorithm on big-endian
2+
platforms. This should ensure siphash gives consistent results across
3+
platforms.

Python/pyhash.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,7 @@ static PyHash_FuncDef PyHash_Func = {fnv, "fnv", 8 * SIZEOF_PY_HASH_T,
364364

365365

366366
static uint64_t
367-
siphash24(uint64_t key0, uint64_t key1, const void *src, Py_ssize_t src_sz) {
368-
uint64_t k0 = _le64toh(key0);
369-
uint64_t k1 = _le64toh(key1);
367+
siphash24(uint64_t k0, uint64_t k1, const void *src, Py_ssize_t src_sz) {
370368
uint64_t b = (uint64_t)src_sz << 56;
371369
const uint64_t *in = (uint64_t*)src;
372370

0 commit comments

Comments
 (0)