diff options
author | konrad <konrad@serenityos.org> | 2023-01-08 05:23:54 +0100 |
---|---|---|
committer | Jelle Raaijmakers <jelle@gmta.nl> | 2023-01-25 23:17:36 +0100 |
commit | d7d233ab04ef3baf449bea130fd0f27db0a2cd47 (patch) | |
tree | 58b202f59c4ca801b33408c42d175502d7aa0449 /Kernel/Random.cpp | |
parent | cb4cbe3ae8d8515cbf13110d98e03440e902418e (diff) | |
download | serenity-d7d233ab04ef3baf449bea130fd0f27db0a2cd47.zip |
Kernel: Use existing assembly snippets for x86-64 RDSEED & RDRAND calls
Diffstat (limited to 'Kernel/Random.cpp')
-rw-r--r-- | Kernel/Random.cpp | 28 |
1 files changed, 9 insertions, 19 deletions
diff --git a/Kernel/Random.cpp b/Kernel/Random.cpp index e49678a0f3..f98162565e 100644 --- a/Kernel/Random.cpp +++ b/Kernel/Random.cpp @@ -29,27 +29,17 @@ KernelRng& KernelRng::the() UNMAP_AFTER_INIT KernelRng::KernelRng() { #if ARCH(X86_64) - bool supports_rdseed = Processor::current().has_feature(CPUFeature::RDSEED); - bool supports_rdrand = Processor::current().has_feature(CPUFeature::RDRAND); - if (supports_rdseed || supports_rdrand) { - dmesgln("KernelRng: Using RDSEED or RDRAND as entropy source"); + if (Processor::current().has_feature(CPUFeature::RDSEED)) { + dmesgln("KernelRng: Using RDSEED as entropy source"); + for (size_t i = 0; i < pool_count * reseed_threshold; ++i) { - u32 value = 0; - if (supports_rdseed) { - asm volatile( - "1:\n" - "rdseed %0\n" - "jnc 1b\n" - : "=r"(value)); - } else { - asm volatile( - "1:\n" - "rdrand %0\n" - "jnc 1b\n" - : "=r"(value)); - } + add_random_event(Kernel::rdseed(), i % 32); + } + } else if (Processor::current().has_feature(CPUFeature::RDRAND)) { + dmesgln("KernelRng: Using RDRAND as entropy source"); - add_random_event(value, i % 32); + for (size_t i = 0; i < pool_count * reseed_threshold; ++i) { + add_random_event(Kernel::rdrand(), i % 32); } } else if (TimeManagement::the().can_query_precise_time()) { // Add HPET as entropy source if we don't have anything better. |