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.
This commit is contained in:
Timon Kruiper 2023-01-30 11:47:49 +01:00 committed by Linus Groh
parent 5781d58fe8
commit 5aba83e6ba

View file

@ -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!");