From 414125fc151c1b01b6840ba71f178686e402bbec Mon Sep 17 00:00:00 2001 From: Stefan Butz Date: Sat, 4 Jul 2026 20:21:39 +0200 Subject: [PATCH] Seed entropy using arm rng Tested successfully on qemu with `-cpu neoverse-v1`. --- src/arch/aarch64/kernel/processor.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/arch/aarch64/kernel/processor.rs b/src/arch/aarch64/kernel/processor.rs index 3a62f128a7..6eb7a43899 100644 --- a/src/arch/aarch64/kernel/processor.rs +++ b/src/arch/aarch64/kernel/processor.rs @@ -1,6 +1,7 @@ use core::arch::asm; use core::{fmt, mem}; +use aarch64_cpu::asm::random::ArmRng; use aarch64_cpu::registers::*; use hermit_sync::{Lazy, OnceCell, without_interrupts}; @@ -196,8 +197,16 @@ impl fmt::Display for CpuFrequency { } } +static RNG: Lazy> = Lazy::new(ArmRng::new); + pub fn seed_entropy() -> Option<[u8; 32]> { - None + let rng = RNG.as_ref()?; + let mut buf = [0u8; 32]; + for word in buf.chunks_mut(8) { + let value = rng.rndr().or(None).unwrap().to_ne_bytes(); + word.copy_from_slice(&value); + } + Some(buf) } /// The halt function stops the processor until the next interrupt arrives