x86_64: generate a seed for the RNG with RDRAND when available
This commit is contained in:
43
arch/x86_64/random.S
Normal file
43
arch/x86_64/random.S
Normal 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
|
||||
Reference in New Issue
Block a user