SipHash
raw JSON → 0.0.1 verified Fri May 01 auth: no python
A pure Python implementation of SipHash, a fast short-input PRF. Version 0.0.1 is the latest and only release; no active development.
pip install siphash Common errors
error TypeError: a bytes-like object is required, not 'str' ↓
cause Message passed as string instead of bytes.
fix
Use msg = 'hello'.encode('utf-8')
error ValueError: Key must be exactly 16 bytes long ↓
cause Key length is not 16 bytes.
fix
Ensure key is 16 bytes: key = b'sixteenbyteslong'
Warnings
gotcha Key must be exactly 16 bytes; any other length raises ValueError. ↓
fix Ensure key length is 16.
gotcha SipHash_2_4 and SipHash_1_3 are the only variants; no 8-round or 4-round versions. ↓
fix Use SipHash_2_4 for default security.
gotcha Input message must be bytes; passing str will cause TypeError. ↓
fix Encode strings before hashing: msg.encode('utf-8')
Imports
- SipHash_2_4
from siphash import SipHash_2_4
Quickstart
from siphash import SipHash_2_4
key = b'\x00' * 16 # 128-bit key
msg = b'hello'
siphash = SipHash_2_4(key)
digest = siphash(msg)
print(digest.hex()) # 64-bit digest