X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Flibs%2FCryptRand.php;h=0d3613ae230c4d493093bb2f929f2fcf2ff47e56;hp=10088f2363a5e76cc8c3621c48aea9bffd888b3d;hb=49748181dd56ec97e7ba7c13e684a16abceb3cc0;hpb=81087198c24d881fb697c2e79b058c25c534eb5e diff --git a/includes/libs/CryptRand.php b/includes/libs/CryptRand.php index 10088f2363..0d3613ae23 100644 --- a/includes/libs/CryptRand.php +++ b/includes/libs/CryptRand.php @@ -242,6 +242,21 @@ class CryptRand { $this->strong = true; } + if ( strlen( $buffer ) < $bytes ) { + // If available make use of PHP 7's random_bytes + // On Linux, getrandom syscall will be used if available. + // On Windows CryptGenRandom will always be used + // On other platforms, /dev/urandom will be used. + // All error situations will throw Exceptions and or Errors + if ( function_exists( 'random_bytes' ) ) { + $rem = $bytes - strlen( $buffer ); + $buffer .= random_bytes( $rem ); + } + if ( strlen( $buffer ) >= $bytes ) { + $this->strong = true; + } + } + if ( strlen( $buffer ) < $bytes ) { // If available make use of mcrypt_create_iv URANDOM source to generate randomness // On unix-like systems this reads from /dev/urandom but does it without any buffering