Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:94002 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 21920 invoked from network); 15 Jun 2016 11:11:03 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Jun 2016 11:11:03 -0000 Authentication-Results: pb1.pair.com smtp.mail=cmbecker69@gmx.de; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=cmbecker69@gmx.de; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmx.de designates 212.227.17.22 as permitted sender) X-PHP-List-Original-Sender: cmbecker69@gmx.de X-Host-Fingerprint: 212.227.17.22 mout.gmx.net Received: from [212.227.17.22] ([212.227.17.22:58375] helo=mout.gmx.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0C/AE-27860-5C731675 for ; Wed, 15 Jun 2016 07:11:02 -0400 Received: from [192.168.2.102] ([217.82.228.97]) by mail.gmx.com (mrgmx101) with ESMTPSA (Nemesis) id 0Lm7MT-1bmCMA2Ggb-00ZjKz; Wed, 15 Jun 2016 13:10:55 +0200 To: Tom Worster , Leigh , internals@lists.php.net References: <53e44ebc-6ed0-089d-9798-843802b88cd2@thefsb.org> Message-ID: <09801e5f-1b7a-32e4-8768-bbf6ab175e23@gmx.de> Date: Wed, 15 Jun 2016 13:11:11 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.1 MIME-Version: 1.0 In-Reply-To: <53e44ebc-6ed0-089d-9798-843802b88cd2@thefsb.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:cnRe6bUlUW/0+YK0sKV19ylS7fxPlV0GXJ7tYRJJ7xr6VY0lWTa od0ZkoDvE/0e++WA7XKfmB5CKWbYp9Tvi3xqIdKe1D3ZrMYtU7PKBQvaPb7e9e7T0nqp8bj BWtL7o4h67sim6tsVT/KN3EQyf/e9TF2IUkl0V7pyTy6roP5CeVk6E1kVlVjCz7w0k71fHo 3HOYuy1bguzXR7R1GACmg== X-UI-Out-Filterresults: notjunk:1;V01:K0:9K8epc3lMX8=:wR8IfN69VyjJ6HvwUmmEMO gVXCYTSmIs62r1kZ+9XDiHoLZAljQ2rVxz+3DXbqz34NtmVQwFE7omSkUMKZmlA0IW+dq7bE6 e3qWwUC2gkb/eOm01yT+/+ol7LFm+c7eJB5wkzqylPiNRS0inYjipB01firpW7Mhi8K44W5ge 7duyttjmiP4WX5JEmU4bwgyrtFV9kgfpP5Jb8TlYwFdMvnwWxW25+Bih3EYjLB3Qb2RpPuOy6 So7B0LdpS8vV83x5svLg4+ldaK77fGNtjkGS6rNgPsRXBEqqBslBx2EZ/bseQsfmqHUxg7kyZ Hu+rWAwz0F3kU2uwKVjRWv14Vp49ZzqVWZCGomi0DLrITXQjYmm9GRURbZiBEaeYcQ4GIbIv2 gwcmP3P3RsDU094QUtyHNV/xONrZ3OcLzxac4FnEWwAIUcS7KJT13enwLNVQzMvDvkAemKOQi v1eUHDeOPSxzyXfQiLraoeECiDyXhbVN2LuY+XgaVFM2ENJ4bWO/NPYQfQakY2twyg5aQBSQK UXtYV6Fkdvmw7FPS1Bb0fMrwFOkp1/ezAPepJTfoTJc2SOODDtzSPdzrxIMSNTkMBbV+thzKc 3pKnWqzx83QsNadDe6s29+X2qpvf8By2HJ6ymPHWNsxxPZgMtgo939kZV5XV1xNIX4NII/uCp 5H4tjvhMRj4dM6WivZ8l29VQ3Xnp8f0cxR7/sNYhe8mLk4ufJbf8TF9EM44tc9N6IdQojSLdM 2F8BGL6Fj784Gj9w2dwIxOhommPAh6drgq4g9D4Jtws62Mp+GIMBvdIQRdTeC0+/r2/JxMkGi JUogl2X Subject: Re: [RFC] RNG fixes From: cmbecker69@gmx.de (Christoph Becker) On 15.06.2016 at 01:08, Tom Worster wrote: > On 6/14/16 12:46 PM, Leigh wrote: > >> The RFC can be found here: https://wiki.php.net/rfc/rng_fixes > > Thanks for putting this together. I am strongly pro on two points and > moderately contra on the other two. I'd prefer separated votes, even > though I don't have a vote. I numbered the 4 bullets in your intro 1 > thru 4. > > 4. Insecure usage. I think we should replace the internal insecure uses > of php_rand(). I can't see a reason not to. > > 3. Poor scaling of bounded outputs. I think RAND_RANGE() should be > fixed. Users surely expect unbiased distribution. There's a BC argument > but the bug is pretty serious. I think this should apply to array_rand() > too. > > 1. Incorrect implementations. > > I don't think we should dictate that programs currently using mt_rand() > shall use in future use MT19937 any more than we should dictate that > XorShift64 or any other PRNG better fits their requirements. > > The incorrectness of the mt_rand() implementation with respect to its > documentation can be fixed either in the code or in the docs. Given > that, as far as we know, mt_rand()'s byte-stream looks like a decent > PRNG[1] it's not clear that the actual MT19937 sequence is more > important that backward compatibility. I for one think it's very unlikely. > > [1] https://gist.github.com/tom--/a12175047578b3ae9ef8 > > I also don't think we should assume the responsibility of correcting > people's insecure programs using rand() or mt_rand() (e.g. for keys, > IVs, salts) by changing the algorithm. Programs this bad need more > rework than we can provide. These functions have had scary-colored > cautions on them for a long time. > > 2. Roughly the same arguments applies to rand(). The function is PHP's > API to the OS's rand(3). There's value to that and probably people who > rely on it. Hm, at least traditionally the rand() implementation on Windows is limited to non-negative short ints (16-bit signed), what appears generally limited, and might make it hard to write portable code. On the other hand a developer could use mt_rand() instead, and we could document that rand() is a rather low-level non-portable API. > Summarizing 2. and 3. it's not clear what we fix in the real world with > the proposed changes to rand() and mt_rand(). But I do see BC breakage. > I would prefer to fix these bugs the docs. > > > With respect to PRNGs completely new to PHP (you mentioned Xoroshiro128+ > and PCG), I would prefer completely divorce this question from the bugs > discussed above. If some PHP users need efficient implementations of > such algorithms then I would urge whoever wants to write them to use a > new API and to provide them via PECL. In software, "better" is always > with respect to context. While there are specific, well-known uses for > random numbers (e.g. crypto) where we can make recommendations, in > general we cannot. I agree to every said (except where noted). -- Christoph M. Becker