Skip to content

Commit

Permalink
bpo-32260: don't byte swap siphash keys (python#4771)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
benjaminp authored Dec 9, 2017
1 parent 42aa93b commit 4e3e156
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Don't byte swap the input keys to the SipHash algorithm on big-endian
platforms. This should ensure siphash gives consistent results across
platforms.
4 changes: 1 addition & 3 deletions Python/pyhash.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,7 @@ static PyHash_FuncDef PyHash_Func = {fnv, "fnv", 8 * SIZEOF_PY_HASH_T,


static uint64_t
siphash24(uint64_t key0, uint64_t key1, const void *src, Py_ssize_t src_sz) {
uint64_t k0 = _le64toh(key0);
uint64_t k1 = _le64toh(key1);
siphash24(uint64_t k0, uint64_t k1, const void *src, Py_ssize_t src_sz) {
uint64_t b = (uint64_t)src_sz << 56;
const uint64_t *in = (uint64_t*)src;

Expand Down

0 comments on commit 4e3e156

Please sign in to comment.