Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117028 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 80229 invoked from network); 14 Feb 2022 13:36:22 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 14 Feb 2022 13:36:22 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D02D9180382 for ; Mon, 14 Feb 2022 06:53:48 -0800 (PST) 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,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-yb1-f177.google.com (mail-yb1-f177.google.com [209.85.219.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 14 Feb 2022 06:53:48 -0800 (PST) Received: by mail-yb1-f177.google.com with SMTP id p19so46800574ybc.6 for ; Mon, 14 Feb 2022 06:53:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=colopl.co.jp; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=7C9rsu7Ht8iDZHpAAf3nvx84FM0RbQcl6oY1MBO65LM=; b=Ur+VlXGZ47jvuH4uOB2ThsvvQuqlIcfQv4W7xfrmDGkNBuWAUW06J9rmBi1IcJYFCK j4xpv9xxVxs4bwYFDCcRwz+LJpkC8/Kw6j2pnMrFrJ73/IplTyzihGHZYJeCJLa9pGhC 9lTJZ8t321NZ6ul947OwoB/8nPr/py7TV4Rx+ipEkBQA+HJu+sLXXnq9rqNWxmvCCax0 gdcTWHRyJfh0YBgL3buRAQ3O/q/7VGUBHOIwVgpUE2WxtNHlfuzglW/l9ucYgBwcWrEl Vox2EPmLh9+qUuuSbd1Udxy5v+2TaAccWynNW+CNAg59x5VOAvwEB7k3Hopnt6Dwqet6 nyIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=7C9rsu7Ht8iDZHpAAf3nvx84FM0RbQcl6oY1MBO65LM=; b=F71vqDC9GwhC0+KBxKYIXKc6br+3nck/zskpZ/1Jx1eaexWYSxYTFvzUmlBqowB6WW zFRDw8MWO8DPnOHoI5uR1YjJP9Qh1oEfG019y2smGtBmczTI5Kq5HnfAy3K5zLMgvxcI ZQv3n2GwyE44vpkZy2z+7DRspqzbbwkH+lMfc61Qgj+axkjEmKTcWiGKk6R+wnSIWtFx uo6vgjSSGQBQLi0LyQPNJ+2+LT6BppNvahixy3R+MWaVVswztbJtD0wI58oZKLovkeh4 ovIJXdFTRoKhdLLKANJMSWrkLttb5d5RjxsvuiDEALP/n5ylvnDW+NB3XAIMYBAA90Lv GqrQ== X-Gm-Message-State: AOAM532R2uop9sjKUhd4hHcSAv5gsQ+RUN5qi5KTxRVZY1iFpALMbfLM jbg72CDZPfpAqHf1WuzAPO/Im2pzcboDQqg19xUw X-Google-Smtp-Source: ABdhPJzGgIq5Yr28M8qYpg6ELa9fWlJw3rcBvzrY4e8fniMza1bWVg9iUp9fnUVfxR1d/74139Dbw7UsVXv1xQNXISY= X-Received: by 2002:a81:2084:: with SMTP id g126mr14573555ywg.85.1644850427353; Mon, 14 Feb 2022 06:53:47 -0800 (PST) MIME-Version: 1.0 References: <41a1b458-4941-f34e-f1b4-e25b3298b80a@bastelstu.be> In-Reply-To: <41a1b458-4941-f34e-f1b4-e25b3298b80a@bastelstu.be> Date: Mon, 14 Feb 2022 23:53:36 +0900 Message-ID: To: =?UTF-8?Q?Tim_D=C3=BCsterhus?= Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="0000000000006e6edd05d7fb95ae" Subject: Re: [PHP-DEV] [RFC] [Under Discussion] Random Extension 4.0 From: g-kudo@colopl.co.jp (Go Kudo) --0000000000006e6edd05d7fb95ae Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 2022=E5=B9=B42=E6=9C=8814=E6=97=A5(=E6=9C=88) 20:40 Tim D=C3=BCsterhus : > Hi > > On 2/14/22 12:11, Go Kudo wrote: > > The refreshed RFC and implementation are available at the following URL= : > > > > https://wiki.php.net/rfc/rng_extension > > https://github.com/php/php-src/pull/8094 > > > > If there are no specific comments, I would like to start voting as soon > as > > the two-week pre-announcement phase is over. > > 1) XorShift128+ has a 128 Bit internal state, but takes an integer seed > within the constructor. Thus only 64 Bits of seed can be provided. > > Maybe the seed parameter should be a 16-byte string instead? > Initializing the generator with a completely random seed would then be: > > new XorShift128Plus(\random_bytes(16)); > > instead of the much more complicated: > > new XorShift128Plus(\random_int(\PHP_INT_MIN, \PHP_INT_MAX)); > > Perhaps the following API would be even clearer: > > XorShift128Plus::fromSeed(\random_bytes(16)); > XorShift128Plus::fromGenerator(new Secure()); // Takes 16 bytes from the > given generator. > > 2) I would adjust the 'Randomizer' to use the 'Secure' generator as a > safe default. If absolute performance or a reproducible sequence is > required then one can use a custom generator, but the default will be > the secure CSPRNG, making it harder to misuse. > > 3) The RFC is inconsistent in the example code. Is it 'stringShuffle' or > 'shuffleString'? > > 4) The RFC should document the 'NumberGenerator' interface. Specifically > I'm interested in the return type of the 'generate' method. Does it > return bytes or integers? Is it legal to implement the interface in > userland code? > > Best regards > Tim D=C3=BCsterhus > Hi > 1) XorShift128+ has a 128 Bit internal state, but takes an integer seed within the constructor. Thus only 64 Bits of seed can be provided. This is for convenience. Other software that uses XorShift128+, such as Chromium (V8), also uses a 64-bit value for the initial seed value. I think that 128-bit value seeding with strings is unintuitive and not very good for performance. https://chromium.googlesource.com/v8/v8/+/refs/heads/main/src/base/utils/ra= ndom-number-generator.h > 2) I would adjust the 'Randomizer' to use the 'Secure' generator as a safe default. If absolute performance or a reproducible sequence is required then one can use a custom generator, but the default will be the secure CSPRNG, making it harder to misuse. Certainly, this may be appropriate. But, in this case, the Randomizer generated with the default parameters will not be serializable. Is that acceptable? Personally, I think this is a good change. > 3) The RFC is inconsistent in the example code. Is it 'stringShuffle' or 'shuffleString'? RFC Fixed :) > 4) The RFC should document the 'NumberGenerator' interface. Specifically I'm interested in the return type of the 'generate' method. Does it return bytes or integers? Is it legal to implement the interface in userland code? It returns an int. Also, as pointed out in GH, the generated value is implicitly treated as the size equivalent of PHP_INT_SIZE (zend_long) on the environment. This means that it is not possible to implement the userland Mersenne twister (32-bit) in a 64-bit environment. https://github.com/php/php-src/pull/8094#pullrequestreview-881660425 --0000000000006e6edd05d7fb95ae--