use crate::rng::Rng;
use cryptography::{Csprng, CtrDrbgAes256};
const CTR_DRBG_SEED_LEN: usize = 48;
pub struct CryptoCtrDrbg {
inner: CtrDrbgAes256,
}
impl CryptoCtrDrbg {
#[must_use]
pub fn new(seed_material: &[u8; CTR_DRBG_SEED_LEN]) -> Self {
Self {
inner: CtrDrbgAes256::new(seed_material),
}
}
#[must_use]
pub fn with_test_seed() -> Self {
let seed = core::array::from_fn::<u8, CTR_DRBG_SEED_LEN, _>(|i| i as u8);
Self::new(&seed)
}
}
impl Rng for CryptoCtrDrbg {
fn next_u32(&mut self) -> u32 {
let mut out = [0u8; 4];
self.inner.fill_bytes(&mut out);
u32::from_be_bytes(out)
}
}