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üsterhus
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php