adjust trng source provider based on hardware target

This commit is contained in:
bunnie 2024-05-29 13:47:49 +08:00
parent 4d28e940d0
commit ae4ed7ba3d
3 changed files with 12 additions and 4 deletions

View file

@ -19,7 +19,8 @@ rkyv = { version = "0.4.3", features = [
"const_generics",
], default-features = false }
gam = { path = "../gam" }
trng = { path = "../trng" }
trng = { path = "../trng", optional = true }
cram-hal-service = { path = "../cram-hal-service", optional = true } # provides trng for cramium-soc
tts-frontend = { path = "../tts" }
locales = { path = "../../locales" }
bit_field = "0.9.0"
@ -27,9 +28,10 @@ bit_field = "0.9.0"
utralib = { version = "0.1.24", optional = true, default-features = false }
[features]
precursor = ["utralib/precursor"]
hosted = ["utralib/hosted"]
renode = ["utralib/renode"]
precursor = ["utralib/precursor", "trng"]
hosted = ["utralib/hosted", "trng"]
renode = ["utralib/renode", "trng"]
cramium-soc = ["utralib/cramium-soc", "cram-hal-service"]
tts = []
ditherpunk = []
hazardous-debug = []

View file

@ -180,6 +180,9 @@ impl Modals {
REFCOUNT.fetch_add(1, Ordering::Relaxed);
let conn =
xns.request_connection_blocking(api::SERVER_NAME_MODALS).expect("Can't connect to Modals server");
#[cfg(feature = "cramium-soc")]
let trng = cram_hal_service::trng::Trng::new(&xns).unwrap();
#[cfg(not(feature = "cramium-soc"))]
let trng = trng::Trng::new(&xns).unwrap();
let mut token = [0u32; 4];
trng.fill_buf(&mut token).unwrap();

View file

@ -138,6 +138,9 @@ fn wrapped_main() -> ! {
let mut list_selected = 0u32;
let mut token_lock: Option<[u32; 4]> = None;
#[cfg(feature = "cramium-soc")]
let trng = cram_hal_service::trng::Trng::new(&xns).unwrap();
#[cfg(not(feature = "cramium-soc"))]
let trng = trng::Trng::new(&xns).unwrap();
// this is a random number that serves as a "default" that cannot be guessed
let default_nonce =