Library / Hashing / Hashing / SipHasher
SipHasher
A DoS-resistant Hasher OF K backed by SipHash-2-4-64. Keyed by a process-global 16-byte secret (EV_siphash_native.hpp, seeded once from OS entropy), so an attacker cannot predict bucket distribution (hash-flooding defense). The default hasher inside ProHashDictionary; opt-in elsewhere as Dictionary[K, V, SipHasher[K]] / Set[V, SipHasher[V]].
Constructors 4
INIT()The DEFAULT — canonical SipHash-2-4, keyed from OS entropy.
INIT(SipVariant v)
Opt in to the SipHash-1-3 round schedule (a third fewer rounds; the schedule Rust ships). Still keyed from OS entropy. 1-3 is a WEAKER PRF than 2-4 — choosing it is a security decision, not a performance one. See SipVariant.
INIT(uint64 key0, uint64 key1)
Adopt an explicit key — used by clone(), and available when a caller needs a REPRODUCIBLE digest (a fixed key hashes deterministically across runs).
INIT(uint64 key0, uint64 key1, SipVariant v)
Methods 6
METHOD clone() RETURNS SipHasher[K]reads
Hasher EXTENDS Cloneable — every dictionary DUPLICATEs its hasher when cloned. The clone MUST carry the SAME key AND the same variant: re-seeding (or re-scheduling) here would make the clone disagree with the entries the cloned dictionary copied over, and every lookup in the copy would miss.
METHOD roundSchedule() RETURNS SipVariantreads
Which round schedule this hasher runs.
METHOD hashSlice(REFERENCE binary[] buf, int64 off, int64 len) RETURNS uint64reads
SipHash-64 over a RAW BYTE SLICE buf[off .. off+len) — the fast byte path, and
the one byte-keyed callers (StringKeyedDictionary / ProHashDictionary) should use.
This is what hashBuffer below cannot be. It absorbs each 64-bit message word with
ONE System->memoryWord wide load instead of assembling it from eight
bounds-checked per-byte accessor calls, and HOTLOOP hoists the trailing bytes'
per-element bounds check into a single up-front range check. Neither skips a check
— both move it — so the memory-safety floor is unchanged.
METHOD hashBuffer(REFERENCE ByteBuffer bytes) RETURNS uint64reads
SipHash-64 over a ByteBuffer — the byte-sequence core for the generic Hasher OF K
String path.
This used to assemble each 64-bit word from EIGHT bounds-checked, handle-indirected
bytes[i] accessor calls — the per-element dispatch the s05 study named as the real
bottleneck. It no longer does: ByteBuffer.data() hands back a non-owning REFERENCE
to the raw binary[] storage (zero copy — the buffer keeps ownership), which is
exactly the handle the bulk primitives need. So this now simply delegates to
hashSlice, and the ByteBuffer path gets System->memoryWord + HOTLOOP for free.
One implementation of SipHash over bytes, not two.
METHOD hashWord(uint64 m) RETURNS uint64reads
SipHash-64 over a single 8-byte word (primitive keys). No byte loop, so none of the bulk-memory levers apply here — this path is pure round arithmetic, and the only lever on it is the round SCHEDULE (SipVariant).
METHOD hash(REFERENCE K key) RETURNS uint64reads
Hasher OF K — the 64-bit SipHash-2-4 digest.