p3_monty_31/no_packing/
poseidon2.rs

1//! These are just simple wrapper structs allowing us to implement Poseidon2 Internal/ExternalLayer on top of them.
2//!
3//! They are used only in the case that none of the vectorization architectures (AVX2/AVX512/NEON) are available.
4
5use alloc::vec::Vec;
6use core::marker::PhantomData;
7
8use p3_poseidon2::{ExternalLayerConstants, ExternalLayerConstructor, InternalLayerConstructor};
9
10use crate::{FieldParameters, InternalLayerBaseParameters, MontyField31, MontyParameters};
11
12/// The internal layers of the Poseidon2 permutation for Monty31 fields.
13#[derive(Debug, Clone)]
14pub struct Poseidon2InternalLayerMonty31<
15    MP: MontyParameters,
16    const WIDTH: usize,
17    ILP: InternalLayerBaseParameters<MP, WIDTH>,
18> {
19    pub(crate) internal_constants: Vec<MontyField31<MP>>,
20    _phantom: PhantomData<ILP>,
21}
22
23/// The external layers of the Poseidon2 permutation for Monty31 fields.
24#[derive(Debug, Clone)]
25pub struct Poseidon2ExternalLayerMonty31<MP: MontyParameters, const WIDTH: usize> {
26    pub(crate) external_constants: ExternalLayerConstants<MontyField31<MP>, WIDTH>,
27}
28
29impl<FP: FieldParameters, const WIDTH: usize, ILP: InternalLayerBaseParameters<FP, WIDTH>>
30    InternalLayerConstructor<MontyField31<FP>> for Poseidon2InternalLayerMonty31<FP, WIDTH, ILP>
31{
32    fn new_from_constants(internal_constants: Vec<MontyField31<FP>>) -> Self {
33        Self {
34            internal_constants,
35            _phantom: PhantomData,
36        }
37    }
38}
39
40impl<FP: FieldParameters, const WIDTH: usize> ExternalLayerConstructor<MontyField31<FP>, WIDTH>
41    for Poseidon2ExternalLayerMonty31<FP, WIDTH>
42{
43    fn new_from_constants(
44        external_constants: ExternalLayerConstants<MontyField31<FP>, WIDTH>,
45    ) -> Self {
46        Self { external_constants }
47    }
48}