miden_core/chiplets/hasher.rs
1//! TODO: add docs
2use super::Felt;
3pub use crate::crypto::hash::{Rpo256 as Hasher, RpoDigest as Digest};
4
5/// Number of field element needed to represent the sponge state for the hash function.
6///
7/// This value is set to 12: 8 elements are reserved for rate and the remaining 4 elements are
8/// reserved for capacity. This configuration enables computation of 2-to-1 hash in a single
9/// permutation.
10pub const STATE_WIDTH: usize = Hasher::STATE_WIDTH;
11
12/// Number of field elements in the rate portion of the hasher's state.
13pub const RATE_LEN: usize = 8;
14
15// PASS-THROUGH FUNCTIONS
16// ================================================================================================
17
18/// Returns a hash of two digests. This method is intended for use in construction of Merkle trees.
19#[inline(always)]
20pub fn merge(values: &[Digest; 2]) -> Digest {
21 Hasher::merge(values)
22}
23
24/// Returns a hash of two digests with a specified domain.
25#[inline(always)]
26pub fn merge_in_domain(values: &[Digest; 2], domain: Felt) -> Digest {
27 Hasher::merge_in_domain(values, domain)
28}
29
30/// Returns a hash of the provided list of field elements.
31#[inline(always)]
32pub fn hash_elements(elements: &[Felt]) -> Digest {
33 Hasher::hash_elements(elements)
34}
35
36/// Applies Rescue-XLIX round function to the provided state.
37///
38/// The function takes sponge state as an input and applies a single Rescue-XLIX round to it. The
39/// round number must be specified via `round` parameter, which must be between 0 and 6 (both
40/// inclusive).
41#[inline(always)]
42pub fn apply_round(state: &mut [Felt; STATE_WIDTH], round: usize) {
43 Hasher::apply_round(state, round)
44}
45
46/// Applies Rescue-XLIX permutation (7 rounds) to the provided state.
47#[inline(always)]
48pub fn apply_permutation(state: &mut [Felt; STATE_WIDTH]) {
49 Hasher::apply_permutation(state)
50}