Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Doc/c-api/hash.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,29 @@ See also the :c:member:`PyTypeObject.tp_hash` member and :ref:`numeric-hash`.
Add :c:macro:`!Py_HASH_SIPHASH13`.


.. c:macro:: Py_HASH_EXTERNAL

If :c:macro:`Py_HASH_ALGORITHM` is set to that value, the hash function
definition ``PyHash_Func`` must be provided by embedders at compile time.
For instance, to use SipHash-4-8 for conservative security purposes

.. code-block:: c

static Py_hash_t
siphash48(const void *src, Py_ssize_t src_sz) { ... }

PyHash_FuncDef PyHash_Func = {
.hash = siphash48,
.name = "siphash48",
.hash_bits = 64,
.seed_bits = 128,
};

.. availability:: Unix

.. versionadded:: 3.4


.. c:macro:: Py_HASH_CUTOFF

Buffers of length in range ``[1, Py_HASH_CUTOFF)`` are hashed using DJBX33A
Expand Down
5 changes: 3 additions & 2 deletions Doc/using/configure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1024,13 +1024,14 @@ Libraries options
Security Options
----------------

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

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

* ``siphash13`` (default);
* ``siphash24``;
* ``fnv``.
* ``fnv``;
* ``external``.

.. versionadded:: 3.4

Expand Down
6 changes: 5 additions & 1 deletion configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -3966,12 +3966,15 @@ dnl quadrigraphs "@<:@" and "@:>@" produce "[" and "]" in the output
AC_ARG_WITH(
[hash_algorithm],
[AS_HELP_STRING(
[--with-hash-algorithm=@<:@fnv|siphash13|siphash24@:>@],
[--with-hash-algorithm=@<:@fnv|siphash13|siphash24|external@:>@],
[select hash algorithm for use in Python/pyhash.c (default is SipHash13)]
)],
[
AC_MSG_RESULT([$withval])
case "$withval" in
external)
AC_DEFINE([Py_HASH_ALGORITHM], [0])
;;
siphash13)
AC_DEFINE([Py_HASH_ALGORITHM], [3])
;;
Expand Down
Loading