pub struct Drbg { /* private fields */ }
Implementations§
Source§impl Drbg
impl Drbg
Sourcepub fn new_with_entropy(alg: Algorithm, entropy: &[u8]) -> Result<Self, Error>
pub fn new_with_entropy(alg: Algorithm, entropy: &[u8]) -> Result<Self, Error>
Create a new DRBG state with the given hash function. This also initializes the DRBG state with the given entropy.
Sourcepub fn personalized(
alg: Algorithm,
entropy: &[u8],
nonce: &[u8],
personalization: &str,
) -> Result<Self, Error>
pub fn personalized( alg: Algorithm, entropy: &[u8], nonce: &[u8], personalization: &str, ) -> Result<Self, Error>
Create a new DRBG state with the given hash function. This also initializes the DRBG state with the given entropy, nonce and personalization string.
Sourcepub fn reseed(
&mut self,
entropy: &[u8],
additional_input: &[u8],
) -> Result<(), Error>
pub fn reseed( &mut self, entropy: &[u8], additional_input: &[u8], ) -> Result<(), Error>
Reseed the DRBG state.
Sourcepub fn generate(&mut self, output: &mut [u8]) -> Result<(), Error>
pub fn generate(&mut self, output: &mut [u8]) -> Result<(), Error>
Generate random bytes.
Note that you will need to call reseed()
when reseed_required
is true
and the rand
feature is not enabled. If the rand
feature is enabled,
the Drbg reseeds itself when needed, using OsRng
.
Sourcepub fn generate_with_input(
&mut self,
output: &mut [u8],
additional_input: &[u8],
) -> Result<(), Error>
pub fn generate_with_input( &mut self, output: &mut [u8], additional_input: &[u8], ) -> Result<(), Error>
Generate random bytes with additional input mixed into the state.
Note that you will need to call reseed()
when reseed_required
is true
and the rand
feature is not enabled. If the rand
feature is enabled,
the Drbg reseeds itself when needed, using OsRng
.
Sourcepub fn generate_vec(&mut self, len: usize) -> Result<Vec<u8>, Error>
pub fn generate_vec(&mut self, len: usize) -> Result<Vec<u8>, Error>
Generate random bytes.
Allocates the vector of length len
.
Note that you will need to call reseed()
when reseed_required
is true
and the rand
feature is not enabled. If the rand
feature is enabled,
the Drbg reseeds itself when needed, using OsRng
.
Sourcepub fn generate_array<const LEN: usize>(&mut self) -> Result<[u8; LEN], Error>
pub fn generate_array<const LEN: usize>(&mut self) -> Result<[u8; LEN], Error>
Generate random bytes.
Allocates the array of length LEN
.
Note that you will need to call reseed()
when reseed_required
is true
and the rand
feature is not enabled. If the rand
feature is enabled,
the Drbg reseeds itself when needed, using OsRng
.
Sourcepub fn reseed_required(&self) -> bool
pub fn reseed_required(&self) -> bool
Returns true if a reseed is required and false otherwise.
Trait Implementations§
Source§impl RngCore for Drbg
impl RngCore for Drbg
Source§fn fill_bytes(&mut self, dest: &mut [u8])
fn fill_bytes(&mut self, dest: &mut [u8])
dest
with random data. Read moreimpl CryptoRng for Drbg
Auto Trait Implementations§
impl Freeze for Drbg
impl RefUnwindSafe for Drbg
impl !Send for Drbg
impl !Sync for Drbg
impl Unpin for Drbg
impl UnwindSafe for Drbg
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> CryptoRngCore for T
impl<T> CryptoRngCore for T
Source§impl<R> Rng for R
impl<R> Rng for R
Source§fn gen<T>(&mut self) -> Twhere
Standard: Distribution<T>,
fn gen<T>(&mut self) -> Twhere
Standard: Distribution<T>,
Source§fn gen_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
fn gen_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
Source§fn sample<T, D>(&mut self, distr: D) -> Twhere
D: Distribution<T>,
fn sample<T, D>(&mut self, distr: D) -> Twhere
D: Distribution<T>,
Source§fn sample_iter<T, D>(self, distr: D) -> DistIter<D, Self, T>where
D: Distribution<T>,
Self: Sized,
fn sample_iter<T, D>(self, distr: D) -> DistIter<D, Self, T>where
D: Distribution<T>,
Self: Sized,
Source§fn gen_bool(&mut self, p: f64) -> bool
fn gen_bool(&mut self, p: f64) -> bool
p
of being true. Read moreSource§fn gen_ratio(&mut self, numerator: u32, denominator: u32) -> bool
fn gen_ratio(&mut self, numerator: u32, denominator: u32) -> bool
numerator/denominator
of being
true. I.e. gen_ratio(2, 3)
has chance of 2 in 3, or about 67%, of
returning true. If numerator == denominator
, then the returned value
is guaranteed to be true
. If numerator == 0
, then the returned
value is guaranteed to be false
. Read more