fix hosted mode

This commit is contained in:
bunnie 2025-11-18 23:59:17 +08:00
parent a208d59690
commit 90362b2604
3 changed files with 21 additions and 4 deletions

View file

@ -1,4 +1,5 @@
use String; use String;
#[cfg(not(feature = "hosted-baosec"))]
use rand_core::RngCore; use rand_core::RngCore;
use crate::{CommonEnv, ShellCmdApi}; use crate::{CommonEnv, ShellCmdApi};
@ -38,6 +39,7 @@ impl<'a> ShellCmdApi<'a> for TrngCmd {
"u64" => { "u64" => {
log::info!("A u64 trng value: {:x}", env.trng.get_u64().unwrap()); log::info!("A u64 trng value: {:x}", env.trng.get_u64().unwrap());
} }
#[cfg(not(feature = "hosted-baosec"))]
"buf" => { "buf" => {
let mut test1 = [0u8; 8192]; let mut test1 = [0u8; 8192];
let mut trng = bao1x_hal_service::trng::Trng::new(&env.xns).unwrap(); let mut trng = bao1x_hal_service::trng::Trng::new(&env.xns).unwrap();

View file

@ -10,6 +10,7 @@ xous-names = { package = "xous-api-names", version = "0.9.68" }
"ux-api" = { path = "../../libs/ux-api" } "ux-api" = { path = "../../libs/ux-api" }
"rand" = "0.8" "rand" = "0.8"
rand_core = "0.6.4" rand_core = "0.6.4"
rand_chacha = "0.3.1"
log = "0.4.14" log = "0.4.14"
log-server = { package = "xous-api-log", version = "0.1.66" } log-server = { package = "xous-api-log", version = "0.1.66" }
num-derive = { version = "0.4.2", default-features = false } num-derive = { version = "0.4.2", default-features = false }
@ -18,10 +19,7 @@ rkyv = { version = "0.8.8", default-features = false, features = [
"std", "std",
"alloc", "alloc",
] } ] }
bao1x-api = { path = "../../libs/bao1x-api", features = [ bao1x-api = { path = "../../libs/bao1x-api", features = ["derive-rkyv", "std"] }
"derive-rkyv",
"std",
] }
[target.'cfg(any(windows,unix))'.dependencies] [target.'cfg(any(windows,unix))'.dependencies]
minifb = "0.26.0" minifb = "0.26.0"

View file

@ -34,6 +34,23 @@ impl Trng {
left.copy_from_slice(&chunk[..n]); left.copy_from_slice(&chunk[..n]);
} }
} }
pub fn fill_seeded_bytes(&mut self, dest: &mut [u8]) {
use rand_chacha::ChaCha8Rng;
use rand_chacha::rand_core::RngCore;
use rand_chacha::rand_core::SeedableRng;
// for very short runs, fill directly from the HW TRNG
if dest.len() < 64 {
self.fill_bytes_via_next(dest);
return;
}
// larger runs, seed a ChaCha8 and use its results to fill the buffer
let mut seed = [0u8; 32];
self.fill_bytes_via_next(&mut seed);
let mut cstrng = ChaCha8Rng::from_seed(seed);
cstrng.fill_bytes(dest);
}
} }
impl RngCore for Trng { impl RngCore for Trng {