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 the following facts:

  1. 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.
  2. As a result of the previous point, we don’t make use of an input buffer to accumulate seed material.

Implementations§

§

impl RpoRandomCoin

pub fn new(seed: [BaseElement; 4]) -> RpoRandomCoin

Returns a new RpoRandomCoin initialize with the specified seed.

pub fn from_parts(state: [BaseElement; 12], current: usize) -> RpoRandomCoin

Returns an RpoRandomCoin instantiated from the provided components.

§Panics

Panics if current is smaller than 4 or greater than or equal to 12.

pub fn into_parts(self) -> ([BaseElement; 12], usize)

Returns components of this random coin.

Trait Implementations§

§

impl Clone for RpoRandomCoin

§

fn clone(&self) -> RpoRandomCoin

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
§

impl Debug for RpoRandomCoin

§

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

Formats the value using the given formatter. Read more
§

impl Deserializable for RpoRandomCoin

§

fn read_from<R>(source: &mut R) -> Result<RpoRandomCoin, DeserializationError>
where R: ByteReader,

Reads a sequence of bytes from the provided source, attempts to deserialize these bytes into Self, and returns the result. Read more
§

fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>

Attempts to deserialize the provided bytes into Self and returns the result. Read more
§

impl FeltRng for RpoRandomCoin

§

fn draw_element(&mut self) -> BaseElement

Draw, uniformly at random, a base field element.
§

fn draw_word(&mut self) -> [BaseElement; 4]

Draw, uniformly at random, a Word.
§

impl PartialEq for RpoRandomCoin

§

fn eq(&self, other: &RpoRandomCoin) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl RandomCoin for RpoRandomCoin

§

type BaseField = BaseElement

Base field for random elements which can be generated by this random coin.
§

type Hasher = Rpo256

Hash function which is used by the random coin to generate random field elements.
§

fn new(seed: &[<RpoRandomCoin as RandomCoin>::BaseField]) -> RpoRandomCoin

Returns a new random coin instantiated with the provided seed.
§

fn reseed(&mut self, data: RpoDigest)

Reseeds the coin with the specified data by setting the new seed to hash(seed || data).
§

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.
§

fn draw<E>(&mut self) -> Result<E, RandomCoinError>
where E: FieldElement<BaseField = BaseElement>,

Returns the next pseudo-random field element. Read more
§

fn draw_integers( &mut self, num_values: usize, domain_size: usize, nonce: u64 ) -> Result<Vec<usize>, RandomCoinError>

Returns a vector of integers selected from the range [0, domain_size) after it reseeds the coin with a nonce. Read more
§

impl Serializable for RpoRandomCoin

§

fn write_into<W>(&self, target: &mut W)
where W: ByteWriter,

Serializes self into bytes and writes these bytes into the target.
§

fn to_bytes(&self) -> Vec<u8>

Serializes self into a vector of bytes.
§

fn get_size_hint(&self) -> usize

Returns an estimate of how many bytes are needed to represent self. Read more
§

impl Copy for RpoRandomCoin

§

impl Eq for RpoRandomCoin

§

impl StructuralPartialEq for RpoRandomCoin

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where 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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where 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.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where 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 T
where 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 T
where 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.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more