Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98118 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 59977 invoked from network); 2 Feb 2017 11:52:41 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Feb 2017 11:52:41 -0000 Authentication-Results: pb1.pair.com header.from=yohgaki@ohgaki.net; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=yohgaki@ohgaki.net; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ohgaki.net designates 180.42.98.130 as permitted sender) X-PHP-List-Original-Sender: yohgaki@ohgaki.net X-Host-Fingerprint: 180.42.98.130 ns1.es-i.jp Received: from [180.42.98.130] ([180.42.98.130:39820] helo=es-i.jp) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 89/D9-51557-78D13985 for ; Thu, 02 Feb 2017 06:52:41 -0500 Received: (qmail 100210 invoked by uid 89); 2 Feb 2017 11:52:36 -0000 Received: from unknown (HELO mail-qt0-f174.google.com) (yohgaki@ohgaki.net@209.85.216.174) by 0 with ESMTPA; 2 Feb 2017 11:52:36 -0000 Received: by mail-qt0-f174.google.com with SMTP id w20so24351460qtb.1 for ; Thu, 02 Feb 2017 03:52:36 -0800 (PST) X-Gm-Message-State: AMke39lK57r2wtRnxVP2eDA3xrEyzLeNujOj/ksFVmoyXdppAbXTU53HYRFjKBtnHH6y6UpixBhU33Hi8KIWHA== X-Received: by 10.55.166.66 with SMTP id p63mr7539566qke.142.1486036348090; Thu, 02 Feb 2017 03:52:28 -0800 (PST) MIME-Version: 1.0 Received: by 10.140.19.232 with HTTP; Thu, 2 Feb 2017 03:51:47 -0800 (PST) In-Reply-To: <1fa97f9f4d4c0866fb4b0f21fc68b068@gmail.com> References: <0D26A03B-6BEB-4730-8E4B-0F7D6835E683@thefsb.org> <8991137d8dd8ba915bcacd4fbc1fe88f@gmail.com> <1fa97f9f4d4c0866fb4b0f21fc68b068@gmail.com> Date: Thu, 2 Feb 2017 20:51:47 +0900 X-Gmail-Original-Message-ID: Message-ID: To: =?UTF-8?Q?Lauri_Kentt=C3=A4?= Cc: Tom Worster , "internals@lists.php.net" , Leigh , Nikita Popov Content-Type: multipart/alternative; boundary=94eb2c070ec8a6c7e705478accf1 Subject: Re: [PHP-DEV] Re: Improving mt_rand() seed From: yohgaki@ohgaki.net (Yasuo Ohgaki) --94eb2c070ec8a6c7e705478accf1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi Lauri, On Thu, Feb 2, 2017 at 6:54 PM, Lauri Kentt=C3=A4 = wrote: > I think this RFC is badly prepared. You're overhauling the whole mt_rand > system in one go, but you're not doing it properly. There is no > justification for breaking compability, not in 7.x and not even in 8.0 in > my opinion. > Which part are you referring as BC? I suppose it is Current behavior is extremely bad because if there is srand()/mt_srand() call in execution path. 1) When seed is provided to srand()/mt_srand(), consecutive rand()/mt_rand() calls became non random. (Unacceptable) 2) 1) applies to across request. (Extremely bad) 3) Even without seed, srand()/mt_srand() call makes guess a lot easier than it should be. i.e. Combined LCG is weak. Suppose attacker find execution path that has static seed for srand()/mt_srand(), then attacker can predict exact random or can guess easily. a.php b.php If a.php is called, then b.php's mt_rand() is not random at all. Even if mt_rand()/rand() is predictable, this kind of behavior is _ABSOLUTELY_ unacceptable. IMO. It's BC, but how many srand()/mt_srand() calls are used in real apps? I know there are, but benefits outweighs BC impact. > > There's now three completely unrelated "issues": > > 1) You want to improve automatic seeding and GENERATE_SEED. You could jus= t > generate a 32-bit value from php_random_bytes and silently use the curren= t > as fallback; this solution was practically accepted already. You just was= te > time with your arguments about CSPRNG being sooooo important: everybody h= as > already heard you, and most people seem to disagree. > True, but I've never heard of CSPRNG failure that could cause BC that matter as PHP problem yet. > > 2) You want to support long seeds. However, 2^32 is a lot of random > states. It's enough for almost any legitimate MT use case. As was earlier > discussed, adding this support to the global mt_srand is not practical. > Anyone who really needs a longer seed should most probably also use a PRN= G > object to avoid cases where some internal function (say, shuffle) modifie= s > the MT state by accident. > > 3) You want to use long seeds by default. This would be possible, as > discussed earlier, by seeding the whole MT state buffer from a CSPRNG. > However, you should consider also the possible performance impact of > generating 2,5 kB from CSPRNG on each request/reseed. And again, 2^32 is > probably enough already. > > FWIW, my Raspberry Pi kernel log has several lines about /dev/urandom not > being properly seeded before the system is fully started, so using a CSPR= NG > is not guaranteed to work so well. > Although users must never do this, but there are codes that generate random password/access key by mt_rand(). If algorithm is known to attacker, all attacker should do could be making very small size of dictionary or current computer is fast enough to compute next random string to be generated in short enough time. If MT rand is seed fully, above task becomes hard enough task attackers to avoid attacks. Reading data from CSPRNG shouldn't be too slow as you know. One in a hundred calls shouldn't matter. Even when it could matter, users may set PHP to reseed one in a million, but the default shouldn't be too large. When hardware TRNG is not available, CSPRNG could generate poor random until system corrects enough entropy events. i.e. matter of time. CSPRNG output should be available. If not, I'm surprised and I'll change my opinion. How many mt_rand()/rand() calls are executed during PHP process lifetime? With 32 bits seed, users will never use even 0.0000000000000001% of MT rand potential. It's too much waste of the algorithm, isn't it? Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net --94eb2c070ec8a6c7e705478accf1--