Commit ca93ca23 authored by Jason A. Donenfeld's avatar Jason A. Donenfeld Committed by Jakub Kicinski

wireguard: selftests: simplify RNG seeding

The seed_rng() function was written to work across lots of old kernels,
back when WireGuard used a big compatibility layer. Now that things have
evolved, we can vastly simplify this, by just marking the RNG as seeded.
Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent ec59f128
...@@ -56,26 +56,14 @@ static void print_banner(void) ...@@ -56,26 +56,14 @@ static void print_banner(void)
static void seed_rng(void) static void seed_rng(void)
{ {
int fd; int bits = 256, fd;
struct {
int entropy_count;
int buffer_size;
unsigned char buffer[256];
} entropy = {
.entropy_count = sizeof(entropy.buffer) * 8,
.buffer_size = sizeof(entropy.buffer),
.buffer = "Adding real entropy is not actually important for these tests. Don't try this at home, kids!"
};
if (mknod("/dev/urandom", S_IFCHR | 0644, makedev(1, 9))) pretty_message("[+] Fake seeding RNG...");
panic("mknod(/dev/urandom)"); fd = open("/dev/random", O_WRONLY);
fd = open("/dev/urandom", O_WRONLY);
if (fd < 0) if (fd < 0)
panic("open(urandom)"); panic("open(random)");
for (int i = 0; i < 256; ++i) { if (ioctl(fd, RNDADDTOENTCNT, &bits) < 0)
if (ioctl(fd, RNDADDENTROPY, &entropy) < 0) panic("ioctl(RNDADDTOENTCNT)");
panic("ioctl(urandom)");
}
close(fd); close(fd);
} }
...@@ -270,10 +258,10 @@ static void check_leaks(void) ...@@ -270,10 +258,10 @@ static void check_leaks(void)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
seed_rng();
ensure_console(); ensure_console();
print_banner(); print_banner();
mount_filesystems(); mount_filesystems();
seed_rng();
kmod_selftests(); kmod_selftests();
enable_logging(); enable_logging();
clear_leaks(); clear_leaks();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment