]> granicus.if.org Git - python/commitdiff
bpo-32260: don't byte swap siphash keys (#4771)
authorBenjamin Peterson <benjamin@python.org>
Sat, 9 Dec 2017 19:24:18 +0000 (11:24 -0800)
committerGitHub <noreply@github.com>
Sat, 9 Dec 2017 19:24:18 +0000 (11:24 -0800)
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.

Misc/NEWS.d/next/Core and Builtins/2017-12-09-11-03-51.bpo-32260.1DAO-p.rst [new file with mode: 0644]
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 (file)
index 0000000..523ffe0
--- /dev/null
@@ -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.
index bc6786c7b8b243f325a07acc505db2e1e622d796..4494a2f6ef62d04c4ac318314ec0ca1f4a69f894 100644 (file)
@@ -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;