pub struct RapidSecrets {
pub seed: u64,
pub secrets: [u64; 3],
}Expand description
Hold the seed and secrets to be used by rapidhash.
RapidSecrets premix the seed and generate a set of other secrets based on the seed that are all used in the hashing process. There are some quality checks on the random values to ensure a reasonable distribution of entropy in the generated secrets.
Constructing this struct is fairly cheap, but unnecessary in the critical path. We therefore
recommend instantiating it once and re-using the same instance for any persistent hashing. The
seed method is marked const to also do so at compile time.
§Minimal HashDoS Protection
We recommend changing the default seed and secrets must be changed to avoid trivial collision attacks. For persistent hashing, you can hard code your own randomized seed at compile time.
use rapidhash::v1::RapidSecrets;
const DEFAULT_SECRETS: RapidSecrets = RapidSecrets::seed(0x123456); // <-- change this value!
/// Export your chosen rapidhash version and secrets for use throughout your project.
pub fn rapidhash(data: &[u8]) -> u64 {
rapidhash::v1::rapidhash_v1_seeded(data, &DEFAULT_SECRETS)
}TODO: serde or serialization support.
Fields§
§seed: u64The core rapidhash seed.
secrets: [u64; 3]The secrets, effectively other seeds used in the hashing process.
Implementations§
Source§impl RapidSecrets
impl RapidSecrets
Sourcepub const fn seed(seed: u64) -> Self
pub const fn seed(seed: u64) -> Self
Generate secrets from a given randomized seed.
Note the chosen seed will be pre-mixed to further randomized it, and the secrets will be computed based on the seed.
If compatibility with the C++ implementation is required, use the seed_cpp method instead.
Sourcepub const fn reseed(&self) -> Self
pub const fn reseed(&self) -> Self
Creates a new RapidSecrets instance with a different seed and the same secrets.
This is useful for in-memory hashing, so we can quickly use a different seed for other HashMaps.
Sourcepub const fn seed_cpp(seed: u64) -> Self
pub const fn seed_cpp(seed: u64) -> Self
Creates a new RapidSecrets instance using a seed and secrets that are compatible with the
C++ implementation.
Note that these use the default secrets and therefore are liable to some trivial collision attacks, as randomising both the seed and secrets is necessary to provide minimal HashDoS resistance.
Trait Implementations§
Source§impl Clone for RapidSecrets
impl Clone for RapidSecrets
Source§fn clone(&self) -> RapidSecrets
fn clone(&self) -> RapidSecrets
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for RapidSecrets
Source§impl Debug for RapidSecrets
impl Debug for RapidSecrets
impl Eq for RapidSecrets
Source§impl Hash for RapidSecrets
impl Hash for RapidSecrets
Source§impl PartialEq for RapidSecrets
impl PartialEq for RapidSecrets
Source§fn eq(&self, other: &RapidSecrets) -> bool
fn eq(&self, other: &RapidSecrets) -> bool
self and other values to be equal, and is used by ==.