Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:100237 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 78136 invoked from network); 16 Aug 2017 21:42:10 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Aug 2017 21:42:10 -0000 Authentication-Results: pb1.pair.com header.from=solar@openwall.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=solar@openwall.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain openwall.com designates 195.42.179.200 as permitted sender) X-PHP-List-Original-Sender: solar@openwall.com X-Host-Fingerprint: 195.42.179.200 mother.openwall.net Received: from [195.42.179.200] ([195.42.179.200:60858] helo=mother.openwall.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 68/E8-34801-13CB4995 for ; Wed, 16 Aug 2017 17:42:10 -0400 Received: (qmail 32301 invoked from network); 16 Aug 2017 21:42:06 -0000 Received: from localhost (HELO pvt.openwall.com) (127.0.0.1) by localhost with SMTP; 16 Aug 2017 21:42:06 -0000 Received: by pvt.openwall.com (Postfix, from userid 503) id 69478AB18D; Wed, 16 Aug 2017 23:41:55 +0200 (CEST) Date: Wed, 16 Aug 2017 23:41:55 +0200 To: Nikita Popov Cc: Leigh , PHP internals Message-ID: <20170816214155.GA12831@openwall.com> References: <20170816191247.GA12324@openwall.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i Subject: Re: [PHP-DEV] PHP 7.1.0 to 7.2.0beta2 mt_rand() modulo bias bug From: solar@openwall.com (Solar Designer) On Wed, Aug 16, 2017 at 10:06:02PM +0200, Nikita Popov wrote: > I'd suggest to split the 32-bit and 64-bit code codepaths entirely, as the > interleaved #ifs are somewhat hard to follow. Something like > https://gist.github.com/nikic/64e7ec58ebb6121d350fb80927a65082 (not > thoroughly tested). This looks good to me - especially how you reduced the nesting of if's by special-casing the "Powers of two are not biased" return. With this change, you can as well drop the "Special case where no modulus is required", as it'd happen to be handled the same by your new return. OTOH, that optimization might require an extra comment on its own. Here's what this might look like (totally untested): https://gist.github.com/solardiz/5e3d313bbee2c1ce6e200e433b750bef Alexander