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.
State
SipState
Hash
- Types that can meaningfully be hashed should implement this.HashUtil
Streaming
- Streaming hash-functions should implement this.of HashUtil for A
of Hash for A
of io::Writer for &SipState
of Streaming for &SipState
SipState
State
default_state
hash_keyed_2
hash_keyed_3
hash_keyed_4
hash_keyed_5
State
type State = SipState
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,
}
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(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() -> u64
Streaming
Streaming hash-functions should implement this.
input
fn input(&[const u8])
result_bytes
fn result_bytes() -> ~[u8]
result_str
fn result_str() -> ~str
result_u64
fn result_u64() -> u64
reset
fn reset()
HashUtil
for A
hash
fn hash() -> u64
Hash
for A
hash_keyed
fn hash_keyed(k0: u64, k1: u64) -> u64
io::Writer
for &SipState
write
fn write(msg: &[const u8])
seek
fn seek(_x: int, _s: io::SeekStyle)
tell
fn tell() -> uint
flush
fn flush() -> int
get_type
fn get_type() -> io::WriterType
Streaming
for &SipState
input
fn input(buf: &[const u8])
result_u64
fn result_u64() -> u64
result_bytes
fn result_bytes() -> ~[u8]
result_str
fn result_str() -> ~str
reset
fn reset()
SipState
fn SipState(key0: u64, key1: u64) -> SipState
State
fn State(k0: u64, k1: u64) -> State
default_state
fn default_state() -> State
hash_keyed_2
fn hash_keyed_2<A: IterBytes, B: IterBytes>(a: &A, b: &B, k0: u64, k1: u64) ->
u64
hash_keyed_3
fn hash_keyed_3<A: IterBytes, B: IterBytes,
C: IterBytes>(a: &A, b: &B, c: &C, k0: u64, k1: u64) -> u64
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
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