summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorTimon Kruiper <timonkruiper@gmail.com>2023-01-30 11:47:49 +0100
committerLinus Groh <mail@linusgroh.de>2023-02-08 18:19:48 +0000
commit5aba83e6ba05b3e94e85d7f68cd662546e1ad563 (patch)
treed277aa12171444c17dd4fd92f41194333a198846 /Kernel
parent5781d58fe892f93667ccfb7d52115a64fb4b1309 (diff)
downloadserenity-5aba83e6ba05b3e94e85d7f68cd662546e1ad563.zip
Kernel/aarch64: Add TimeManagement fallback entropy source to Random.cpp
The emulated aarch64 CPU does not contain the RNG cpu feature, so the random number generator was not seeded. This commit adds a fallback to use TimeManagement as a entropy source, such that get_good_random_bytes works, which is needed for running the first userspace application on aarch64.
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/Random.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/Kernel/Random.cpp b/Kernel/Random.cpp
index 96f176540f..8745494a6c 100644
--- a/Kernel/Random.cpp
+++ b/Kernel/Random.cpp
@@ -68,7 +68,14 @@ UNMAP_AFTER_INIT KernelRng::KernelRng()
add_random_event(Aarch64::Asm::read_rndrrs(), i % 32);
}
} else {
- dmesgln("KernelRng: No entropy source available!");
+ // Fallback to TimeManagement as entropy
+ dmesgln("KernelRng: Using bad entropy source TimeManagement");
+ auto current_time = static_cast<u64>(TimeManagement::the().now().to_milliseconds());
+ for (size_t i = 0; i < pool_count * reseed_threshold; ++i) {
+ add_random_event(current_time, i % 32);
+ current_time *= 0x574au;
+ current_time += 0x40b2u;
+ }
}
#else
dmesgln("KernelRng: No entropy source available!");