Hash.SipHash

lib/Hash/SipHash.gob

SipHash-1-3 (Aumasson and Bernstein): one compression round per 8-byte block and three at the end, the variant Rust's HashMap, Python and Swift use. Unlike the others in Hash it is a keyed pseudorandom function, so an attacker who sees no hash values cannot build keys that collide.

A word is one block. A run of bytes is its length as one block, then its whole words as blocks, then, if 1 to 7 bytes remain, one block holding them zero-padded. The length comes first, so the blocks say where every run ends, whatever its length, and two runs cannot run together. That costs one round per run; a length byte in the last block would be free, but would keep only the length modulo 256. The final block is SipHash's: the total length in the top byte.

The state is changed in place and each method returns the state it was given, which Hasher allows because a caller uses each state once. A state returned by value would be a new four-word record from a compression too large to inline, and the optimizer allocates such a record.

type SipHash
instance Hasher SipHash