pub struct MimcHasher { /* private fields */ }Expand description
MiMC-Feistel sponge hasher.
This struct provides the MiMC hash function with configurable parameters.
For most use cases, use MimcHasher::default() which provides parameters
compatible with Tornado Cash / circomlib.
§Example
use stealth_lib::hash::MimcHasher;
// Use default parameters (compatible with Tornado Cash)
let hasher = MimcHasher::default();
let hash = hasher.hash(123, 456);
// Hash is deterministic
assert_eq!(hasher.hash(123, 456), hasher.hash(123, 456));
// Different inputs produce different outputs
assert_ne!(hasher.hash(123, 456), hasher.hash(123, 789));Implementations§
Source§impl MimcHasher
impl MimcHasher
Sourcepub fn new(field_prime: u128, num_rounds: usize, constants: Vec<u128>) -> Self
pub fn new(field_prime: u128, num_rounds: usize, constants: Vec<u128>) -> Self
Creates a new MimcHasher with custom parameters.
§Arguments
field_prime- The field modulus for arithmetic operationsnum_rounds- Number of Feistel roundsconstants- Round constants (must have at leastnum_rounds * 2elements)
§Example
use stealth_lib::hash::MimcHasher;
let constants = vec![0u128; 20];
let hasher = MimcHasher::new(
340282366920938463463374607431768211455, // 2^128 - 1
10,
constants,
);Sourcepub fn field_prime(&self) -> u128
pub fn field_prime(&self) -> u128
Returns the field prime used by this hasher.
Sourcepub fn num_rounds(&self) -> usize
pub fn num_rounds(&self) -> usize
Returns the number of rounds used by this hasher.
Sourcepub fn hash(&self, left: u128, right: u128) -> u128
pub fn hash(&self, left: u128, right: u128) -> u128
MiMC sponge hash function.
Computes the MiMC-Feistel-Sponge hash of two input values. This is the primary hash function used for Merkle tree construction.
§Arguments
left- First input valueright- Second input value
§Returns
The hash output as a u128.
§Example
use stealth_lib::hash::MimcHasher;
let hasher = MimcHasher::default();
// Hash two values
let hash = hasher.hash(123, 456);
// Hash is deterministic
assert_eq!(hash, hasher.hash(123, 456));Sourcepub fn hash_single(&self, input: u128) -> u128
pub fn hash_single(&self, input: u128) -> u128
Trait Implementations§
Source§impl Clone for MimcHasher
impl Clone for MimcHasher
Source§fn clone(&self) -> MimcHasher
fn clone(&self) -> MimcHasher
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for MimcHasher
impl Debug for MimcHasher
Auto Trait Implementations§
impl Freeze for MimcHasher
impl RefUnwindSafe for MimcHasher
impl Send for MimcHasher
impl Sync for MimcHasher
impl Unpin for MimcHasher
impl UnwindSafe for MimcHasher
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more