Kernel: Seed RNG by real time if no RDRAND available

This commit is contained in:
Bananymous 2024-02-20 13:00:26 +02:00
parent b979023b9d
commit f3f5ca1bd8
1 changed files with 10 additions and 2 deletions

View File

@ -1,6 +1,7 @@
#include <kernel/Debug.h>
#include <kernel/CPUID.h>
#include <kernel/Debug.h>
#include <kernel/Random.h>
#include <kernel/Timer/Timer.h>
namespace Kernel
{
@ -18,9 +19,16 @@ namespace Kernel
CPUID::get_features(ecx, edx);
if (ecx & CPUID::ECX_RDRND)
{
asm volatile("rdrand %0" : "=a"(s_rand_seed));
dprintln("RNG seeded by RDRAND");
}
else
dprintln("No RDRAND available");
{
auto rt = SystemTimer::get().real_time();
s_rand_seed ^= rt.tv_sec ^ rt.tv_nsec;
dprintln("RNG seeded by real time");
}
}
uint32_t Random::get_u32()