|
@@ -13,9 +13,12 @@ pub trait HashFunction {
|
|
// type Range;
|
|
// type Range;
|
|
type Description: Copy + Debug;
|
|
type Description: Copy + Debug;
|
|
|
|
|
|
- /// Sample hash function.
|
|
|
|
|
|
+ /// Sample a random hash function.
|
|
fn sample(range_size: u64) -> Self;
|
|
fn sample(range_size: u64) -> Self;
|
|
|
|
|
|
|
|
+ /// Sample a hash function using a given seed.
|
|
|
|
+ fn from_seed(range_size: u64, seed: [u8; 32]) -> Self;
|
|
|
|
+
|
|
fn from_description(description: Self::Description) -> Self;
|
|
fn from_description(description: Self::Description) -> Self;
|
|
fn to_description(&self) -> Self::Description;
|
|
fn to_description(&self) -> Self::Description;
|
|
|
|
|
|
@@ -71,6 +74,12 @@ impl HashFunction for AesHashFunction {
|
|
self.description.range_size
|
|
self.description.range_size
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ fn from_seed(range_size: u64, seed: [u8; 32]) -> Self {
|
|
|
|
+ let mut rng = ChaCha12Rng::from_seed(seed);
|
|
|
|
+ let key = rng.gen();
|
|
|
|
+ Self::from_description(AesHashFunctionDescription { range_size, key })
|
|
|
|
+ }
|
|
|
|
+
|
|
fn sample(range_size: u64) -> Self {
|
|
fn sample(range_size: u64) -> Self {
|
|
let key: [u8; 16] = thread_rng().gen();
|
|
let key: [u8; 16] = thread_rng().gen();
|
|
Self::from_description(AesHashFunctionDescription { range_size, key })
|
|
Self::from_description(AesHashFunctionDescription { range_size, key })
|