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: DuplexSpongeModeCurrent mode (whether its absorbing or squeezing)
Implementations
sourceimpl<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>(
src_limbs: &[(F, F)],
ty: OptimizationType
) -> Vec<F>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A>where
A: Allocator,
pub fn compress_elements<TargetField: PrimeField>(
src_limbs: &[(F, F)],
ty: OptimizationType
) -> Vec<F>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A>where
A: Allocator,
A: Allocator,
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>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A>where
A: Allocator,
pub fn get_bits(&mut self, num_bits: usize) -> Vec<bool>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A>where
A: Allocator,
A: Allocator,
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
sourceimpl<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>
sourcefn 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.
sourcefn 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.
sourcefn 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
sourcefn new_with_parameters(parameters: &Self::Parameters) -> Self
fn new_with_parameters(parameters: &Self::Parameters) -> Self
sourcefn 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]>
sourcefn 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]>
sourcefn absorb_bytes(&mut self, elements: &[u8])
fn absorb_bytes(&mut self, elements: &[u8])
sourcefn squeeze_short_nonnative_field_element<Target: PrimeField>(
&mut self
) -> Target
fn squeeze_short_nonnative_field_element<Target: PrimeField>(
&mut self
) -> Target
sourceimpl<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>
sourcefn clone(&self) -> PoseidonSponge<F, RATE, CAPACITY>
fn clone(&self) -> PoseidonSponge<F, RATE, CAPACITY>
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more