Struct snarkvm_algorithms::crypto_hash::poseidon::PoseidonSponge
source · pub struct PoseidonSponge<F: PrimeField, const RATE: usize, const CAPACITY: usize> {
pub mode: DuplexSpongeMode,
/* private fields */
}
Expand description
A duplex sponge based using the Poseidon permutation.
This implementation of Poseidon is entirely from Fractal’s implementation in COS20 with small syntax changes.
Fields§
§mode: DuplexSpongeMode
Current mode (whether its absorbing or squeezing)
Implementations§
source§impl<F: PrimeField, const RATE: usize> PoseidonSponge<F, RATE, 1>
impl<F: PrimeField, const RATE: usize> PoseidonSponge<F, RATE, 1>
sourcepub fn compress_elements<TargetField: PrimeField, I: Iterator<Item = (F, F)>>(
&self,
src_limbs: Peekable<I>,
ty: OptimizationType
) -> Vec<F>
pub fn compress_elements<TargetField: PrimeField, I: Iterator<Item = (F, F)>>( &self, src_limbs: Peekable<I>, ty: OptimizationType ) -> Vec<F>
Compress every two elements if possible. Provides a vector of (limb, num_of_additions), both of which are F.
sourcepub fn get_limbs_representations<TargetField: PrimeField>(
elem: &TargetField,
optimization_type: OptimizationType
) -> SmallVec<[F; 10]>
pub fn get_limbs_representations<TargetField: PrimeField>( elem: &TargetField, optimization_type: OptimizationType ) -> SmallVec<[F; 10]>
Convert a TargetField
element into limbs (not constraints)
This is an internal function that would be reused by a number of other functions
sourcepub fn get_limbs_representations_from_big_integer<TargetField: PrimeField>(
elem: &<TargetField as PrimeField>::BigInteger,
optimization_type: OptimizationType
) -> SmallVec<[F; 10]>
pub fn get_limbs_representations_from_big_integer<TargetField: PrimeField>( elem: &<TargetField as PrimeField>::BigInteger, optimization_type: OptimizationType ) -> SmallVec<[F; 10]>
Obtain the limbs directly from a big int
sourcepub fn push_elements_to_sponge<TargetField: PrimeField>(
&mut self,
src: impl IntoIterator<Item = TargetField>,
ty: OptimizationType
)
pub fn push_elements_to_sponge<TargetField: PrimeField>( &mut self, src: impl IntoIterator<Item = TargetField>, ty: OptimizationType )
Push elements to sponge, treated in the non-native field representations.
sourcepub fn get_bits(&mut self, num_bits: usize) -> Vec<bool>
pub fn get_bits(&mut self, num_bits: usize) -> Vec<bool>
obtain random bits from hashchain. not guaranteed to be uniformly distributed, should only be used in certain situations.
sourcepub fn get_fe<TargetField: PrimeField>(
&mut self,
num_elements: usize,
outputs_short_elements: bool
) -> SmallVec<[TargetField; 10]>
pub fn get_fe<TargetField: PrimeField>( &mut self, num_elements: usize, outputs_short_elements: bool ) -> SmallVec<[TargetField; 10]>
obtain random field elements from hashchain. not guaranteed to be uniformly distributed, should only be used in certain situations.
Trait Implementations§
source§impl<F: PrimeField, const RATE: usize> AlgebraicSponge<F, RATE> for PoseidonSponge<F, RATE, 1>
impl<F: PrimeField, const RATE: usize> AlgebraicSponge<F, RATE> for PoseidonSponge<F, RATE, 1>
source§fn absorb_native_field_elements<T: ToConstraintField<F>>(
&mut self,
elements: &[T]
)
fn absorb_native_field_elements<T: ToConstraintField<F>>( &mut self, elements: &[T] )
Takes in field elements.
source§fn absorb_nonnative_field_elements<Target: PrimeField>(
&mut self,
elements: impl IntoIterator<Item = Target>
)
fn absorb_nonnative_field_elements<Target: PrimeField>( &mut self, elements: impl IntoIterator<Item = Target> )
Takes in field elements.
source§fn squeeze_short_nonnative_field_elements<Target: PrimeField>(
&mut self,
num: usize
) -> SmallVec<[Target; 10]>
fn squeeze_short_nonnative_field_elements<Target: PrimeField>( &mut self, num: usize ) -> SmallVec<[Target; 10]>
Takes out field elements of 168 bits.
§type Parameters = Arc<PoseidonParameters<F, RATE, 1>>
type Parameters = Arc<PoseidonParameters<F, RATE, 1>>
fn sample_parameters() -> Self::Parameters
source§fn new_with_parameters(parameters: &Self::Parameters) -> Self
fn new_with_parameters(parameters: &Self::Parameters) -> Self
source§fn squeeze_nonnative_field_elements<Target: PrimeField>(
&mut self,
num: usize
) -> SmallVec<[Target; 10]>
fn squeeze_nonnative_field_elements<Target: PrimeField>( &mut self, num: usize ) -> SmallVec<[Target; 10]>
source§fn squeeze_native_field_elements(
&mut self,
num_elements: usize
) -> SmallVec<[F; 10]>
fn squeeze_native_field_elements( &mut self, num_elements: usize ) -> SmallVec<[F; 10]>
source§fn absorb_bytes(&mut self, elements: &[u8])
fn absorb_bytes(&mut self, elements: &[u8])
source§fn squeeze_short_nonnative_field_element<Target: PrimeField>(
&mut self
) -> Target
fn squeeze_short_nonnative_field_element<Target: PrimeField>( &mut self ) -> Target
source§impl<F: Clone + PrimeField, const RATE: usize, const CAPACITY: usize> Clone for PoseidonSponge<F, RATE, CAPACITY>
impl<F: Clone + PrimeField, const RATE: usize, const CAPACITY: usize> Clone for PoseidonSponge<F, RATE, CAPACITY>
source§fn clone(&self) -> PoseidonSponge<F, RATE, CAPACITY>
fn clone(&self) -> PoseidonSponge<F, RATE, CAPACITY>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more