From 6618d8dc4db6d488f8e55f43d2f0a3f3ee597151 Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 22 Jun 2024 21:18:48 +0800 Subject: [PATCH] improve docs on what's happening in the TRNG buffer --- libs/cramium-hal/src/sce/trng.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libs/cramium-hal/src/sce/trng.rs b/libs/cramium-hal/src/sce/trng.rs index 7ed68faf7..5d16e1a5a 100644 --- a/libs/cramium-hal/src/sce/trng.rs +++ b/libs/cramium-hal/src/sce/trng.rs @@ -90,6 +90,8 @@ pub struct Trng { pub csr: CSR, _count: u16, // vestigial, to be removed? mode: Mode, + /// Buffer some raw entropy inside the kernel, so we can "burst out" entropy + /// for reseed operations without having to wait for the TRNG to regenerate data. raw: [Option; RAW_ENTRIES], #[cfg(feature = "compress-entropy")] rng_var: u8, @@ -136,13 +138,16 @@ impl Trng { } pub fn get_raw(&mut self) -> u32 { + // Pull from the buffered entropy pool, until it's empty. for d in self.raw.iter_mut() { if let Some(r) = d.take() { return r; } } + // If empty, refill the buffer. while self.csr.r(utra::trng::SFR_SR) & Status::BUFREADY.bits() == 0 {} + #[cfg(feature = "compress-entropy")] let mut sample = self.csr.r(utra::trng::SFR_BUF); #[cfg(feature = "compress-entropy")]