[Python-checkins] bpo-32260: don't byte swap siphash keys (#4771)

Benjamin Peterson webhook-mailer at python.org
Sat Dec 9 14:24:21 EST 2017


https://github.com/python/cpython/commit/4e3e156391e70cd23cae18f2629ec323b3b1e7de
commit: 4e3e156391e70cd23cae18f2629ec323b3b1e7de
branch: master
author: Benjamin Peterson <benjamin at python.org>
committer: GitHub <noreply at github.com>
date: 2017-12-09T11:24:18-08:00
summary:

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.

files:
A Misc/NEWS.d/next/Core and Builtins/2017-12-09-11-03-51.bpo-32260.1DAO-p.rst
M Python/pyhash.c

diff --git a/Misc/NEWS.d/next/Core and Builtins/2017-12-09-11-03-51.bpo-32260.1DAO-p.rst b/Misc/NEWS.d/next/Core and Builtins/2017-12-09-11-03-51.bpo-32260.1DAO-p.rst
new file mode 100644
index 00000000000..523ffe0a611
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2017-12-09-11-03-51.bpo-32260.1DAO-p.rst	
@@ -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.
diff --git a/Python/pyhash.c b/Python/pyhash.c
index bc6786c7b8b..4494a2f6ef6 100644
--- a/Python/pyhash.c
+++ b/Python/pyhash.c
@@ -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;
 



More information about the Python-checkins mailing list