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.

Type State

type State = SipState

Struct SipState

struct SipState {
    k0: u64,
    k1: u64,
    mut length: uint,
    mut v0: u64,
    mut v1: u64,
    mut v2: u64,
    mut v3: u64,
    tail: [mut u8 * 8],
    mut ntail: uint,
}

Interface 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(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.

Interface HashUtil

Method hash

fn hash() -> u64

Interface Streaming

Streaming hash-functions should implement this.

Method input

fn input(&[const u8])

Method result_bytes

fn result_bytes() -> ~[u8]

Method result_str

fn result_str() -> ~str

Method result_u64

fn result_u64() -> u64

Method reset

fn reset()

Implementation of HashUtil for A

Method hash

fn hash() -> u64

Implementation of Hash for A

Method hash_keyed

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

Implementation of io::Writer for &SipState

Method write

fn write(msg: &[const u8])

Method seek

fn seek(_x: int, _s: io::SeekStyle)

Method tell

fn tell() -> uint

Method flush

fn flush() -> int

Method get_type

fn get_type() -> io::WriterType

Implementation of Streaming for &SipState

Method input

fn input(buf: &[const u8])

Method result_u64

fn result_u64() -> u64

Method result_bytes

fn result_bytes() -> ~[u8]

Method result_str

fn result_str() -> ~str

Method reset

fn reset()

Function SipState

fn SipState(key0: u64, key1: u64) -> SipState

Function State

fn State(k0: u64, k1: u64) -> State

Function default_state

fn default_state() -> State

Function hash_keyed_2

fn hash_keyed_2<A: IterBytes, B: IterBytes>(a: &A, b: &B, k0: u64, k1: u64) ->
 u64

Function hash_keyed_3

fn hash_keyed_3<A: IterBytes, B: IterBytes,
                C: IterBytes>(a: &A, b: &B, c: &C, k0: u64, k1: u64) -> u64

Function hash_keyed_4

fn hash_keyed_4<A: IterBytes, B: IterBytes, C: IterBytes,
                D: IterBytes>(a: &A, b: &B, c: &C, d: &D, k0: u64, k1: u64) ->
 u64

Function hash_keyed_5

fn hash_keyed_5<A: IterBytes, B: IterBytes, C: IterBytes, D: IterBytes,
                E: IterBytes>(a: &A, b: &B, c: &C, d: &D, e: &E, k0: u64,
                              k1: u64) -> u64