mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
allow gen2 to use the seeded trng fill
This commit is contained in:
parent
0942858bbc
commit
69b77f3072
1 changed files with 9 additions and 0 deletions
|
|
@ -7,6 +7,7 @@ use aes_gcm_siv::Nonce;
|
|||
use bao1x_emu::trng::Trng;
|
||||
#[cfg(all(feature = "bao1x-hal", not(feature = "hosted-baosec")))]
|
||||
use bao1x_hal_service::trng::Trng;
|
||||
#[cfg(not(feature = "gen2"))]
|
||||
use rand_core::RngCore;
|
||||
#[cfg(all(not(feature = "bao1x-hal"), not(feature = "hosted-baosec")))]
|
||||
use trng::Trng;
|
||||
|
|
@ -23,14 +24,22 @@ impl TrngPool {
|
|||
let xns = xous_names::XousNames::new().unwrap();
|
||||
let mut trng = Trng::new(&xns).unwrap();
|
||||
let mut cache: [u8; 8192] = [0; 8192];
|
||||
#[cfg(not(feature = "gen2"))]
|
||||
trng.fill_bytes(&mut cache);
|
||||
// speed up gen2 ops with seeded fill
|
||||
#[cfg(feature = "gen2")]
|
||||
trng.fill_seeded_bytes(&mut cache);
|
||||
TrngPool { trng: RefCell::new(trng), e_cache: RefCell::new(cache.to_vec()) }
|
||||
}
|
||||
|
||||
pub(crate) fn ensure_entropy(&self, amount: usize) {
|
||||
if self.e_cache.borrow().len() < amount {
|
||||
let mut cache: [u8; 8192] = [0; 8192];
|
||||
#[cfg(not(feature = "gen2"))]
|
||||
self.trng.borrow_mut().fill_bytes(&mut cache);
|
||||
// speed up gen2 ops with seeded fill
|
||||
#[cfg(feature = "gen2")]
|
||||
self.trng.borrow_mut().fill_seeded_bytes(&mut cache);
|
||||
self.e_cache.borrow_mut().extend_from_slice(&cache);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue