[][src]Struct dusk_poseidon_merkle::Poseidon

pub struct Poseidon<T: PoseidonLeaf> { /* fields omitted */ }

The Poseidon structure will accept a number of inputs equal to the arity.

The leaves must implement ops::Mul against a Scalar, because the MDS matrix and the round constants are set, by default, as scalars.

Methods

impl<T: PoseidonLeaf> Poseidon<T>[src]

pub fn push(&mut self, leaf: T) -> Result<usize, Error>[src]

The poseidon width will be defined by arity + 1, because the first element will be a set of bitflags defining which element is present or absent. The absent elements will be represented by 0, and the present ones by 1, considering inverse order.

For example: given we have an arity of 8, and if we have two present elements, three absent, and three present, we will have the first element as 0xe3, or (11100011).

Every time we push an element, we set the related bitflag with the proper state.

The returned usize represents the leaf position for the insert operation

pub fn remove(&mut self, index: usize) -> Result<T, Error>[src]

Removes an item that is indexed by index.

Internally, the buffer is stored in form of index + 1, because of the leading bitflags element.

Example

use dusk_poseidon_merkle::*;

let mut h = Poseidon::default();

assert!(h.remove(0).is_err());

let idx = h.push(Scalar::one()).unwrap();
assert_eq!(0, idx);

h.remove(0).unwrap();

pub fn remove_item(&mut self, item: &T) -> Option<T>[src]

Removes the first equivalence of the item from the leafs set and returns it.

pub fn remove_unchecked(&mut self, index: usize) -> T[src]

Set the provided index as absent for the hash calculation.

Panics

Panics if index is out of bounds.

pub fn replace(&mut self, buf: &[Option<T>])[src]

Replace the leaves with the provided optional items.

Panics

Panics if the provided slice is bigger than the arity.

pub fn reset(&mut self)[src]

Restore the initial state

pub fn hash(&mut self) -> T where
    Scalar: Mul<T, Output = T>, 
[src]

The absent elements will be considered as zeroes in the permutation.

The number of rounds is divided into two equal parts for the full rounds, plus the partial rounds.

The returned element is the second poseidon leaf, for the first is initially the bitflags scheme.

pub fn full_round(&mut self) where
    Scalar: Mul<T, Output = T>, 
[src]

The full round function will add the round constants and apply the S-Box to all poseidon leaves, including the bitflags first element.

After that, the poseidon elements will be set to the result of the product between the poseidon leaves and the constant MDS matrix.

pub fn partial_round(&mut self) where
    Scalar: Mul<T, Output = T>, 
[src]

The partial round is the same as the full round, with the difference that we apply the S-Box only to the first bitflags poseidon leaf.

Trait Implementations

impl<T: Clone + PoseidonLeaf> Clone for Poseidon<T>[src]

impl<T: Copy + PoseidonLeaf> Copy for Poseidon<T>[src]

impl<T: PoseidonLeaf> Default for Poseidon<T>[src]

impl<T: PartialEq + PoseidonLeaf> PartialEq<Poseidon<T>> for Poseidon<T>[src]

impl<T: Debug + PoseidonLeaf> Debug for Poseidon<T>[src]

Auto Trait Implementations

impl<T> Send for Poseidon<T> where
    T: Send

impl<T> Sync for Poseidon<T> where
    T: Sync

impl<T> Unpin for Poseidon<T> where
    T: Unpin

impl<T> UnwindSafe for Poseidon<T> where
    T: UnwindSafe

impl<T> RefUnwindSafe for Poseidon<T> where
    T: RefUnwindSafe

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Clear for T where
    T: InitializableFromZeroed + ?Sized
[src]

impl<T> InitializableFromZeroed for T where
    T: Default
[src]

impl<T> Same<T> for T[src]

type Output = T

Should always be Self