starkom-poseidon2 6.3.0

Starkom's implementation of the Poseidon2 algebraic hash.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
use starkom_ff::PrimeField;

/// Helper function to decode a binary file of packed field elements.
pub(crate) fn decode_constants<F: PrimeField, const N: usize>(bytes: &[u8]) -> [F; N] {
    let repr_size = (F::NUM_BITS >> 3) + ((F::NUM_BITS & 7) != 0) as usize;
    assert_eq!(bytes.len(), N * repr_size);
    let mut constants = [F::ZERO; N];
    for i in 0..N {
        let bytes = &bytes[(i * repr_size)..((i + 1) * repr_size)];
        constants[i] = F::try_from_le_bytes(bytes).unwrap();
    }
    constants
}