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§

source

fn init(&mut self, domain_param: H::D) -> &mut dyn Hasher<H>

Set the initial state based on domain separation string generated from H::domain_string(domain_param)

source

fn reset(&mut self) -> &mut dyn Hasher<H>

Restore the initial state that was set most recently

source

fn update(&mut self, input: &H) -> &mut dyn Hasher<H>

Consume hash input

source

fn digest(&mut self) -> Fp

Obtain has result output

Provided Methods§

source

fn hash(&mut self, input: &H) -> Fp

Hash input and obtain result output

source

fn init_and_hash(&mut self, domain_param: H::D, input: &H) -> Fp

Initialize state, hash input and obtain result output

Implementors§

source§

impl<SC: SpongeConstants, H: Hashable> Hasher<H> for Poseidon<SC, H>where H::D: DomainParameter,