Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98130 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 28118 invoked from network); 3 Feb 2017 06:15:57 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Feb 2017 06:15:57 -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:44062] helo=es-i.jp) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4F/42-51557-A1024985 for ; Fri, 03 Feb 2017 01:15:55 -0500 Received: (qmail 12485 invoked by uid 89); 3 Feb 2017 06:15:50 -0000 Received: from unknown (HELO mail-qt0-f180.google.com) (yohgaki@ohgaki.net@209.85.216.180) by 0 with ESMTPA; 3 Feb 2017 06:15:50 -0000 Received: by mail-qt0-f180.google.com with SMTP id k15so19355089qtg.3 for ; Thu, 02 Feb 2017 22:15:50 -0800 (PST) X-Gm-Message-State: AIkVDXKrH8pE0f3xRaJ9OUgeHK8dP5klReHKn6Q9RIH/EX8MKL/jIEMwUAeUCM6M9fdV1i4ZjINfrk74N6A4Bw== X-Received: by 10.55.19.66 with SMTP id d63mr11308223qkh.73.1486102544521; Thu, 02 Feb 2017 22:15:44 -0800 (PST) MIME-Version: 1.0 Received: by 10.140.19.232 with HTTP; Thu, 2 Feb 2017 22:15:03 -0800 (PST) In-Reply-To: References: <0D26A03B-6BEB-4730-8E4B-0F7D6835E683@thefsb.org> <8991137d8dd8ba915bcacd4fbc1fe88f@gmail.com> Date: Fri, 3 Feb 2017 15:15:03 +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=001a114018d8444bf705479a364e Subject: Re: [PHP-DEV] Re: Improving mt_rand() seed From: yohgaki@ohgaki.net (Yasuo Ohgaki) --001a114018d8444bf705479a364e Content-Type: text/plain; charset=UTF-8 Hi all, On Thu, Feb 2, 2017 at 12:47 PM, Yasuo Ohgaki wrote: > > Posting RFC draft before discussion > > https://wiki.php.net/rfc/improve_predictable_prng_random > > This RFC includes results of recent PRNG related discussions. > I would like to keep it simple, but basic object feature will be > implemented. > > Methods could raise exceptions for invalid operations rather than ignoring. > > Comments? > I realized BC in PHP 7.1 is not so obvious. I added what's broken by PHP 7.1. I also made to raise exception for insane usage. Reseed cycle can be set up to 2^31. https://wiki.php.net/rfc/improve_predictable_prng_random RFC is written to implement to be minimal/enough to fix issues consistently. Adding new Random object or methods are easy if these are needed. Please note that RFC objectives are - Fix BC made by PHP 7.1. (For PHP 7.1, we may simply add new state for rand()/srand(), but this is out of scope) - Use MT rand optimal way - Keep it simple to be minimal - Keep consistency across APIs There are worry about CSPRNG overhead, reading 2500 bytes from CSPRNG on PHP 7.1-dev debug build took less than 0.00001 sec with my PC. [yohgaki@dev PHP-7.1]$ ./php-bin -d error_reporting=-1 -r '$s = microtime(true);for ($i=0; $i<1000; $i++) $n=random_bytes(2500); var_dump(microtime(true)-$s);' float(0.010347843170166) Since it will reseed 1 in 100, average overhead is less than 0.0000001 sec with debug build. 100 seems good choice. IMO. I don't mind to use larger reseed cycle default if it isn't too large. Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net --001a114018d8444bf705479a364e--