Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 3 Feb 2003 14:46:29 +0300
From:      "Andrey A. Chernov" <ache@nagual.pp.ru>
To:        Kris Kennaway <kris@obsecurity.org>
Cc:        current@FreeBSD.ORG
Subject:   Final fix for correlation problem (was Re: rand() is broken)
Message-ID:  <20030203114629.GA77557@nagual.pp.ru>
In-Reply-To: <20030202090422.GA59750@nagual.pp.ru>
References:  <20030202070644.GA9987@rot13.obsecurity.org> <20030202090422.GA59750@nagual.pp.ru>

next in thread | previous in thread | raw e-mail | index | archive | help

--bp/iNruPH9dso1Pn
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

This is final fix for 1st value correlation problem. Somebody with=20
math statistic knowledge please run some test to be sure that NSHUFF is=20
good enough for this simple PRNG (i.e. not 100% good, but good for average=
=20
quality PRNG we have). My simple test shown that 100 is enough, but I=20
am not PRNG math expert. Maybe increasing NSHUFF up too 2000 required.

Similar patch is needed for random(3) TYPE_0 too, I'll produce it when we
find good NSHUFF.

--- stdlib/rand.c.bak	Mon Feb  3 13:22:12 2003
+++ stdlib/rand.c	Mon Feb  3 14:03:58 2003
@@ -51,6 +51,8 @@
 #include <stdio.h>
 #endif /* TEST */
=20
+#define NSHUFF 100      /* to drop seed -> 1st value correlation */
+
 static int
 do_rand(unsigned long *ctx)
 {
@@ -108,7 +110,11 @@
 srand(seed)
 u_int seed;
 {
+	int i;
+
 	next =3D seed;
+	for (i =3D 0; i < NSHUFF; i++)
+		(void)do_rand(&next);
 }
=20
=20
@@ -137,7 +143,7 @@
 		unsigned long junk;
=20
 		gettimeofday(&tv, NULL);
-		next =3D (getpid() << 16) ^ tv.tv_sec ^ tv.tv_usec ^ junk;
+		srand((getpid() << 16) ^ tv.tv_sec ^ tv.tv_usec ^ junk);
 	}
 }
=20

--=20
Andrey A. Chernov
http://ache.pp.ru/

--bp/iNruPH9dso1Pn
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.0 (FreeBSD)

iQCVAwUBPj5WleJgpPLZnQjrAQHqRgQAiH7mWI2K30s/m9dilOVcj5v62kVcPoW5
rADaGKbs44d3r6XVyFnlB32I4HNq74n8LhGQmxZTe0dHAF4Q4P3n0mLk4GgKyNEq
nrAfJ0IE6y7YuEa71uACYq2G0DRPRITve/T80kWsDoTAHFA/Z/LG7OR2Q83UmrXz
l6FSYPzmLk8=
=juZn
-----END PGP SIGNATURE-----

--bp/iNruPH9dso1Pn--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030203114629.GA77557>