From owner-svn-src-all@FreeBSD.ORG Thu Jan 26 18:55:32 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 5589A1065673 for ; Thu, 26 Jan 2012 18:55:32 +0000 (UTC) (envelope-from markm@FreeBSD.org) Received: from gromit.grondar.org (grandfather.grondar.org [93.89.92.32]) by mx1.freebsd.org (Postfix) with ESMTP id 1A3318FC0C for ; Thu, 26 Jan 2012 18:55:31 +0000 (UTC) Received: from uucp by gromit.grondar.org with local-rmail (Exim 4.76 (FreeBSD)) (envelope-from ) id 1RqUOd-0002tR-5d for svn-src-all@freebsd.org; Thu, 26 Jan 2012 18:50: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 1RqUNN-000OwI-0g; Thu, 26 Jan 2012 18:48:49 +0000 To: David Schultz In-reply-to: <20120126175243.GA19199@zim.MIT.EDU> References: <20120126143819.GA88677@vniz.net> <20120126155626.GA92229@vniz.net> <201201261132.38320.jhb@freebsd.org> <20120126165521.GA92622@vniz.net> <20120126175243.GA19199@zim.MIT.EDU> From: Mark Murray Date: Thu, 26 Jan 2012 18:48:48 +0000 Message-Id: Cc: svn-src-head@FreeBSD.ORG, svn-src-all@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: Thu, 26 Jan 2012 18:55:32 -0000 David Schultz writes: > > Although current version with current kernel flags works, I forget > > it is implementation defined in general and not always equal to > > sizeof(int), f.e. with gcc --short-enums. I'll remade it with > > #defines, thanx again. > > Why complicate things with atomics at all? A race might result in > arc4random(9) being seeded multiple times, but that's harmless. > > The race that worries me is that consumers that call arc4random() > before it is properly seeded will get predictable numbers. To fix > that robustly, we'd either have to move arc4random() into the random > module (tricky given all the places where it's used), or make the > random module a mandatory part of the kernel. There is a VERY old problem here, and it is of the chicken vs egg variety. The random device won't unlock until it has enough entropy, and there are things in the kernel that appear to need "random enough" numbers earlier than that. It ought to be possible to unlock the CSPRNG by harvesting entropy earlier, but this is hard work. Very hard work. Unless you have entropy-generating hardware. In the meanwhile, you are left with other alternatives; reseed arc4random() with some early entropy; try to move entropy consumers to later in the boot sequence; try to not depend on entropy early on, and correct for this later (where necessary). There are loads of other alternatives. What you can't do is unlock before you have enough entropy, and that won't happen until the running kernel has had some time to accumulate this. I am in favour of treating arc4random() as a PRNG with (say) the date/time, the TSC register and other easy-to-get data as the first seed. After that its treated as a CSPRNG. This requires that early consumers know the limitations and adapt to them. The notion of making arc4random() block would be silly; the point of the thing is that it always returns numbers, and after the random device seeds, it should always be good. > OpenSSL addresses the issue by providing two APIs: RAND_bytes() > requires a good entropy source and produces cryptographically strong > pseudorandomness. RAND_pseudo_bytes() produces "good" (but not > necessarily unpredictable) randomness, even in the absence of an > entropy source. Applications call one interface or the other, > depending on whether they require cryptographic- quality randomness. You are treading on graves here :-). An ancient bikeshed is buried in the vicinty. M -- Mark R V Murray Cert APS(Open) Dip Phys(Open) BSc Open(Open) BSc(Hons)(Open) Pi: 132511160