decaf377_rdsa/
hash.rs

1use blake2b_simd::{Params, State};
2use decaf377::Fr;
3
4/// Provides H^star, the hash-to-scalar function.
5pub struct HStar {
6    state: State,
7}
8
9impl Default for HStar {
10    fn default() -> Self {
11        let state = Params::new()
12            .hash_length(64)
13            .personal(b"decaf377-rdsa---")
14            .to_state();
15        Self { state }
16    }
17}
18
19impl HStar {
20    /// Add `data` to the hash, and return `Self` for chaining.
21    pub fn update(&mut self, data: impl AsRef<[u8]>) -> &mut Self {
22        self.state.update(data.as_ref());
23        self
24    }
25
26    /// Consume `self` to compute the hash output.
27    pub fn finalize(&self) -> Fr {
28        Fr::from_le_bytes_mod_order(self.state.finalize().as_array())
29    }
30}