File tree Expand file tree Collapse file tree 4 files changed +35
-4
lines changed
Expand file tree Collapse file tree 4 files changed +35
-4
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -1024,13 +1024,14 @@ Libraries options
10241024Security 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
Original file line number Diff line number Diff line change @@ -3966,12 +3966,15 @@ dnl quadrigraphs "@<:@" and "@:>@" produce "[" and "]" in the output
39663966AC_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[
39733973AC_MSG_RESULT ( [ $withval] )
39743974case "$withval" in
3975+ external)
3976+ AC_DEFINE ( [ Py_HASH_ALGORITHM] , [ 0] )
3977+ ;;
39753978 siphash13)
39763979 AC_DEFINE ( [ Py_HASH_ALGORITHM] , [ 3] )
39773980 ;;
You can’t perform that action at this time.
0 commit comments