Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118348 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 55982 invoked from network); 4 Aug 2022 16:33:16 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 4 Aug 2022 16:33:16 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 01DE91804AF for ; Thu, 4 Aug 2022 11:33:37 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS24940 176.9.0.0/16 X-Spam-Virus: No X-Envelope-From: Received: from chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 4 Aug 2022 11:33:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1659638014; bh=x+joSUfqjuL/3bSav3St91/m4fG6nPrDZVAuQNz0ots=; h=Date:Subject:To:References:From:In-Reply-To:From; b=as/5A7Yo4zev2nO3xMUGfMY8KC5ZIpxnuCk0E1vXZN7S4b6c/0ADgmKereatrcTe/ zoI6zwZU67YwbG3G6VROhhDMFqcNaVKAU+Nv0fqpNHaU4CanZXOQNrSUYgVnwmuRLr V8i7Uf9VbHpJsSTB4N1SURC5a8NsLbBM+acMAixAFTVIYIu8QTJdW8zx6653EwnlFg QxL4bch/vV6y2DIG1KcMMo/A7k7jW3lg3tRcX46E24tatVjI21qYLvKw24EK8jLwvL 8EQ+rTdA60MLAvD/RmDummQh++kZ0Bv8tGFSd3NplzSyfZgGlL+q23TPQvguIyuhRM BASkb0Yd+/+Rw== Message-ID: <67f9981b-de29-2f83-cecf-08ea3c1199ae@bastelstu.be> Date: Thu, 4 Aug 2022 20:33:34 +0200 MIME-Version: 1.0 Content-Language: en-US To: Anton Smirnov , PHP Internals List , Go Kudo References: <157e4f6b6e96376e61194b9a358c87b02880ec28.camel@sandfox.me> In-Reply-To: <157e4f6b6e96376e61194b9a358c87b02880ec28.camel@sandfox.me> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] xoshiro** edge case (all zeros) From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=c3=bcsterhus?=) Hi On 8/4/22 10:09, Anton Smirnov wrote: > xoshiro** has a known edge case: all-zero seed Indeed, good catch. I had that in mind, but forgot about it. > > $engine = new \Random\Engine\Xoshiro256StarStar(str_repeat("\0", 32)); > > while (true) { > echo hex2bin($engine->generate()), PHP_EOL; // 0000000000000000 > } > > It should be documented and/or handled > > It's only for a string seed, int seed is not affected > I've created a PR here: https://github.com/php/php-src/pull/9250 I've opted to throw a ValueError in that case, as that's the only safe option that does not introduce a bias. The 32xNUL seed basically should only happen for manually written testing input and not happen otherwise. An actual random seed will result in 32 NUL bytes with just a 2**-256 chance and when relying on the implicit CSPRNG seeding (`null` as seed parameter) my PR will just retry to catch even that edge case. Best regards Tim Düsterhus