random-util: remove RDRAND usage

/dev/urandom is seeded with RDRAND. Calling genuine_random_bytes(...,
..., 0) will use /dev/urandom as a last resort. Hence, we gain nothing
here by having our own RDRAND wrapper, because /dev/urandom already is
based on RDRAND output, even before /dev/urandom has fully initialized.

Furthermore, RDRAND is not actually fast! And on each successive
generation of new x86 CPUs, from both AMD and Intel, it just gets
slower.

This commit simplifies things by just using /dev/urandom in cases where
we before might use RDRAND, since /dev/urandom will always have RDRAND
mixed in as part of it.

And above where I say "/dev/urandom", what I actually mean is
GRND_INSECURE, which is the same thing but won't generate warnings in
dmesg.
This commit is contained in:
Jason A. Donenfeld
2022-03-14 19:47:13 +00:00
committed by Luca Boccassi
parent e28770e367
commit ffa047a03e
9 changed files with 29 additions and 227 deletions
-17
View File
@@ -26,7 +26,6 @@ static void test_genuine_random_bytes_one(RandomFlags flags) {
TEST(genuine_random_bytes) {
test_genuine_random_bytes_one(0);
test_genuine_random_bytes_one(RANDOM_BLOCK);
test_genuine_random_bytes_one(RANDOM_ALLOW_RDRAND);
}
TEST(pseudo_random_bytes) {
@@ -41,22 +40,6 @@ TEST(pseudo_random_bytes) {
}
}
TEST(rdrand) {
int r;
for (unsigned i = 0; i < 10; i++) {
unsigned long x = 0;
r = rdrand(&x);
if (r < 0) {
log_error_errno(r, "RDRAND failed: %m");
return;
}
printf("%lx\n", x);
}
}
#define TOTAL 100000
static void test_random_u64_range_one(unsigned mod) {