Skip to main content

A CFFI-based implementation of SipHash24

Project description

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/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

csiphash-0.0.3.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

csiphash-0.0.3-cp27-none-macosx_10_12_intel.whl (18.7 kB view details)

Uploaded CPython 2.7macOS 10.12+ Intel (x86-64, i386)

File details

Details for the file csiphash-0.0.3.tar.gz.

File metadata

  • Download URL: csiphash-0.0.3.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for csiphash-0.0.3.tar.gz
Algorithm Hash digest
SHA256 5a930c98d052d298814f98dd5a980045f4a1d617e1d2604e1e9c7c841650e29b
MD5 e3e747b650101d8413f1d555722824a9
BLAKE2b-256 370880bfcaf11d0c32a44731465681eebcf097af100670219652d55aca081b5f

See more details on using hashes here.

File details

Details for the file csiphash-0.0.3-cp27-none-macosx_10_12_intel.whl.

File metadata

File hashes

Hashes for csiphash-0.0.3-cp27-none-macosx_10_12_intel.whl
Algorithm Hash digest
SHA256 87c5919498df2c8d749980ab55a4d7e50ef74c98e337003d2e5bf6681ba161ab
MD5 797ce39af4249d0a14431f7642ee179f
BLAKE2b-256 59405f968b4eb120eae6c349b1a11f50d9f049a3deb33918373847b601b8d9cc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page