Skip to content

Commit 58d8642

Browse files
committed
correctly support Py_HASH_EXTERNAL for Unix platforms
1 parent 87942d9 commit 58d8642

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

Doc/c-api/hash.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,29 @@ See also the :c:member:`PyTypeObject.tp_hash` member and :ref:`numeric-hash`.
4444
Add :c:macro:`!Py_HASH_SIPHASH13`.
4545

4646

47+
.. c:macro:: Py_HASH_EXTERNAL
48+
49+
If :c:macro:`Py_HASH_ALGORITHM` is set to that value, the hash function
50+
definition ``PyHash_Func`` must be provided by embedders at compile time.
51+
For instance, to use SipHash-4-8 for conservative security purposes
52+
53+
.. code-block:: c
54+
55+
static Py_hash_t
56+
siphash48(const void *src, Py_ssize_t src_sz) { ... }
57+
58+
PyHash_FuncDef PyHash_Func = {
59+
.hash = siphash48,
60+
.name = "siphash48",
61+
.hash_bits = 64,
62+
.seed_bits = 128,
63+
};
64+
65+
.. availability:: Unix
66+
67+
.. versionadded:: 3.4
68+
69+
4770
.. c:macro:: Py_HASH_CUTOFF
4871
4972
Buffers of length in range ``[1, Py_HASH_CUTOFF)`` are hashed using DJBX33A

Doc/using/configure.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,13 +1024,14 @@ Libraries options
10241024
Security Options
10251025
----------------
10261026

1027-
.. option:: --with-hash-algorithm=[fnv|siphash13|siphash24]
1027+
.. option:: --with-hash-algorithm=[fnv|siphash13|siphash24|external]
10281028

10291029
Select hash algorithm for use in ``Python/pyhash.c``:
10301030

10311031
* ``siphash13`` (default);
10321032
* ``siphash24``;
1033-
* ``fnv``.
1033+
* ``fnv``;
1034+
* ``external``.
10341035

10351036
.. versionadded:: 3.4
10361037

configure

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3966,12 +3966,15 @@ dnl quadrigraphs "@<:@" and "@:>@" produce "[" and "]" in the output
39663966
AC_ARG_WITH(
39673967
[hash_algorithm],
39683968
[AS_HELP_STRING(
3969-
[--with-hash-algorithm=@<:@fnv|siphash13|siphash24@:>@],
3969+
[--with-hash-algorithm=@<:@fnv|siphash13|siphash24|external@:>@],
39703970
[select hash algorithm for use in Python/pyhash.c (default is SipHash13)]
39713971
)],
39723972
[
39733973
AC_MSG_RESULT([$withval])
39743974
case "$withval" in
3975+
external)
3976+
AC_DEFINE([Py_HASH_ALGORITHM], [0])
3977+
;;
39753978
siphash13)
39763979
AC_DEFINE([Py_HASH_ALGORITHM], [3])
39773980
;;

0 commit comments

Comments
 (0)