Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:72597 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 19139 invoked from network); 14 Feb 2014 13:10:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Feb 2014 13:10:51 -0000 Authentication-Results: pb1.pair.com smtp.mail=jakub.php@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=jakub.php@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.46 as permitted sender) X-PHP-List-Original-Sender: jakub.php@gmail.com X-Host-Fingerprint: 209.85.216.46 mail-qa0-f46.google.com Received: from [209.85.216.46] ([209.85.216.46:61638] helo=mail-qa0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D5/E1-09381-BD51EF25 for ; Fri, 14 Feb 2014 08:10:51 -0500 Received: by mail-qa0-f46.google.com with SMTP id k15so4769941qaq.5 for ; Fri, 14 Feb 2014 05:10:48 -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=8QGetSjtBns/zIti9XQfiJUg+RgcqSMWEaFLBTufr9E=; b=i0rx7PvrMMppPAvS7Rx8lqh9AyjFHeDSYNPC9ZEiKd0NgsIK3aoIG5o27pfCKmF5kF CbSnHxHhL95Oec3mEKvyAP8IBtH2t6zV2YjjJQk9A75KroMONpFH/BKPM55jQX1qXgXA rFJ2w3CAhYMGZ+IdHKyGHomjjk4C54setO4QihVaBmMRDs2VxmIpQ9OBMIsrIF1A6Eqe sqBxsKiACRq7+P7zOrlgx5b4wBNnD2Lbf26+kMn9fKfwtKY4i60Lrj1VMrqJXZ3qTT6T 5QbWKs6nMSpPNGsnH9PwnXoucuycBZiScgUNDzy65iGMUUhVkT8uHDIrto5d+67OrpsQ jRUA== MIME-Version: 1.0 X-Received: by 10.140.33.198 with SMTP id j64mr12020124qgj.14.1392383448796; Fri, 14 Feb 2014 05:10:48 -0800 (PST) Sender: jakub.php@gmail.com Received: by 10.224.68.68 with HTTP; Fri, 14 Feb 2014 05:10:48 -0800 (PST) In-Reply-To: References: Date: Fri, 14 Feb 2014 13:10:48 +0000 X-Google-Sender-Auth: 4xVYgLAL7sQx3dkyJUcauaAqBHw Message-ID: To: Andrey Andreev Cc: Pierre Joye , PHP internals Content-Type: multipart/alternative; boundary=001a1139b400db54f304f25d884f Subject: Re: [PHP-DEV] unify entropy source for all php related functions From: bukka@php.net (Jakub Zelenka) --001a1139b400db54f304f25d884f Content-Type: text/plain; charset=ISO-8859-1 On Fri, Feb 14, 2014 at 1:02 PM, Andrey Andreev wrote: > On Fri, Feb 14, 2014 at 2:26 PM, Pierre Joye wrote: > > > > On Feb 14, 2014 7:03 PM, "Andrey Andreev" wrote: > >> ALL sources > >> say that /dev/urandom is both widely used and considered safe for > >> cryptography. Only a select few mention that it could be a bit weaker > >> in specific cases, in theory. > > > > No urandom (and similar) are not crypto safe. Totally not. They are > however > > good enough for most usages but crypto safe related tasks like key > > generation and the likes. Any (good) paper mentions this. > > > > Cheers, > > Pierre > > So how does openssl_random_pseudo_bytes() work without blocking then? > > $ cat test.php > $crypto_strong = NULL; > $orandom = openssl_random_pseudo_bytes(32, $crypto_strong); > var_dump(bin2hex($orandom), $crypto_strong); > $mrandom = mcrypt_create_iv(32, MCRYPT_DEV_RANDOM); > var_dump($mrandom); > > $ php test.php > string(64) > "bc10fe2a302039bc0b1ff85b1da53d1b2dc73be515bc1ab9a4a1f8895da7357b" > bool(true) > (blocks) > > If it doesn't block, it obviously doesn't use (only) /dev/random, yet > it says that the output is crypto-safe. Or is that a bug? > OpenSSL uses their PRNG where /dev/urandom is used as a default source on Unix for seeding. See https://github.com/openssl/openssl/blob/master/e_os.h#L82 https://github.com/openssl/openssl/blob/master/crypto/rand/rand_unix.c#L246 and https://github.com/openssl/openssl/blob/master/crypto/rand/md_rand.c for PRNG implementation I think that they are considering the source strong enough for seeding but you can still add entropy if you want to. I have covered the complete OpenSSL API in my crypto ext. See the readme in https://github.com/bukka/php-crypto for more details (scroll down to see the the API for Crypto\Rand class) Regards Jakub --001a1139b400db54f304f25d884f--