Skip to main content

miden_crypto/hash/
mod.rs

1//! Cryptographic hash functions used by the Miden protocol.
2
3use crate::{Felt, Word, ZERO};
4
5/// Generic digest types for binary hash functions.
6pub(crate) mod digest;
7
8/// Blake3 hash function.
9pub mod blake;
10
11/// Keccak hash function.
12pub mod keccak;
13
14/// SHA-2 hash functions (SHA-256 and SHA-512).
15pub mod sha2;
16
17/// Poseidon2 hash function.
18pub mod poseidon2 {
19    pub use p3_goldilocks::Poseidon2Goldilocks;
20
21    pub use super::algebraic_sponge::poseidon2::{
22        Poseidon2, Poseidon2Challenger, Poseidon2Compression, Poseidon2Hasher,
23        Poseidon2Permutation256,
24    };
25}
26
27/// Rescue Prime Optimized (RPO) hash function.
28pub mod rpo {
29    pub use super::algebraic_sponge::rescue::rpo::{
30        Rpo256, RpoChallenger, RpoCompression, RpoHasher, RpoPermutation256,
31    };
32}
33
34/// Rescue Prime Extended (RPX) hash function.
35pub mod rpx {
36    pub use super::algebraic_sponge::rescue::rpx::{
37        Rpx256, RpxChallenger, RpxCompression, RpxHasher, RpxPermutation256,
38    };
39}
40
41mod algebraic_sponge;
42
43// TRAITS
44// ================================================================================================
45
46/// Extension trait for hashers to provide iterator-based hashing.
47pub trait HasherExt {
48    /// The digest type produced by this hasher.
49    type Digest;
50
51    /// Hashes an iterator of byte slices.
52    ///
53    /// This method allows for more efficient hashing by avoiding the need to
54    /// allocate a contiguous buffer when the input data is already available
55    /// as discrete slices.
56    fn hash_iter<'a>(slices: impl Iterator<Item = &'a [u8]>) -> Self::Digest;
57}