pub struct Tip5 {
pub state: [BFieldElement; 16],
}
Fields§
§state: [BFieldElement; 16]
Implementations§
Source§impl Tip5
impl Tip5
pub const fn new(domain: Domain) -> Tip5
pub fn permutation(&mut self)
Sourcepub fn trace(&mut self) -> [[BFieldElement; 16]; 6]
pub fn trace(&mut self) -> [[BFieldElement; 16]; 6]
Functionally equivalent to permutation
. Returns the trace of
applying the permutation; that is, the initial state of the sponge as well as its state
after each round.
Sourcepub fn hash_10(input: &[BFieldElement; 10]) -> [BFieldElement; 5]
pub fn hash_10(input: &[BFieldElement; 10]) -> [BFieldElement; 5]
Hash 10 BFieldElement
s.
There is no input-padding because the input length is fixed.
When you want to hash together two Digest
s, use Self::hash_pair
instead. In some rare cases you do want to hash a fixed-length string
of individual BFieldElement
s, which is why this function is exposed.
See also: Self::hash_pair
, Self::hash
, Self::hash_varlen
.
Sourcepub fn hash_pair(left: Digest, right: Digest) -> Digest
pub fn hash_pair(left: Digest, right: Digest) -> Digest
Hash two Digest
s together.
This function is syntax sugar for calling Self::hash_10
on the
concatenation of the digests’ values.
See also: Self::hash_10
, Self::hash
, Self::hash_varlen
.
Sourcepub fn hash<T>(value: &T) -> Digestwhere
T: BFieldCodec,
pub fn hash<T>(value: &T) -> Digestwhere
T: BFieldCodec,
Hash an object based on its BFieldCodec
-encoding.
Thin wrapper around hash_varlen
.
See also: Self::hash_10
, Self::hash_pair
, Self::hash_varlen
.
Sourcepub fn hash_varlen(input: &[BFieldElement]) -> Digest
pub fn hash_varlen(input: &[BFieldElement]) -> Digest
Hash a variable-length sequence of BFieldElement
.
This function pads the input as its length is variable.
Note that Self::hash_varlen
and Self::hash_10
are different
functions, even when the input to the former, after padding, agrees with
the input to the latter. The difference comes from the initial value of
the capacity-part of the state, which in the case of variable-length
hashing is all-ones but in the case of fixed-length hashing is
all-zeroes.
Prefer Self::hash
whenever an object is being hashed whose type
implements BFieldCodec
. However, such an object is not always
available, which is why this function is exposed.
See also: Self::hash_10
, Self::hash_pair
, Self::hash
.
Sourcepub fn sample_indices(
&mut self,
upper_bound: u32,
num_indices: usize,
) -> Vec<u32>
pub fn sample_indices( &mut self, upper_bound: u32, num_indices: usize, ) -> Vec<u32>
Produce num_indices
random integer values in the range [0, upper_bound)
. The
upper_bound
must be a power of 2.
This method uses von Neumann rejection sampling. Specifically, if the top 32 bits of a BFieldElement are all ones, then the bottom 32 bits are not uniformly distributed, and so they are dropped. This method invokes squeeze until enough uniform u32s have been sampled.
Sourcepub fn sample_scalars(&mut self, num_elements: usize) -> Vec<XFieldElement>
pub fn sample_scalars(&mut self, num_elements: usize) -> Vec<XFieldElement>
Produce num_elements
random XFieldElement
values.
If num_elements
is not divisible by RATE
, spill the remaining elements of the
last squeeze
.
Trait Implementations§
Source§impl<'arbitrary> Arbitrary<'arbitrary> for Tip5
impl<'arbitrary> Arbitrary<'arbitrary> for Tip5
Source§fn arbitrary(u: &mut Unstructured<'arbitrary>) -> Result<Tip5, Error>
fn arbitrary(u: &mut Unstructured<'arbitrary>) -> Result<Tip5, Error>
Self
from the given unstructured data. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'arbitrary>) -> Result<Tip5, Error>
fn arbitrary_take_rest(u: Unstructured<'arbitrary>) -> Result<Tip5, Error>
Self
from the entirety of the given
unstructured data. Read moreSource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Unstructured
this type
needs to construct itself. Read moreSource§fn try_size_hint(
depth: usize,
) -> Result<(usize, Option<usize>), MaxRecursionReached>
fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>
Unstructured
this type
needs to construct itself. Read moreSource§impl BFieldCodec for Tip5
impl BFieldCodec for Tip5
type Error = Tip5BFieldDecodingError
fn decode( sequence: &[BFieldElement], ) -> Result<Box<Tip5>, <Tip5 as BFieldCodec>::Error>
fn encode(&self) -> Vec<BFieldElement>
Source§fn static_length() -> Option<usize>
fn static_length() -> Option<usize>
Source§impl<'de> Deserialize<'de> for Tip5
impl<'de> Deserialize<'de> for Tip5
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Tip5, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Tip5, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl GetSize for Tip5
impl GetSize for Tip5
Source§fn get_heap_size(&self) -> usize
fn get_heap_size(&self) -> usize
Source§fn get_heap_size_with_tracker<TRACKER>(
&self,
tracker: TRACKER,
) -> (usize, TRACKER)where
TRACKER: GetSizeTracker,
fn get_heap_size_with_tracker<TRACKER>(
&self,
tracker: TRACKER,
) -> (usize, TRACKER)where
TRACKER: GetSizeTracker,
tracker
. Read moreSource§fn get_stack_size() -> usize
fn get_stack_size() -> usize
Source§fn get_size_with_tracker<T>(&self, tracker: T) -> (usize, T)where
T: GetSizeTracker,
fn get_size_with_tracker<T>(&self, tracker: T) -> (usize, T)where
T: GetSizeTracker,
tracker
. Read moreSource§impl Hasher for Tip5
impl Hasher for Tip5
1.26.0 · Source§fn write_u128(&mut self, i: u128)
fn write_u128(&mut self, i: u128)
u128
into this hasher.1.3.0 · Source§fn write_usize(&mut self, i: usize)
fn write_usize(&mut self, i: usize)
usize
into this hasher.1.26.0 · Source§fn write_i128(&mut self, i: i128)
fn write_i128(&mut self, i: i128)
i128
into this hasher.1.3.0 · Source§fn write_isize(&mut self, i: isize)
fn write_isize(&mut self, i: isize)
isize
into this hasher.Source§fn write_length_prefix(&mut self, len: usize)
fn write_length_prefix(&mut self, len: usize)
hasher_prefixfree_extras
)Source§impl Serialize for Tip5
impl Serialize for Tip5
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Eq for Tip5
impl StructuralPartialEq for Tip5
Auto Trait Implementations§
impl Freeze for Tip5
impl RefUnwindSafe for Tip5
impl Send for Tip5
impl Sync for Tip5
impl Unpin for Tip5
impl UnwindSafe for Tip5
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more