Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98032 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 55839 invoked from network); 30 Jan 2017 02:26:31 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Jan 2017 02:26:31 -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:48284] helo=es-i.jp) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 14/80-51557-454AE885 for ; Sun, 29 Jan 2017 21:26:31 -0500 Received: (qmail 115066 invoked by uid 89); 30 Jan 2017 02:26:24 -0000 Received: from unknown (HELO mail-wm0-f53.google.com) (yohgaki@ohgaki.net@74.125.82.53) by 0 with ESMTPA; 30 Jan 2017 02:26:24 -0000 Received: by mail-wm0-f53.google.com with SMTP id v77so27660109wmv.0 for ; Sun, 29 Jan 2017 18:26:23 -0800 (PST) X-Gm-Message-State: AIkVDXItYArP6Y7lwJ3JwZI/ucoVt2ZRu1QpXCggCstSuwJn44Z5u9ucM5TKqcgidXXljkY4N2ftzE6xirp66w== X-Received: by 10.28.51.205 with SMTP id z196mr11213694wmz.22.1485743176423; Sun, 29 Jan 2017 18:26:16 -0800 (PST) MIME-Version: 1.0 Received: by 10.195.12.8 with HTTP; Sun, 29 Jan 2017 18:25:35 -0800 (PST) In-Reply-To: References: <0D26A03B-6BEB-4730-8E4B-0F7D6835E683@thefsb.org> Date: Mon, 30 Jan 2017 11:25:35 +0900 X-Gmail-Original-Message-ID: Message-ID: To: Tom Worster Cc: "internals@lists.php.net" , =?UTF-8?Q?Lauri_Kentt=C3=A4?= , Leigh , Nikita Popov Content-Type: multipart/alternative; boundary=001a11444e804223cd0547468a12 Subject: Re: [PHP-DEV] Re: Improving mt_rand() seed From: yohgaki@ohgaki.net (Yasuo Ohgaki) --001a11444e804223cd0547468a12 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi all, On Mon, Jan 30, 2017 at 10:08 AM, Yasuo Ohgaki wrote: > Issues are >> - Current mt_rand() is not fully exploited. It wastes more than 99% of i= ts >> random cycle. >> >> This was discussed in Aug last year and dropped. >> > I didn't notice the discussion, let's discuss again. > > It does not make sense to discard more than 99% of cycle. In addition, MT > rand reference implementation is capable to initialize whole state buffer= , > why we shouldn't have it? > First of all, users should never use mt_rand() for any security related purposes. However, there are too many codes that use mt_rand() for the purpose. MT rand is a lot harder to predict than older predictable PRNG. Many users misunderstood it as "secure like CSPRNG" because it is advertised "very secure and hard to predict than older PRNG" too much. Attackers can get "mt_rand() generated random string" very easily on many apps. Apps generate access token by mt_rand() is just a matter of requesting proper apps' feature. e.g. password generated by mt_rand(), access token generated by mt_rand(). With ideal implementation, attackers must search random sequence from 2^19937=E2=88=921 cycle, but they can guess random sequence easily because PHP's mt_rand() has only 2^32 initial states. It's far less than 1% of MT rand capability. This allows attackers to guess "mt_rand() generated random string" easily than it could be. Attackers may get victim's correct password with combination of "getting mt_rand() generated password" and "social engineering", e.g. Notify victim "Your account is compromised, please reset your password. Please make sure to use system generated strong random password". Exploiting Access token that allows access to system by itself could be even easier. Attackers generate mt_rand() created access token and guess next access token to be generated, then use the access token that is owned by poor victim. _Mainly_, it is users fault because mt_rand() should never be used for above purpose, but mt_rand() generated random string being extremely weak than it could be is our fault. Our part could be fixed by us. Let's fix it now. Lauri made patch for unseeded mt_rand(). I'll prepare patch that allows int array initialization for mt_srand() so that whole state buffer can be initialized as user specifies. void mt_srand(int|array $seed) where $seed could be $seed =3D [123456789, 987654321, ....]; // Up to max size of state buffer It can be said current mt_rand() is good enough for the purpose. I totally agree with this. However, I cannot agree that current mt_rand() implementation is ideal/what is should be. Any comments? Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net --001a11444e804223cd0547468a12--