Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:84824 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 79676 invoked from network); 15 Mar 2015 13:17:06 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Mar 2015 13:17:06 -0000 Authentication-Results: pb1.pair.com header.from=padraic.brady@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=padraic.brady@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.50 as permitted sender) X-PHP-List-Original-Sender: padraic.brady@gmail.com X-Host-Fingerprint: 209.85.213.50 mail-yh0-f50.google.com Received: from [209.85.213.50] ([209.85.213.50:35089] helo=mail-yh0-f50.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 70/48-29489-05685055 for ; Sun, 15 Mar 2015 08:17:04 -0500 Received: by yhct68 with SMTP id t68so9515629yhc.2 for ; Sun, 15 Mar 2015 06:17:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=wYedjcOE1Lh+3nT3V+MU14igGDJT1mOiAKjcfKY39UQ=; b=09erq2/cobAFAsIgs8Iz2uSOuM5k9u0kNmb3LeYB2g+blKSoHmyBnh7WBjQCTmkBBL uxhMM4PPVuroD4L//LdgUUYtzKNYIsd42tGm1h9714zTkaQQWIOejt3P2VK/mFTJpK8k OW4iJ0fw0vjyJOYkjAR7DghotJItH9Nxk2X4XWQpTAipyuVg0DFac57MgZOA9/Dh+E5/ p+tjQiwMLFlHBOPHbx4orVdCWAcK/xEAqvUZcOTWL7uRmLIira6W4Wpkerre8D5ndPuC +j9Jo4eTaFB0xhki61b+7EdtEcKIYq0F3muifvUrDrapfnamank0+/FNj+FoTLpz9Okg yIpw== MIME-Version: 1.0 X-Received: by 10.236.227.198 with SMTP id d66mr55435918yhq.147.1426425421991; Sun, 15 Mar 2015 06:17:01 -0700 (PDT) Received: by 10.170.222.86 with HTTP; Sun, 15 Mar 2015 06:17:01 -0700 (PDT) In-Reply-To: <55055F1D.2020200@beccati.com> References: <55055F1D.2020200@beccati.com> Date: Sun, 15 Mar 2015 13:17:01 +0000 Message-ID: To: Matteo Beccati Cc: Sammy Kaye Powers , PHP Internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] [VOTE] Vote open for reliable user-land CSPRNG From: padraic.brady@gmail.com (=?UTF-8?Q?P=C3=A1draic_Brady?=) Hi Matteo, On 15 March 2015 at 10:29, Matteo Beccati wrote: > Disclaimer: I do know a little about security, but I am not a crypto-expe= rt > by any means. If I'm saying something silly, just let me know ;) > > I want to vote yes, but naming is something that scares me a bit. Without > any indication that it's CSPRNG, people might start using it even when > unnecessary, and I'd be worried about potential negative effects, such as > exhausting the entropy pool. It's probably more of a documentation proble= m, > but we know many won't read the docs and a "hint" in the function name co= uld > help guiding users. Were folk to use random_int() by default, it would be actually be considerably better than the situation today where many reach for mt_rand() without really considering the use case. Using a strong source of ints instead of a weak source still ends up with you getting the requested ints. There's no downside unless the source is blocking. Using the weak source over a strong source will also get you ints, but without knowing the use, it has the immediate downside risk of being from a weak source which shouldn't be used for anything requiring strong randomness. So random_int() really is the best first default option to go for when in doubt, with some careful consideration before switching to mt_rand(). As for exhausting the entropy pool, this is something of a misconception. The sources in the RFC are pseudorandom generators which won't exhaust the entropy pool by design. > For example, it would be overkill to use random_int() to randomly pick th= e > content of a boxes at each reload of a web page, but if what I need is a > *random int*, then random_int() seems a far better choice than some obscu= re > rand() or mt_rand(). > > Or in the poker deck example, wouldn't it be enough just to seed mt_srand > with a crypto-secure number to remove the biasing and using mt_rand to > shuffle the deck? In essence, this is what the functions are already providing an interface to: systems which take a truly random seed and output pseudorandom values. The difference is that the underlying system is designed to be cryptographically secure (for most uses). mt_rand(), on the other hand, is not. Paddy -- P=C3=A1draic Brady http://blog.astrumfutura.com http://www.survivethedeepend.com