pub struct CtrDrbg<'a, RNG: RngCore + CryptoRng, D: DerefMut<Target = RNG>> { /* private fields */ }
Expand description
CTR_DRBG pseudorandom generator
Cryptographically secure pseudorandom number generator (CSPRNG). The Mbed TLS implementation of CTR_DRBG which uses AES-256 (default) or AES-128.
Use this if:
- your RNG source isn’t suitable for generating sufficient amounts of cryptographically secure random numbers (e.g. your RNG isn’t fast enough)
- if you do not have a true hardware RNG and want to use it as an RNG initialized with a
user-supplied (fixed) seed (use the
personalization_string
then); it should be obvious that a non-random seed does not yield true random numbers and that reusing the same seed undermines security - if you want to augment your RNG with another source of entropy (again, use the
personalization_string
)
This type is a wrapper around the mbedtls_ctr_drbg_context
Implementations§
Source§impl<'a, RNG: RngCore + CryptoRng> CtrDrbg<'a, RNG, &'a mut RNG>
impl<'a, RNG: RngCore + CryptoRng> CtrDrbg<'a, RNG, &'a mut RNG>
Sourcepub fn new(
entropy_source: &'a mut RNG,
personalization_string: Option<&'a [u8]>,
) -> Result<Self, Error>
pub fn new( entropy_source: &'a mut RNG, personalization_string: Option<&'a [u8]>, ) -> Result<Self, Error>
Initialize and seed a CtrDrbg context
Might fail when no entropy can be collected.
When the alloc
feature is activated, the new_with_heap_rng
constructor can be used to
pass an owned entropy source which will be moved to the heap.
This enables you to freely move the CtrDrbg
together with the context.
§Example
use embedded_mbedtls::rng::CtrDrbg;
use rand_core::RngCore;
let mut entropy_src = rng;
let mut ctr_drbg = CtrDrbg::new(&mut entropy_src, None).unwrap();
let _random = ctr_drbg.next_u32();
Trait Implementations§
Source§impl<RNG: RngCore + CryptoRng, D: DerefMut<Target = RNG>> RngCore for CtrDrbg<'_, RNG, D>
impl<RNG: RngCore + CryptoRng, D: DerefMut<Target = RNG>> RngCore for CtrDrbg<'_, RNG, D>
Source§fn fill_bytes(&mut self, dest: &mut [u8])
fn fill_bytes(&mut self, dest: &mut [u8])
Fill
dest
with random data. Read moreimpl<RNG: RngCore + CryptoRng, D: DerefMut<Target = RNG>> CryptoRng for CtrDrbg<'_, RNG, D>
Auto Trait Implementations§
impl<'a, RNG, D> Freeze for CtrDrbg<'a, RNG, D>where
D: Freeze,
impl<'a, RNG, D> RefUnwindSafe for CtrDrbg<'a, RNG, D>where
D: RefUnwindSafe,
impl<'a, RNG, D> !Send for CtrDrbg<'a, RNG, D>
impl<'a, RNG, D> !Sync for CtrDrbg<'a, RNG, D>
impl<'a, RNG, D> Unpin for CtrDrbg<'a, RNG, D>where
D: Unpin,
impl<'a, RNG, D> UnwindSafe for CtrDrbg<'a, RNG, D>where
D: UnwindSafe,
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
Source§impl<T> CryptoRngCore for T
impl<T> CryptoRngCore for T
Source§fn as_rngcore(&mut self) -> &mut dyn RngCore
fn as_rngcore(&mut self) -> &mut dyn RngCore
Upcast to an
RngCore
trait object.