Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Jason A. Donenfeld and committed by
Jakub Kicinski
ca93ca23 ec59f128

+7 -19
+7 -19
tools/testing/selftests/wireguard/qemu/init.c
··· 56 56 57 57 static void seed_rng(void) 58 58 { 59 - int fd; 60 - struct { 61 - int entropy_count; 62 - int buffer_size; 63 - unsigned char buffer[256]; 64 - } entropy = { 65 - .entropy_count = sizeof(entropy.buffer) * 8, 66 - .buffer_size = sizeof(entropy.buffer), 67 - .buffer = "Adding real entropy is not actually important for these tests. Don't try this at home, kids!" 68 - }; 59 + int bits = 256, fd; 69 60 70 - if (mknod("/dev/urandom", S_IFCHR | 0644, makedev(1, 9))) 71 - panic("mknod(/dev/urandom)"); 72 - fd = open("/dev/urandom", O_WRONLY); 61 + pretty_message("[+] Fake seeding RNG..."); 62 + fd = open("/dev/random", O_WRONLY); 73 63 if (fd < 0) 74 - panic("open(urandom)"); 75 - for (int i = 0; i < 256; ++i) { 76 - if (ioctl(fd, RNDADDENTROPY, &entropy) < 0) 77 - panic("ioctl(urandom)"); 78 - } 64 + panic("open(random)"); 65 + if (ioctl(fd, RNDADDTOENTCNT, &bits) < 0) 66 + panic("ioctl(RNDADDTOENTCNT)"); 79 67 close(fd); 80 68 } 81 69 ··· 258 270 259 271 int main(int argc, char *argv[]) 260 272 { 261 - seed_rng(); 262 273 ensure_console(); 263 274 print_banner(); 264 275 mount_filesystems(); 276 + seed_rng(); 265 277 kmod_selftests(); 266 278 enable_logging(); 267 279 clear_leaks();