Fix for pure initial seeding of libkern/arc4random.c

From: Andrey Chernov <ache_at_freebsd.org>
Date: Sat, 26 Nov 2011 09:51:07 +0400
This is preliminary patch just to illustrate idea how bad (31bit) initial 
seeding of kernel's arc4random() can be fixed. Do you like it?

--- yarrow.c.bak	2011-11-26 09:40:49.000000000 +0400
+++ yarrow.c	2011-11-26 09:44:05.000000000 +0400
_at__at_ -59,6 +59,8 _at__at_ static void reseed(u_int);
 /* The reseed thread mutex */
 struct mtx random_reseed_mtx;
 
+static arc4rand_reseed = 1;
+
 /* Process a single stochastic event off the harvest queue */
 void
 random_process_event(struct harvest *event)
_at__at_ -261,6 +263,11 _at__at_ reseed(u_int fastslow)
 
 	/* Release the reseed mutex */
 	mtx_unlock(&random_reseed_mtx);
+
+	if (arc4rand_reseed) {
+		arc4rand_reseed = 0;
+		arc4rand(NULL, 0, 1);
+	}
 }
 
 /* Internal function to return processed entropy from the PRNG */

-- 
http://ache.vniz.net/
Received on Sat Nov 26 2011 - 04:51:10 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:21 UTC