Struct miden_core::crypto::random::RpoRandomCoin
source · pub struct RpoRandomCoin { /* private fields */ }Expand description
A simplified version of the SPONGE_PRG reseedable pseudo-random number generator algorithm
described in https://eprint.iacr.org/2011/499.pdf. The simplification is related to
to the following facts:
- A call to the reseed method implies one and only one call to the permutation function. This is possible because in our case we never reseed with more than 4 field elements.
- As a result of the previous point, we dont make use of an input buffer to accumulate seed
material.
It is important to note that the current implementation of
RPORandomCoinassumes thatdraw_integers()is called immediately afterreseed_with_int().
Trait Implementations§
source§impl RandomCoin for RpoRandomCoin
impl RandomCoin for RpoRandomCoin
§type BaseField = BaseElement
type BaseField = BaseElement
Base field for random elements which can be generated by this random coin.
§type Hasher = Rpo256
type Hasher = Rpo256
Hash function which is used by the random coin to generate random field elements.
source§fn new(seed: &[Self::BaseField]) -> Self
fn new(seed: &[Self::BaseField]) -> Self
Returns a new random coin instantiated with the provided
seed.source§fn reseed(&mut self, data: RpoDigest)
fn reseed(&mut self, data: RpoDigest)
Reseeds the coin with the specified data by setting the new seed to hash(
seed || data).source§fn reseed_with_int(&mut self, value: u64)
fn reseed_with_int(&mut self, value: u64)
Reseeds the coin with the specified value by setting the new seed to hash(
seed ||
value).source§fn leading_zeros(&self) -> u32
fn leading_zeros(&self) -> u32
Returns the number of leading zeros in the seed if it is interpreted as an integer in
big-endian byte order.
source§fn check_leading_zeros(&self, value: u64) -> u32
fn check_leading_zeros(&self, value: u64) -> u32
Computes hash(
seed || value) and returns the number of leading zeros in the resulting
value if it is interpreted as an integer in big-endian byte order.source§fn draw<E: FieldElement<BaseField = Felt>>(
&mut self
) -> Result<E, RandomCoinError>
fn draw<E: FieldElement<BaseField = Felt>>( &mut self ) -> Result<E, RandomCoinError>
Returns the next pseudo-random field element. Read more
source§fn draw_integers(
&mut self,
num_values: usize,
domain_size: usize
) -> Result<Vec<usize>, RandomCoinError>
fn draw_integers( &mut self, num_values: usize, domain_size: usize ) -> Result<Vec<usize>, RandomCoinError>
Returns a vector of unique integers selected from the range [0, domain_size). Read more
Auto Trait Implementations§
impl RefUnwindSafe for RpoRandomCoin
impl Send for RpoRandomCoin
impl Sync for RpoRandomCoin
impl Unpin for RpoRandomCoin
impl UnwindSafe for RpoRandomCoin
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
Mutably borrows from an owned value. Read more