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>

source

pub fn compress_elements<TargetField: PrimeField>( src_limbs: &[(F, F)], ty: OptimizationType ) -> Vec<F>

Compress every two elements if possible. Provides a vector of (limb, num_of_additions), both of which are F.

source

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

source

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

source

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.

source

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.

source

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>

source§

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> )

Takes in field elements.

source§

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>, Global>

Parameters used by the sponge.
source§

fn sample_parameters() -> Self::Parameters

source§

fn new_with_parameters(parameters: &Self::Parameters) -> Self

Initialize a new instance of the sponge.
source§

fn squeeze_nonnative_field_elements<Target: PrimeField>( &mut self, num: usize ) -> SmallVec<[Target; 10]>

Takes out field elements.
source§

fn squeeze_native_field_elements( &mut self, num_elements: usize ) -> SmallVec<[F; 10]>

Takes in field elements.
source§

fn new() -> Self

Initialize a new instance of the sponge.
source§

fn absorb_bytes(&mut self, elements: &[u8])

Takes in bytes.
source§

fn squeeze_short_nonnative_field_element<Target: PrimeField>( &mut self ) -> Target

Takes out a field element of 168 bits.
source§

impl<F: Clone + PrimeField, const RATE: usize, const CAPACITY: usize> Clone for PoseidonSponge<F, RATE, CAPACITY>

source§

fn clone(&self) -> PoseidonSponge<F, RATE, CAPACITY>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<F: Debug + PrimeField, const RATE: usize, const CAPACITY: usize> Debug for PoseidonSponge<F, RATE, CAPACITY>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<F, const RATE: usize, const CAPACITY: usize> RefUnwindSafe for PoseidonSponge<F, RATE, CAPACITY>where F: RefUnwindSafe,

§

impl<F, const RATE: usize, const CAPACITY: usize> Send for PoseidonSponge<F, RATE, CAPACITY>

§

impl<F, const RATE: usize, const CAPACITY: usize> Sync for PoseidonSponge<F, RATE, CAPACITY>

§

impl<F, const RATE: usize, const CAPACITY: usize> Unpin for PoseidonSponge<F, RATE, CAPACITY>where F: Unpin,

§

impl<F, const RATE: usize, const CAPACITY: usize> UnwindSafe for PoseidonSponge<F, RATE, CAPACITY>where F: UnwindSafe + RefUnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V