mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-10 10:01:13 +09:00
Kernel: Use HPET as entropy source if CPU doesn't support RDRAND
We don't have anything better for these CPUs for now.
This commit is contained in:
parent
ceb5682b54
commit
0a61924727
Notes:
sideshowbarker
2024-07-18 22:50:11 +09:00
Author: https://github.com/sppmacd
Commit: 0a61924727
Pull-request: https://github.com/SerenityOS/serenity/pull/5046
Issue: https://github.com/SerenityOS/serenity/issues/4490
Reviewed-by: https://github.com/tomuta ✅
1 changed files with 10 additions and 0 deletions
|
@ -29,6 +29,7 @@
|
|||
#include <Kernel/Arch/i386/CPU.h>
|
||||
#include <Kernel/Devices/RandomDevice.h>
|
||||
#include <Kernel/Random.h>
|
||||
#include <Kernel/Time/HPET.h>
|
||||
#include <Kernel/Time/TimeManagement.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
@ -45,6 +46,7 @@ KernelRng::KernelRng()
|
|||
bool supports_rdseed = Processor::current().has_feature(CPUFeature::RDSEED);
|
||||
bool supports_rdrand = Processor::current().has_feature(CPUFeature::RDRAND);
|
||||
if (supports_rdseed || supports_rdrand) {
|
||||
klog() << "KernelRng: Using RDSEED or RDRAND as entropy source";
|
||||
for (size_t i = 0; i < resource().pool_count * resource().reseed_threshold; ++i) {
|
||||
u32 value = 0;
|
||||
if (supports_rdseed) {
|
||||
|
@ -63,6 +65,14 @@ KernelRng::KernelRng()
|
|||
|
||||
this->resource().add_random_event(value, i % 32);
|
||||
}
|
||||
} else {
|
||||
// Add HPET as entropy source if we don't have anything better.
|
||||
klog() << "KernelRng: Using HPET as entropy source (bad!)";
|
||||
|
||||
for (size_t i = 0; i < resource().pool_count * resource().reseed_threshold; ++i) {
|
||||
u64 hpet_time = HPET::the().read_main_counter();
|
||||
this->resource().add_random_event(hpet_time, i % 32);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue