Struct CtrDrbg

Source
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>

Source

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<R: RngCore + CryptoRng, D: DerefMut<Target = R>> Drop for CtrDrbg<'_, R, D>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<RNG: RngCore + CryptoRng, D: DerefMut<Target = RNG>> RngCore for CtrDrbg<'_, RNG, D>

Source§

fn next_u32(&mut self) -> u32

Return the next random u32. Read more
Source§

fn next_u64(&mut self) -> u64

Return the next random u64. Read more
Source§

fn fill_bytes(&mut self, dest: &mut [u8])

Fill dest with random data. Read more
Source§

fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error>

Fill dest entirely with random data. Read more
Source§

impl<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> 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> CryptoRngCore for T
where T: CryptoRng + RngCore,

Source§

fn as_rngcore(&mut self) -> &mut dyn RngCore

Upcast to an RngCore trait object.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.