pub fn find_poseidon_ark_and_mds<F: PrimeField>(
    prime_bits: u64,
    rate: usize,
    full_rounds: u64,
    partial_rounds: u64,
    skip_matrices: u64,
) -> (Vec<Vec<F>>, Vec<Vec<F>>) {
    let mut lfsr = PoseidonGrainLFSR::new(
        false,
        prime_bits,
        (rate + 1) as u64,
        full_rounds,
        partial_rounds,
    );

    let mut ark = Vec::<Vec<F>>::with_capacity((full_rounds + partial_rounds) as usize);
    for _ in 0..(full_rounds + partial_rounds) {
        ark.push(lfsr.get_field_elements_rejection_sampling(rate + 1));
    }

    let mut mds = Vec::<Vec<F>>::with_capacity(rate + 1);
    mds.resize(rate + 1, vec![F::zero(); rate + 1]);
    for _ in 0..skip_matrices {
        let _ = lfsr.get_field_elements_mod_p::<F>(2 * (rate + 1));
    }

    // a qualifying matrix must satisfy the following requirements
    // - there is no duplication among the elements in x or y
    // - there is no i and j such that x[i] + y[j] = p
    // - the resultant MDS passes all the three tests

    let xs = lfsr.get_field_elements_mod_p::<F>(rate + 1);
    let ys = lfsr.get_field_elements_mod_p::<F>(rate + 1);

    for i in 0..(rate + 1) {
        for j in 0..(rate + 1) {
            mds[i][j] = (xs[i] + &ys[j]).inverse().unwrap();
        }
    }

    (ark, mds)
}
/// Internal function that computes the ark and mds from the Poseidon Grain LFSR.
Internal function that computes the ark and mds from the Poseidon Grain LFSR.
Internal function that computes the ark and mds from the Poseidon Grain LFSR .
pub fn find_poseidon_ark_and_mds<F: PrimeField>(
    prime_bits: u64,
    rate: usize,
    full_rounds: u64,
    partial_rounds: u64,
    skip_matrices: u64,
) -> (Vec<Vec<F>>, Vec<Vec<F>>) {
    let mut lfsr = PoseidonGrainLFSR::new(
        false,
        prime_bits,
        (rate + 1) as u64,
        full_rounds,
        partial_rounds,
    );
    let mut ark = Vec::<Vec<F>>::with_capacity((full_rounds + partial_rounds) as usize);
    for _ in 0..(full_rounds + partial_rounds) {
        ark.push(lfsr.get_field_elements_rejection_sampling(rate + 1));
    }
    let mut mds = Vec::<Vec<F>>::with_capacity(rate + 1);
    mds.resize(rate + 1, vec![F::zero(); rate + 1]);
    for _ in 0..skip_matrices {
        let _ = lfsr.get_field_elements_mod_p::<F>(2 * (rate + 1));
    }
    // a qualifying matrix must satisfy the following requirements
    // - there is no duplication among the elements in x or y
    // - there is no i and j such that x[i] + y[j] = p
    // - the resultant MDS passes all the three tests
    let xs = lfsr.get_field_elements_mod_p::<F>(rate + 1);
    let ys = lfsr.get_field_elements_mod_p::<F>(rate + 1);
    for i in 0..(rate + 1) {
        for j in 0..(rate + 1) {
            mds[i][j] = (xs[i] + &ys[j]).inverse().unwrap();
        }
    }
    (ark, mds)
}
pub fn find_poseidon_ark_and_mds < F : PrimeField > ( prime_bits : u64 , rate : usize , full_rounds : u64 , partial_rounds : u64 , skip_matrices : u64 , ) -> ( Vec < Vec < F > > , Vec < Vec < F > > ) { let mut lfsr = PoseidonGrainLFSR :: new ( false , prime_bits , ( rate + 1 ) as u64 , full_rounds , partial_rounds , ) ; let mut ark = Vec :: < Vec < F > > :: with_capacity ( ( full_rounds + partial_rounds ) as usize ) ; for _ in 0 .. ( full_rounds + partial_rounds ) { ark . push ( lfsr . get_field_elements_rejection_sampling ( rate + 1 ) ) ; } let mut mds = Vec :: < Vec < F > > :: with_capacity ( rate + 1 ) ; mds . resize ( rate + 1 , vec ! [ F zero ( ) rate 1 ] ) ; for _ in 0 .. skip_matrices { let _ = lfsr . get_field_elements_mod_p :: < F > ( 2 * ( rate + 1 ) ) ; } // a qualifying matrix must satisfy the following requirements // - there is no duplication among the elements in x or y // - there is no i and j such that x[i] + y[j] = p // - the resultant MDS passes all the three tests let xs = lfsr . get_field_elements_mod_p :: < F > ( rate + 1 ) ; let ys = lfsr . get_field_elements_mod_p :: < F > ( rate + 1 ) ; for i in 0 .. ( rate + 1 ) { for j in 0 .. ( rate + 1 ) { mds [ i ] [ j ] = ( xs [ i ] + & ys [ j ] ) . inverse ( ) . unwrap ( ) ; } } ( ark , mds ) }
Internal function that computes the ark and mds from the Poseidon Grain LFSR.
Internal function that computes the ark and mds from the Poseidon Grain LFSR .
prime_bits
u64
rate
usize
full_rounds
u64
partial_rounds
u64
skip_matrices
u64