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.

Trait 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.

Method 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.

Trait HashUtil

Method hash

fn hash(&self) -> u64

Trait Streaming

Streaming hash-functions should implement this.

Method input

fn input(&mut self, &[u8])

Method result_bytes

fn result_bytes(&mut self) -> ~[u8]

Method result_str

fn result_str(&mut self) -> ~str

Method result_u64

fn result_u64(&mut self) -> u64

Method reset

fn reset(&mut self)

Implementation of HashUtil for A where <A: Hash>

Method hash

fn hash(&self) -> u64

Implementation of Hash for A where <A: IterBytes>

Method hash_keyed

fn hash_keyed(&self, k0: u64, k1: u64) -> u64

Implementation of Writer for SipState

Method write

fn write(&mut self, msg: &[u8])

Method flush

fn flush(&mut self)

Implementation of Streaming for SipState

Method input

fn input(&mut self, buf: &[u8])

Method result_u64

fn result_u64(&mut self) -> u64

Method result_bytes

fn result_bytes(&mut self) -> ~[u8]

Method result_str

fn result_str(&mut self) -> ~str

Method reset

fn reset(&mut self)

Function default_state

fn default_state() -> State