siphash24: Streaming-capable SipHash Implementation#
This module provides a C-based streaming-capable implementation of
SipHash with an interface compatible with the hash functions
provided by the hashlib
standard library module. SipHash-1-3
and SipHash-2-4 variants are currently implemented. Others can be
added as needed.
This module differs from other similar modules by providing a
streaming-capable implementation (data can be passed to the hash
object in chunnks and a digest extracted at the end) and by providing
an interface compatible to the hash functions provided by the
hashlib
standard library module. Binary wheels are provied for
all supported Python releases on the most common platforms. More
platforms can be added to the build job as needed.
Following the hashlib
interface, the return value of the
digest()
method is a bytes object. SipHash
values are customarily stored as 64-bit integers. This module extends
the hashlib
interface with an additional intdigest()
method that returns the hash values as a 64-bit
signed int object.
This module is implemented as a thin Cython-based wrapper around the c-siphash library by David Rheinsberg and co-authors. The c-siphash library is based on the SipHash reference implementation by Jean-Philippe Aumasson and Daniel J. Bernstein released to the Public Domain. This module is distributed with the same license as the c-siphash library: Apache-2.0 or LGPL-2.1-or-later.
Despite implementing other SipHash variants, this module is named
siphash24
because the siphash
name was already taken on PyPI
at the time this project was created.
API#
Hash objects implementing the SipHash-1-3 and SipHash-2-4 variants are created by calling the constructor functions
- siphash24.siphash13(data=b'', /, *, key=b'')#
- siphash24.siphash24(data=b'', /, *, key=b'')#
respectively. These functions take two optional parameters:
data – initial chunk of data to hash, which must be bytes-like object. It can be passed only as positional argument.
key – key for keyed hashing, which must be a bytes-like object. The passed key can be up to 16 bytes in lenght. Shorter keys are zero padded to 16 bytes. It can be passed only as a keyword argument.
The hash objects returned but the constructor functions implement the
methods provided by the hash objects in the standard library
hashlib
module:
- hash.update(data)#
Update the hash object with the bytes-like object.
- hash.digest()#
Return the digest of the data passed to the
update()
method so far. This is an 8-bytes bytes object.
- hash.hexdigest()#
Like
digest()
except the digest is returned as a string object of double length, containing only hexadecimal digits.
- hash.copy()#
Return a copy of the hash object. This can be used to efficiently compute the digests of data sharing a common initial substring.
The interface provided by hash objects in the hashlib
module is
extended with an additional method for easy access to the hash value
as a Python integer object:
- hash.intdigest()#
Like
digest()
except the digest is returned as an int object. The returned value is a signed integer up to 64 bits in length.
To conform to the interface of the hash objects in the standard
library hashlib
module, the following values are provided as
constant attributes:
- hash.digest_size#
The size of the resulting hash in bytes. This is 8 for SipHash.
- hash.block_size#
The internal block size of the hash algorithm in bytes. This is 8 for SipHash.
- hash.name#
The canonical name of the hash as a lower-case string.
Release notes#
1.7#
Declare support for Python 3.13 in classifiers and build wheels for CPython 3.13.
Released 15-10-2024.
1.6#
For consistency with the
hashlib
module,hexdisted()
returns a string object, not bytes.
Released 03-07-2024.
1.5#
Update dependencies to latest released versions.
Add SPDX headers to all source files and add licenses text in
LICENSES
directory.
Released 30-03-2024.
1.4#
Update build dependencies.
Set default buildtype to release.
Build wheels for Python 3.12.
Released 03-10-2023.
1.3#
Update build dependencies to released versions. No functional changes.
Released 03-03-2023.
1.2#
Use c-siphash library without modifications.
Switch the build system to Meson and meson-python.
Add support for the SipHash-1-3 variant.
Released 21-11-2022.
1.1#
Added the
intdigest()
method.Added reStructuredText documentation.
Released 06-11-2022.
1.0#
Initial release, 11-09-2022.