Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:72602 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 31170 invoked from network); 14 Feb 2014 15:30:44 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Feb 2014 15:30:44 -0000 Authentication-Results: pb1.pair.com header.from=jakub.php@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=jakub.php@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.177 as permitted sender) X-PHP-List-Original-Sender: jakub.php@gmail.com X-Host-Fingerprint: 209.85.216.177 mail-qc0-f177.google.com Received: from [209.85.216.177] ([209.85.216.177:42154] helo=mail-qc0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3D/F3-09381-2A63EF25 for ; Fri, 14 Feb 2014 10:30:43 -0500 Received: by mail-qc0-f177.google.com with SMTP id i8so20009341qcq.22 for ; Fri, 14 Feb 2014 07:30:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=FGk9H5Pojseu+OcCXp/3ZDb2XextJhKGgsehvkbo4Hk=; b=FFw55X5peJb7R6xQzFMpKSkMj+tq/J2FAkAjtJGZB0oPEe7Dp9mlnnquQvojPgWb9/ /MR8If9hxgwBy1o18cjtVgs3ROxmJE2GB6enUEH0bjSJvrtOmbUXybHHQU8AB/5Plko5 O4U0w3YjZ+kQ7MRzcJNCzhJzGwY82HTJ/y8gDlMk26KqIPGOBqctpV9KKft5m1adwRaw 2bMrwK+8q1QEBbDKurgcpeS9HJZRpxowEtSVT+WdNPg3+z1AU9x1J7hbh4Y6vfxPMPZ+ BkfZbbX/OMjPbxQVtUcg57d2AhmB6hsq6sq0maxbQWH4TrxLvZ5NLoVJUFU8xOjtLxUc xYzg== MIME-Version: 1.0 X-Received: by 10.224.32.133 with SMTP id c5mr14114440qad.54.1392391838674; Fri, 14 Feb 2014 07:30:38 -0800 (PST) Sender: jakub.php@gmail.com Received: by 10.224.68.68 with HTTP; Fri, 14 Feb 2014 07:30:38 -0800 (PST) In-Reply-To: References: Date: Fri, 14 Feb 2014 15:30:38 +0000 X-Google-Sender-Auth: ngBPX-RHdINt9-ubiT7cpSjaqW4 Message-ID: To: Andrey Andreev Cc: Pierre Joye , PHP internals Content-Type: multipart/alternative; boundary=047d7b677600eeb46e04f25f7c6b Subject: Re: [PHP-DEV] unify entropy source for all php related functions From: bukka@php.net (Jakub Zelenka) --047d7b677600eeb46e04f25f7c6b Content-Type: text/plain; charset=ISO-8859-1 On Fri, Feb 14, 2014 at 2:54 PM, Andrey Andreev wrote: > On Fri, Feb 14, 2014 at 4:19 PM, Jakub Zelenka wrote: > > On Fri, Feb 14, 2014 at 1:53 PM, Pierre Joye > wrote: > >> > >> On Feb 14, 2014 8:02 PM, "Andrey Andreev" wrote: > >> > >> > So how does openssl_random_pseudo_bytes() work without blocking then? > >> > >> Because it tells you if the result is crypto safe or not: > >> > >> string *openssl_random_pseudo_bytes* (int $length [, bool > &$crypto_strong] > >> ) > >> > >> > >> If you want only crypto safe result another function has to be used (on > >> opennssl). > > And my test.php that was pasted shows that it dumps TRUE for > $crypto_strong, while mcrypt_create_iv() blocks. > > > That's not the way how it works in md_rand. The ssleay_rand_pseudo_bytes > > (Rand_psedobytes called in openssl_random_pseudo_bytes) is just a wrapper > > for ssleay_rand_bytes with pseudo flag set to 1. ssleay_rand_bytes first > > calls Rand_poll that adds the entropy. The thing is that the entropy is > > taken from /dev/urandom on Unix. It means you will always have enough > > entropy on Linux and the functions returns 1 ($crypto_strong is set to > > true). You won't get false on Linux though. The reason of the flag in > > OpenSSL is if you run it in on some platform that can't provide enough > > entropy which is not the case on Linux. Please see the sources for more > > details. > > Sorry, I'm not really sure what this means, but 2 few bits that I spot are: > > - on UNIX(-like), it uses /dev/urandom > It uses /dev/urandom for seeding PRNG. It means that it reads only 32 bytes (256 bits) from it. If you call openssl_random_pseudo_bytes you will get bytes generated by PRNG > - $crypto_strong will always be true on Linux (UNIX-whatever) > Yes. The reason is that /dev/urandom is non-blocking and you will always get enough entropy from it. You don't have to check the flag on Linux because it will be always true! The point is that OpenSSL considers /dev/urandom strong enough for seeding CSPRNG. Jakub --047d7b677600eeb46e04f25f7c6b--