From owner-svn-src-all@FreeBSD.ORG Wed Jan 25 19:20:09 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 29C381065678 for ; Wed, 25 Jan 2012 19:20:09 +0000 (UTC) (envelope-from markm@FreeBSD.org) Received: from gromit.grondar.org (grandfather.grondar.org [IPv6:2a01:348:0:15:5d59:5c20:0:2]) by mx1.freebsd.org (Postfix) with ESMTP id 38DAB8FC17 for ; Wed, 25 Jan 2012 19:20:08 +0000 (UTC) Received: from uucp by gromit.grondar.org with local-rmail (Exim 4.76 (FreeBSD)) (envelope-from ) id 1Rq8O7-0000P8-4f for svn-src-all@freebsd.org; Wed, 25 Jan 2012 19:20:07 +0000 Received: from localhost ([127.0.0.1] helo=groundzero.grondar.org) by groundzero.grondar.org with esmtp (Exim 4.77 (FreeBSD)) (envelope-from ) id 1Rq8Kn-000Ms9-KE; Wed, 25 Jan 2012 19:16:41 +0000 To: Andrey Chernov In-reply-to: <20120125140237.GA74896@vniz.net> References: <201201162018.q0GKIADK050161@svn.freebsd.org> <20120118061943.GA80874@vniz.net> <20120120055823.GA28177@vniz.net> <20120120215649.GA40016@vniz.net> <20120122185545.GA11874@vniz.net> <20120125140237.GA74896@vniz.net> From: Mark Murray Date: Wed, 25 Jan 2012 19:16:41 +0000 Message-Id: Cc: svn-src-head@FreeBSD.ORG, svn-src-all@FreeBSD.ORG, src-committers@FreeBSD.ORG Subject: Re: svn commit: r230230 - head/sys/dev/random X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Jan 2012 19:20:09 -0000 Andrey Chernov writes: > On Sun, Jan 22, 2012 at 09:43:02PM +0000, Mark Murray wrote: > > > Thanx for review! I'll send final version to this thread a bit > > > later when I'll find more free time. > > Final, unless something else noticed. Cool. NOTE: I am only eyeballing this, not testing it. > --- sys/libkern.h.bak 2012-01-16 07:15:12.000000000 +0400 > +++ sys/libkern.h 2012-01-25 17:31:49.000000000 +0400 > @@ -72,6 +72,7 @@ static __inline quad_t qabs(quad_t a) { > > /* Prototypes for non-quad routines. */ > struct malloc_type; > +extern int arc4rand_iniseed_state; > uint32_t arc4random(void); > void arc4rand(void *ptr, u_int len, int reseed); > int bcmp(const void *, const void *, size_t); Fine. > --- dev/random/randomdev_soft.c.bak 2011-03-02 01:42:19.000000000 +0300 > +++ dev/random/randomdev_soft.c 2012-01-25 17:28:19.000000000 +0400 > @@ -366,6 +366,8 @@ random_yarrow_unblock(void) > selwakeuppri(&random_systat.rsel, PUSER); > wakeup(&random_systat); > } > + if (arc4rand_iniseed_state == 0) > + arc4rand_iniseed_state = 1; > } > > static int I thought you were going to do this as a function? It would be slightly neater to do it that way. > --- libkern/arc4random.c.bak 2008-08-08 01:51:09.000000000 +0400 > +++ libkern/arc4random.c 2012-01-25 17:30:30.000000000 +0400 > @@ -24,6 +24,8 @@ __FBSDID("$FreeBSD: src/sys/libkern/arc4 > #define ARC4_RESEED_SECONDS 300 > #define ARC4_KEYBYTES (256 / 8) > > +int arc4rand_iniseed_state = 0; > + > static u_int8_t arc4_i, arc4_j; > static int arc4_numruns = 0; > static u_int8_t arc4_sbox[256]; > @@ -74,6 +76,8 @@ arc4_randomstir (void) > /* Reset for next reseed cycle. */ > arc4_t_reseed = tv_now.tv_sec + ARC4_RESEED_SECONDS; > arc4_numruns = 0; > + if (arc4rand_iniseed_state == 1) > + arc4rand_iniseed_state = -1; > > /* > * Throw away the first N words of output, as suggested in the > @@ -130,7 +134,7 @@ arc4rand(void *ptr, u_int len, int resee > struct timeval tv; > > getmicrouptime(&tv); > - if (reseed || > + if (reseed || arc4rand_iniseed_state == 1 || > (arc4_numruns > ARC4_RESEED_BYTES) || > (tv.tv_sec > arc4_t_reseed)) > arc4_randomstir(); Looks good! Are you sure this needs no locking or volatile variables? M -- Mark R V Murray Cert APS(Open) Dip Phys(Open) BSc Open(Open) BSc(Hons)(Open) Pi: 132511160