Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:72996 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 80795 invoked from network); 7 Mar 2014 17:18:59 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Mar 2014 17:18:59 -0000 Authentication-Results: pb1.pair.com smtp.mail=pierre.php@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=pierre.php@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.169 as permitted sender) X-PHP-List-Original-Sender: pierre.php@gmail.com X-Host-Fingerprint: 209.85.216.169 mail-qc0-f169.google.com Received: from [209.85.216.169] ([209.85.216.169:52580] helo=mail-qc0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 84/D3-57079-08FF9135 for ; Fri, 07 Mar 2014 12:18:57 -0500 Received: by mail-qc0-f169.google.com with SMTP id i17so5021141qcy.28 for ; Fri, 07 Mar 2014 09:18:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=2v/s1C257SHtmxjjS8guZvcr8mk3S30FlVpQUxjCx40=; b=WmorLcGVEG4R5kZM0RKMkpCzTCEntZpoSKObS9T0V4ILVNmXwLZXcz7jNs3fwvpKK/ eVhLpN3IsAQUHdpviGyDwCrqSGz79db8fkg++42WFSAtQFJd6LS32WGvUHy8LAnC40Tp nwh/aeRcetXzAcwiZ5hjeYWl+p0Y16uF2hu/AGJncEgpyAat0OJwCPHtMSwySclrPPQW WSrkn5m/uAJob2YLm8jIkh7k9nZL2caHFe6/lBvHargxoJCS75E3K6npqWjUaE0nwtNZ e8pZSb0AIhXByhVZaKU4rVLbimSzRbGhNF96rxVZ4I52uoW4qbztGyA4q70SpR/Ds7vD bTxw== MIME-Version: 1.0 X-Received: by 10.140.26.43 with SMTP id 40mr21690600qgu.86.1394212733561; Fri, 07 Mar 2014 09:18:53 -0800 (PST) Received: by 10.140.18.145 with HTTP; Fri, 7 Mar 2014 09:18:53 -0800 (PST) Received: by 10.140.18.145 with HTTP; Fri, 7 Mar 2014 09:18:53 -0800 (PST) In-Reply-To: References: Date: Fri, 7 Mar 2014 18:18:53 +0100 Message-ID: To: Nikita Popov Cc: PHP internals Content-Type: multipart/alternative; boundary=001a11c12bf0b9b05a04f40772cf Subject: Re: [PHP-DEV] Default mcrypt_create_iv() to /dev/urandom From: pierre.php@gmail.com (Pierre Joye) --001a11c12bf0b9b05a04f40772cf Content-Type: text/plain; charset=UTF-8 Hi Nikita, On Mar 7, 2014 4:56 PM, "Nikita Popov" wrote: > > Hi internals! > > Currently the mcrypt_create_iv() function uses /dev/random as the default > source for random bytes. This is problematic, because /dev/random will > block if entropy for reseeding the kernel's CSPRNG is estimated to be low. > If mcrypt_create_iv() with default parameters is used in any kind of > user-facing code the blocking will cause unpredictable slowdowns and can be > easily exploited for a denial of service attack. > > /dev/urandom - contrary to popular misconception - is also a > cryptographically safe source of randomness and is recommended over the use It is not, see below. > of /dev/random for most (sometimes all) applications [1] [2] [3] [4] [5]. > Quoting from the /dev/random man page [1]: > > > If you are unsure about whether you should use */dev/random* or > > */dev/urandom*, then probably you want to use the latter. As a > > general rule, */dev/urandom* should be used for everything except > > long-lived GPG/SSL/SSH keys. [*] And that is exactly why it fits on cryptographic safe. See the other discussions about prng, there is a lot of confusion about this wording. :) > One potential issue when using /dev/urandom is that on some systems > (notably Linux, but not BSD) it will not block even if it can't gather > enough initial entropy for seeding the CSPRNG and as such produce > predicable outputs. This condition can only occur immediately after system > startup and as per the /dev/random man page [1] this is mitigated by "all > major Linux distributions [...] since 2000 at least" by saving a seed file. > > As such I would suggest defaulting the mcrypt_create_iv() $source parameter > to MCRYPT_DEV_URANDOM. Objections? I have no objection as uramdom is good enough for 99.999% of php usage. Cheers, Pierre > Nikita > > [*] The latter claim is disputed, see for example the end of [4]. > > [1]: http://man7.org/linux/man-pages/man4/random.4.html > [2]: http://sockpuppet.org/blog/2014/02/25/safely-generate-random-numbers/ > [3]: > http://security.stackexchange.com/questions/3936/is-a-rand-from-dev-urandom-secure-for-a-login-key/3939#3939 > [4]: http://blog.cr.yp.to/20140205-entropy.html > [5]: http://www.2uo.de/myths-about-urandom/ --001a11c12bf0b9b05a04f40772cf--