Siphashc

raw JSON →
2.7 verified Mon Apr 27 auth: no python

A C-based Python module implementing SipHash-2-4, a fast cryptographic hash function designed for hash tables and message authentication. Current version is 2.7, requiring Python >=3.10. Releases are intermittent.

pip install siphashc
error TypeError: a bytes-like object is required, not 'str'
cause Passing a string instead of bytes to siphash.
fix
Encode the string: siphashc.siphash('hello'.encode('utf-8'))
error AttributeError: module 'siphashc' has no attribute 'siphash'
cause Wrong import path or older version.
fix
Ensure siphashc >=2.0 is installed and use import siphashc, then siphashc.siphash().
gotcha The function only accepts bytes objects; strings must be encoded first.
fix Call data.encode('utf-8') before hashing.
gotcha siphashc returns a 64-bit unsigned integer, not a hex string.
fix Convert to hex with hex(hashed) if needed.
deprecated Python 3.9 and below are no longer supported as of version 2.7.
fix Upgrade to Python >=3.10.

Hash a bytes object using SipHash-2-4.

import siphashc
data = b'hello world'
hashed = siphashc.siphash(data)
print(hashed)  # e.g. 0x9f8d5a4b3c2e1f0a