poseidon_parameters/
v1.rs

1pub use crate::alpha::Alpha;
2pub use crate::round_numbers::RoundNumbers;
3
4pub use crate::matrix::{mat_mul, square_mat_mul, Matrix, SquareMatrix};
5pub use crate::{
6    arc_matrix::ArcMatrix, arc_matrix::OptimizedArcMatrix, matrix_ops::MatrixOperations,
7    matrix_ops::SquareMatrixOperations, mds_matrix::MdsMatrix, mds_matrix::OptimizedMdsMatrices,
8};
9
10/// A set of Poseidon1 parameters for a given set of input parameters over decaf377::Fq.
11///
12/// The const `STATE_SIZE` corresponds to $t$ in the paper, the width of the hash function,
13/// e.g. $t=3$ corresponds to a 2-to-1 hash.
14#[derive(Clone, Debug)]
15pub struct PoseidonParameters<
16    const STATE_SIZE: usize,
17    const STATE_SIZE_MINUS_1: usize,
18    const NUM_MDS_ELEMENTS: usize,
19    const NUM_STATE_SIZE_MINUS_1_ELEMENTS: usize,
20    const NUM_ROUND_ROWS: usize,
21    const NUM_ROUND_COLS: usize,
22    const NUM_ROUND_ELEMENTS: usize,
23    const NUM_PARTIAL_ROUNDS: usize,
24> {
25    // Input parameters.
26    /// Security level.
27    pub M: usize,
28
29    // Generated parameters.
30    /// Exponent of the Sbox, i.e. S-box(x) = x^{\alpha} used in the `SubWords` step
31    pub alpha: Alpha,
32
33    /// Round numbers
34    pub rounds: RoundNumbers,
35
36    /// `t x t` MDS matrix used in the `MixLayer` step
37    pub mds: MdsMatrix<
38        STATE_SIZE,
39        STATE_SIZE_MINUS_1,
40        NUM_MDS_ELEMENTS,
41        NUM_STATE_SIZE_MINUS_1_ELEMENTS,
42    >,
43
44    /// `num_total_rounds x t` matrix of constants used in the `AddRoundConstant` step
45    pub arc: ArcMatrix<NUM_ROUND_ROWS, NUM_ROUND_COLS, NUM_ROUND_ELEMENTS>,
46
47    /// Optimized round constants.
48    pub optimized_arc: OptimizedArcMatrix<NUM_ROUND_ROWS, NUM_ROUND_COLS, NUM_ROUND_ELEMENTS>,
49
50    /// Optimized MDS matrices.
51    pub optimized_mds: OptimizedMdsMatrices<
52        NUM_ROUND_ROWS,
53        NUM_PARTIAL_ROUNDS,
54        STATE_SIZE,
55        STATE_SIZE_MINUS_1,
56        NUM_MDS_ELEMENTS,
57        NUM_STATE_SIZE_MINUS_1_ELEMENTS,
58    >,
59}