Implementation of SipHash 2-4
See: http://131002.net/siphash/
Consider this as a main "general-purpose" hash for all hashtables: it runs at good speed (competitive with spooky and city) and permits cryptographically strong keyed hashing. Key your hashtables from a CPRNG like rand::rng.
Hash
- Types that can meaningfully be hashed should implement this.HashUtil
Streaming
- Streaming hash-functions should implement this.of HashUtil for A where <A: Hash>
of Hash for A where <A: IterBytes>
of Writer for SipState
of Streaming for SipState
default_state
Hash
Types that can meaningfully be hashed should implement this.
Note that this trait is likely to change somewhat as it is closely related to to_bytes::IterBytes
and in almost all cases presently the two are (and must be) used together.
In general, most types only need to implement IterBytes
, and the implementation of Hash
below will take care of the rest. This is the recommended approach, since constructing good keyed hash functions is quite difficult.
hash_keyed
fn hash_keyed(&self, k0: u64, k1: u64) -> u64
Compute a "keyed" hash of the value implementing the trait, taking k0
and k1
as "keying" parameters that randomize or otherwise perturb the hash function in such a way that a hash table built using such "keyed hash functions" cannot be made to perform linearly by an attacker controlling the hashtable's contents.
In practical terms, we implement this using the SipHash 2-4 function and require most types to only implement the IterBytes trait, that feeds SipHash.
HashUtil
hash
fn hash(&self) -> u64
Streaming
Streaming hash-functions should implement this.
input
fn input(&mut self, &[u8])
result_bytes
fn result_bytes(&mut self) -> ~[u8]
result_str
fn result_str(&mut self) -> ~str
result_u64
fn result_u64(&mut self) -> u64
reset
fn reset(&mut self)
HashUtil
for A
where <A: Hash>
hash
fn hash(&self) -> u64
Hash
for A
where <A: IterBytes>
hash_keyed
fn hash_keyed(&self, k0: u64, k1: u64) -> u64
Writer
for SipState
write
fn write(&mut self, msg: &[u8])
flush
fn flush(&mut self)
Streaming
for SipState
input
fn input(&mut self, buf: &[u8])
result_u64
fn result_u64(&mut self) -> u64
result_bytes
fn result_bytes(&mut self) -> ~[u8]
result_str
fn result_str(&mut self) -> ~str
reset
fn reset(&mut self)
default_state
fn default_state() -> State