mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-17 08:40:52 +00:00
add guardband code to driver
This commit is contained in:
parent
6b9955c30e
commit
b24cf4fd8e
1 changed files with 13 additions and 0 deletions
|
|
@ -79,6 +79,13 @@ enum Mode {
|
||||||
}
|
}
|
||||||
|
|
||||||
const RAW_ENTRIES: usize = 16;
|
const RAW_ENTRIES: usize = 16;
|
||||||
|
/// The guardband is a number of entries of the TRNG to dispose of after
|
||||||
|
/// sampling for QC. The idea is to allow the TRNG internal state to evolve
|
||||||
|
/// for at least this many cycles before the next sample is taken, thus
|
||||||
|
/// making it more difficult for any adversary to reason about the current
|
||||||
|
/// state of the TRNG given the QC samples.
|
||||||
|
const RAW_GUARDBAND: usize = 16;
|
||||||
|
|
||||||
pub struct Trng {
|
pub struct Trng {
|
||||||
pub csr: CSR<u32>,
|
pub csr: CSR<u32>,
|
||||||
_count: u16, // vestigial, to be removed?
|
_count: u16, // vestigial, to be removed?
|
||||||
|
|
@ -150,6 +157,12 @@ impl Trng {
|
||||||
*d = Some(self.csr.r(utra::trng::SFR_BUF));
|
*d = Some(self.csr.r(utra::trng::SFR_BUF));
|
||||||
}
|
}
|
||||||
let r = self.csr.r(utra::trng::SFR_BUF);
|
let r = self.csr.r(utra::trng::SFR_BUF);
|
||||||
|
while self.csr.r(utra::trng::SFR_SR) & Status::BUFREADY.bits() == 0 {}
|
||||||
|
// Run the TRNG state forward for some number of cycles to make it harder to draw
|
||||||
|
// any conclusions about the TRNG's state based on the reported raw samples.
|
||||||
|
for _ in 0..RAW_GUARDBAND {
|
||||||
|
let _ = Some(self.csr.r(utra::trng::SFR_SR));
|
||||||
|
}
|
||||||
r
|
r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue