zkhash/gmimc/
gmimc_params.rs

1use ark_ff::PrimeField;
2
3use crate::fields::utils;
4
5#[derive(Clone, Debug)]
6pub struct GmimcParams<S: PrimeField> {
7    pub(crate) t: usize, // statesize
8    pub(crate) d: usize, // sbox degree
9    pub(crate) rounds: usize,
10    pub(crate) round_constants: Vec<S>,
11}
12
13impl<S: PrimeField> GmimcParams<S> {
14    // pub const INIT_SHAKE: &'static str = "GMiMC";
15
16    pub fn new(t: usize, d: usize, rounds: usize) -> Self {
17        assert!(d == 3 || d == 5 || d == 7);
18        // let mut shake = Self::init_shake();
19        // let round_constants = Self::instantiate_rc(rounds, &mut shake);
20        let round_constants = Self::instantiate_rc(rounds);
21
22        GmimcParams {
23            t,
24            d,
25            rounds,
26            round_constants,
27        }
28    }
29
30    // fn init_shake() -> XofReaderCoreWrapper<Shake128ReaderCore> {
31    //     let mut shake = Shake128::default();
32    //     shake.update(Self::INIT_SHAKE.as_bytes());
33    //     for i in S::char().as_ref() {
34    //         shake.update(&u64::to_le_bytes(*i));
35    //     }
36    //     shake.finalize_xof()
37    // }
38
39    fn instantiate_rc(rounds: usize) -> Vec<S> {
40        (0..rounds)
41            .map(|_| utils::random_scalar())
42            .collect()
43    }
44
45    pub fn get_t(&self) -> usize {
46        self.t
47    }
48
49    pub fn get_rounds(&self) -> usize {
50        self.rounds
51    }
52}