Trait mina_hasher::Hasher
source · pub trait Hasher<H: Hashable> {
// Required methods
fn init(&mut self, domain_param: H::D) -> &mut dyn Hasher<H>;
fn reset(&mut self) -> &mut dyn Hasher<H>;
fn update(&mut self, input: &H) -> &mut dyn Hasher<H>;
fn digest(&mut self) -> Fp;
// Provided methods
fn hash(&mut self, input: &H) -> Fp { ... }
fn init_and_hash(&mut self, domain_param: H::D, input: &H) -> Fp { ... }
}
Expand description
Interface for hashing Hashable
inputs
Mina uses a unique hasher configured with domain separation for each type of object hashed.
The underlying hash parameters are large and costly to initialize, so the Hasher
interface
provides a reusable context for efficient hashing with domain separation.
Example usage
use mina_hasher::{create_legacy, Fp, Hashable, Hasher, ROInput};
#[derive(Clone)]
struct Something;
impl Hashable for Something {
type D = u32;
fn to_roinput(&self) -> ROInput {
let mut roi = ROInput::new();
// ... serialize contents of self
roi
}
fn domain_string(id: Self::D) -> Option<String> {
format!("Something {}", id).into()
}
}
let mut hasher = create_legacy::<Something>(123);
let output: Fp = hasher.hash(&Something { });
Required Methods§
Provided Methods§
sourcefn init_and_hash(&mut self, domain_param: H::D, input: &H) -> Fp
fn init_and_hash(&mut self, domain_param: H::D, input: &H) -> Fp
Initialize state, hash input and obtain result output