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

43
arch/x86_64/random.S Normal file
View File

@@ -0,0 +1,43 @@
.code64
.global ml_hwrng_available
.type ml_hwrng_available, @function
ml_hwrng_available:
push %rbp
mov %rsp, %rbp
push %rbx
push %rdx
mov $1, %eax
mov $0, %ecx
cpuid
shr $30, %ecx
and $1, %ecx
mov %ecx, %eax
pop %rdx
pop %rbx
pop %rbp
ret
.global ml_hwrng_generate
.type ml_hwrng_generate, @function
ml_hwrng_generate:
push %rbp
mov %rsp, %rbp
mov $100, %rcx
.retry:
rdrand %rax
jc .done
loop .retry
.fail:
mov $0, %rax
.done:
pop %rbp
ret