Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80414 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 99102 invoked from network); 12 Jan 2015 09:37:13 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Jan 2015 09:37:13 -0000 Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 192.64.116.216 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 192.64.116.216 imap10-3.ox.privateemail.com Received: from [192.64.116.216] ([192.64.116.216:38064] helo=imap10-3.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DE/11-26669-8C593B45 for ; Mon, 12 Jan 2015 04:37:13 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id 515BC2400D4; Mon, 12 Jan 2015 04:37:09 -0500 (EST) X-Virus-Scanned: Debian amavisd-new at imap10.ox.privateemail.com Received: from mail.privateemail.com ([127.0.0.1]) by localhost (imap10.ox.privateemail.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id Dz15ZsP-IHsl; Mon, 12 Jan 2015 04:37:09 -0500 (EST) Received: from [137.50.28.190] (oa-res-28-190.wireless.abdn.ac.uk [137.50.28.190]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.privateemail.com (Postfix) with ESMTPSA id EC5F52400AA; Mon, 12 Jan 2015 04:37:05 -0500 (EST) References: <54B30DB9.3000003@seld.be> <76B8D342-43E7-42E6-AD82-FCF7C5CA8658@ajf.me> <54B31D77.9010100@gmail.com> <976B7B2E-7BC9-4514-ABF3-C0DA3ED98897@ajf.me> <54B32145.80501@gmail.com> <54B32BEA.5090507@gmail.com> <54B38EA6.8070402@lerdorf.com> <47FF88D5-14F8-4844-A9DD-51532FBF3588@ajf.me> Mime-Version: 1.0 (1.0) In-Reply-To: <47FF88D5-14F8-4844-A9DD-51532FBF3588@ajf.me> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Message-ID: Cc: Stanislav Malyshev , Yasuo Ohgaki , PHP Internals List X-Mailer: iPhone Mail (12B440) Date: Mon, 12 Jan 2015 09:37:02 +0000 To: Rasmus Lerdorf Subject: Re: [PHP-DEV] rand(), mt_rand() and limits From: ajf@ajf.me (Andrea Faulds) > On 12 Jan 2015, at 09:31, Andrea Faulds wrote: >=20 > Hi Rasmus, >=20 >> On 12 Jan 2015, at 09:06, Rasmus Lerdorf wrote: >>=20 >> Yes, there is plenty of code out there that relies on srand()+rand() >> returning a repeatable sequence of pseudo-random numbers. I have written >> some myself. C devs are very familiar with this behaviour of srand. >=20 > C devs are also familiar with the usage of strtok, but it doesn't make an A= PI with global state any less flawed. >=20 > The problem with rand() and srand() is they're used for three different pu= rposes, only one of which they're terribly fitting for: >=20 > - To produce a non-repeatable sequence of random numbers (works OK if sran= d() isn't used) > - To produce a repeatable sequence of random numbers (works, but only if y= ou and the sole user of the global random number generator, which is not gu= aranteed by any means) Oops, I accidentally sent that before finishing. - To generate cryptographic keys - a seeded random number generator should N= EVER be used for this, but because PHP is so lacking in good facilities to o= btain random data for cryptographic purposes, unfortunately rand() is used m= ore than it should be. rand() is already pretty bad, but the existence of sr= and() makes this a particular problem. Everything shares the same random num= ber generator, which makes it worse, as something might seed it and now your= key is easily predictable. This is why Suhosin disabled srand by default: it is, unfortunately, also a s= ecurity issue. -- Andrea Faulds http://ajf.me/=