Skip to main content

SipHash is a hash function and message authentication code that is secure, fast and simple. It accepts a 128-bit secret key and a variable-length message, and returns a 64-bit hash. It performs better than most cryptographic hash function-based MACs (especially for short inputs), and offers much better security than non-cryptographic hash functions, providing resistance against hash-flooding DoS attacks. As a result, it is now used as the hash function of choice for hash tables in Python, Ruby, Rust and Redis.

This Python package is the SipHash-2-4 C reference implementation, wrapped with CFFI. It’s incredibly fast: amortized hashing times tested as follows on a mid-2015 MacBook Pro:

Message Size

Time per Hash (Amortized over 1M)

43 bytes

4.89 microseconds

256 bytes

5.00 microseconds

1500 bytes

6.12 microseconds

1 MiB

0.88 milliseconds

Installation

You can get this library with pip:

pip install csiphash

Usage

Currently there’s just a single function, siphash24(), that accepts a secret key bytestring of length 16 and an arbitrary length bytestring for the message, and returns an 8-byte digest bytestring:

>>> from csiphash import siphash24
>>> siphash24(b'\x00' * 16, b'hello, world!\n')
b'\xf1G4\x95\xa5\xaa\xc2b'

If you want to specify keys in hexadecimal, use .decode('hex'):

>>> siphash24('abcdef01234567899876543210fedcba'.decode('hex'), b'hello, world!\n')
'\xd3\xd4N\x1dk\x1f$='

If you want digests in hexadecimal, use .encode('hex'):

>>> siphash24(b'\x00' * 16, b'hello, world!\n').encode('hex')
'f1473495a5aac262'

License

The reference C implementation of SipHash is bundled with this library. It was written by Jean-Philippe Aumasson and Daniel J. Bernstein, and is released under the CC0.

Six is bundled with this library. It was written by Benjamin Peterson, and is licensed under the MIT License.

All other software in this library is released under the UNLICENSE:

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.

In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to http://unlicense.org/

Release files for csiphash 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for csiphash 0.0.5
File Size Uploaded
csiphash-0.0.5.tar.gz 12.9 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for csiphash 0.0.5
File Interpreter ABI Platform
csiphash-0.0.5-cp36-cp36m-macosx_10_12_x86_64.whl CPython 3.6 CPython 3.6 pymalloc macOS 10.12+ x86-64 Details
csiphash-0.0.5-cp27-cp27m-macosx_10_12_x86_64.whl CPython 2.7 CPython 2.7 pymalloc macOS 10.12+ x86-64 Details

Total release size: 46.4 kB

Release files / csiphash-0.0.5.tar.gz

Download URL csiphash-0.0.5.tar.gz
Size 12.9 kB
Tags Source
SHA-256 checksum
How to use checksums
17eade97b880b40f1f090ff00e3fb60381cdc7d5aac53f4ce89c4ddb466a9900
BLAKE2b-256 checksum
How to use checksums
c534906ea34f74f5dd53a066f16cf5fe9cdf02bd2fd1be3451a2ddc26c9dec68
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / csiphash-0.0.5-cp36-cp36m-macosx_10_12_x86_64.whl

Download URL csiphash-0.0.5-cp36-cp36m-macosx_10_12_x86_64.whl
Size 16.8 kB
Tags CPython 3.6 CPython 3.6 pymalloc macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
ff6d150adeb519467aabc4a84ce5e7470b7ca947b892cb8d17c3720fb9e80640
BLAKE2b-256 checksum
How to use checksums
5e3f2b45249a98aaf56515f8aec62f0b77da471a8e507e6982e61fe27f068e45
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / csiphash-0.0.5-cp27-cp27m-macosx_10_12_x86_64.whl

Download URL csiphash-0.0.5-cp27-cp27m-macosx_10_12_x86_64.whl
Size 16.7 kB
Tags CPython 2.7 CPython 2.7 pymalloc macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
fb44ea5aa5a36b4b45f4af9efb48fe256c96438eaaf180869c3462f5b76be6a6
BLAKE2b-256 checksum
How to use checksums
a0e319bd06d65ce8e932a61332b4b00aa986974581dfdbe075eb799b656610d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.0.5 This release

3 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page