mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
add a quick health check to the RO trng
takes 8 samples and makes sure those values aren't repeated in the next 8 samples. has a ~1 in 500 million chance of giving a false positive. But generally should catch: stuck-at fault, and also, a highly trained oscillator fault.
This commit is contained in:
parent
c126f7b4f1
commit
9217b9aff5
1 changed files with 15 additions and 0 deletions
|
|
@ -98,6 +98,21 @@ impl ManagedTrng {
|
|||
None
|
||||
};
|
||||
|
||||
// do a quick health check on the TRNG before using it. Looks for repeated values over 8 samples.
|
||||
// this will rule out e.g. TRNG output tied to 0 or 1, or an external feed just feeding it data.
|
||||
// About 1 in 500 million chance of triggering falsely.
|
||||
let mut values = [0u32; 8];
|
||||
for value in values.iter_mut() {
|
||||
*value = ro_trng.get_raw();
|
||||
}
|
||||
for _ in 0..values.len() {
|
||||
if values.contains(&ro_trng.get_raw()) {
|
||||
// don't proceed if we see a stuck value
|
||||
crate::println!("TRNG had stuck value, dying!");
|
||||
bao1x_hal::sigcheck::die_no_std();
|
||||
}
|
||||
}
|
||||
|
||||
// The first seed is always 0.
|
||||
let mut seed = [0u8; 32];
|
||||
// println!("seed: {:x?}", seed); // used to eyeball that things are working correctly
|
||||
|
|
|
|||
Loading…
Reference in a new issue