pub trait RandomMod: Sized + Zero {
    // Required method
    fn random_mod(rng: &mut impl CryptoRngCore, modulus: &NonZero<Self>) -> Self;
}
Expand description

Modular random number generation support.

Required Methods§

source

fn random_mod(rng: &mut impl CryptoRngCore, modulus: &NonZero<Self>) -> Self

Generate a cryptographically secure random number which is less than a given modulus.

This function uses rejection sampling, a method which produces an unbiased distribution of in-range values provided the underlying CSRNG is unbiased, but runs in variable-time.

The variable-time nature of the algorithm should not pose a security issue so long as the underlying random number generator is truly a CSRNG, where previous outputs are unrelated to subsequent outputs and do not reveal information about the RNG’s internal state.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl RandomMod for BoxedUint

Available on crate features rand_core and alloc only.
source§

impl RandomMod for Limb

Available on crate feature rand_core only.
source§

impl<const LIMBS: usize> RandomMod for Uint<LIMBS>

Available on crate feature rand_core only.