STHash is a fast, keyed, cryptographic hash function designed to process large, possibly untrusted data.
The flipside is that using a secret key (or, in this implementation, a secret seed) is mandatory.
A typical use of STHash is to compute keys for locally cached objects.
The construction relies on:
The current code is portable, written in safe Rust, and has a lot of room for optimization.
However, even without vectorization, it is already consistently faster than optimized BLAKE2bp implementations (using the blake2b-simd
crate) on all platforms.
You can expect more speed increase in future versions.
```rust use sthash::*; use rand::{thread_rng, RngCore};
// This must be a random, secret seed. let seed = [u8; SEEDBYTES]; threadrng().fill_bytes(&mut seed);
// The key constructor accepts an optional application name
// Different personalization strings produce different keys
// from the same seed
.
let key = Key::from_seed(&seed, Some(b"Documentation example"));
// Another personalization string, such as the purpose of the
// Hasher
, can be provided here as well.
let hasher = Hasher::new(key, None);
// Returns a 256-bit hash. let h1 = hasher.hash(data);
// Hasher
structures can safely be reused to hash more data.
let h2 = hasher.hash(data2);
```