summaryrefslogtreecommitdiff
path: root/debian/patches/pyhash.diff
blob: f8ecfdac3d01aca292339e6ad69d653e9e0cc68b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
Index: b/Python/pyhash.c
===================================================================
--- a/Python/pyhash.c
+++ b/Python/pyhash.c
@@ -328,13 +328,14 @@ 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) | \
+#  define _le64toh(v, x) v = \
+                      (((uint64_t)(x) << 56) |			      \
                       (((uint64_t)(x) << 40) & 0xff000000000000ULL) | \
                       (((uint64_t)(x) << 24) & 0xff0000000000ULL) | \
                       (((uint64_t)(x) << 8)  & 0xff00000000ULL) | \
@@ -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]; /* fall through */
         case 1: pt[0] = m[0]; /* fall through */
     }
-    b |= _le64toh(t);
+    _le64toh(t2, t);
+    b |= t2;
 
     v3 ^= b;
     DOUBLE_ROUND(v0,v1,v2,v3);