rfc:rng_fixes

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
rfc:rng_fixes [2016/06/14 14:58] leighrfc:rng_fixes [2016/07/07 10:24] leigh
Line 19: Line 19:
 ===== Proposal ===== ===== Proposal =====
  
-There are several proposals up for discussion that I hope to fine-tune, improve upon or eliminate completely during the discussion phaseThe proposals are:+There are several proposals up for discussion.
  
-  * Replace mt_rand() and rand() to a strongmodern RNG. +  * Fix the current mt_rand() implementationwith the legacy implementation still available.
-  * Alternatively, fix the current mt_rand() implementation.+
   * Alias rand() to mt_rand().   * Alias rand() to mt_rand().
   * Fix RAND_RANGE for large ranges.   * Fix RAND_RANGE for large ranges.
   * Replace insecure uses of php_rand() with php_random_bytes()   * Replace insecure uses of php_rand() with php_random_bytes()
   * Make array_rand() more efficient   * Make array_rand() more efficient
- 
-== Replace mt_rand() and rand() to a strong, modern RNG. == 
-Most of the identified issues can be addressed by replacing the implementations of <php>mt_rand()</php> and <php>rand()</php> with a more modern random number generator such as ([[http://xoroshiro.di.unimi.it/|Xoroshiro128+]]) or ([[http://www.pcg-random.org/|PCG]]) 
- 
-As we currently recommend using <php>mt_rand()</php> over <php>rand()</php> it doesn't make sense to only replace the implementation of <php>rand()</php> with a stronger RNG. 
- 
-This change would alter the output streams of both functions, however it fixes: 
- 
-  * Incorrect implementation of <php>mt_rand()</php> (with documentation to say it is no longer <php>mt_rand()</php>) 
-  * Platform-specific outputs 
-  * Poor scaling of bounded outputs 
  
 == Fix mt_rand() implementation == == Fix mt_rand() implementation ==
 The implementation of <php>mt_rand()</php> in PHP contains a typo that makes it generate a different sequence of numbers to the original mt19937 implementation. [[https://bugs.php.net/bug.php?id=71152|See bug #71152]] The implementation of <php>mt_rand()</php> in PHP contains a typo that makes it generate a different sequence of numbers to the original mt19937 implementation. [[https://bugs.php.net/bug.php?id=71152|See bug #71152]]
  
-It is not known if the period or the quality of the output from the RNG is negatively affected due to this typo.+[[https://gist.github.com/tom--/a12175047578b3ae9ef8|Statistical analysis]] suggests that the quality of the output is unaffected.
  
 As <php>mt_rand()</php> can be seeded for repeatable sequences the current implementation makes it incompatible with other systems that do use correct implementations. However fixing it also means that the sequence generated for a given seed in PHP will also now be different. As <php>mt_rand()</php> can be seeded for repeatable sequences the current implementation makes it incompatible with other systems that do use correct implementations. However fixing it also means that the sequence generated for a given seed in PHP will also now be different.
 +
 +The legacy implementation will be preserved and be selectable with a new `mt_rand_mode(int $mode)` function, along with new constants representing the two modes.
  
 == Alias rand() to mt_rand() == == Alias rand() to mt_rand() ==
Line 61: Line 51:
   * <php>crypt()</php> salt generation   * <php>crypt()</php> salt generation
   * SOAP HTTP auth nonce generation   * SOAP HTTP auth nonce generation
-  * <php>mcrypt_create_iv()</php> fallback with invalid source. 
  
 These instances should all be fixed to use the secure random number generator (even mcrypt which is deprecated) These instances should all be fixed to use the secure random number generator (even mcrypt which is deprecated)
Line 77: Line 66:
   * <php>str_shuffle()</php>   * <php>str_shuffle()</php>
   * <php>crypt()</php>   * <php>crypt()</php>
-  * <php>mcrypt_create_iv()</php> 
  
 ===== Proposed PHP Version(s) ===== ===== Proposed PHP Version(s) =====
Line 93: Line 81:
  
 ==== New Constants ==== ==== New Constants ====
-None+MT_RAND_MT19937 (correct implementation mode) 
 +MT_RAND_PHP (unofficial implementation mode)
  
 ===== Open Issues ===== ===== Open Issues =====
Line 99: Line 88:
  
 ===== Proposed Voting Choices ===== ===== Proposed Voting Choices =====
-This will be an all or nothing vote (after discussion), and as the changes are functional, will require a 50%+1 majority to pass.+Individual votes will be held for the remaining proposals, and since minor BC breaks are introduced they will require a 2/3 majority to pass.
  
 ===== Patches and Tests ===== ===== Patches and Tests =====
-WIP - I will release a patch after a week or so of discussion has taken place when there is a better idea of which proposals are wanted.+https://github.com/php/php-src/pull/1986
  
 ===== Implementation ===== ===== Implementation =====
 +
  
 ===== References ===== ===== References =====
rfc/rng_fixes.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1