x86_64: generate a seed for the RNG with RDRAND when available

This commit is contained in:
2026-03-14 22:18:47 +00:00
parent d2203d9a65
commit 72145257de
3 changed files with 67 additions and 0 deletions

View File

@@ -10,12 +10,14 @@
#include <kernel/init.h>
#include <kernel/libc/stdio.h>
#include <kernel/machine/cpu.h>
#include <kernel/machine/random.h>
#include <kernel/memblock.h>
#include <kernel/object.h>
#include <kernel/percpu.h>
#include <kernel/pmap.h>
#include <kernel/printk.h>
#include <kernel/types.h>
#include <kernel/util.h>
#include <kernel/vm.h>
#define PTR32(x) ((void *)((uintptr_t)(x)))
@@ -123,6 +125,18 @@ int ml_init(uintptr_t arg)
reserve_end = bsp.mod_base + bsp.mod_size;
}
if (ml_hwrng_available()) {
printk("cpu: ardware RNG available");
uint64_t seed = ml_hwrng_generate();
printk("cpu: RNG seed=%zx", seed);
init_random(seed);
} else {
printk("cpu: hardware RNG unavailable");
uint64_t seed = 0xeddc4c8a679dc23f;
printk("cpu: RNG seed=%zx", seed);
init_random(seed);
}
early_vm_init(reserve_end);
e820_scan(PTR32(mb->mmap_addr), mb->mmap_length);