Sfoglia il codice sorgente

Cryptographically secure random integer generation

Andy 7 anni fa
parent
commit
e3c3ef538e
3 ha cambiato i file con 4 aggiunte e 4 eliminazioni
  1. 1 1
      class/deliver/Deliver.class.php
  2. 1 1
      functions/global.php
  3. 2 2
      functions/strings.php

+ 1 - 1
class/deliver/Deliver.class.php

@@ -1080,7 +1080,7 @@ class Deliver {
         if ( !isset( $mimeBoundaryString ) ||
             $mimeBoundaryString == '') {
             $mimeBoundaryString = '----=_' . date( 'YmdHis' ) . '_' .
-            mt_rand( 10000, 99999 );
+            random_int( 10000, 99999 );
         }
         return $mimeBoundaryString;
     }

+ 1 - 1
functions/global.php

@@ -650,7 +650,7 @@ if (!function_exists('session_regenerate_id')) {
     function php_combined_lcg() {
         $tv = gettimeofday();
         $lcg['s1'] = $tv['sec'] ^ (~$tv['usec']);
-        $lcg['s2'] = mt_rand();
+        $lcg['s2'] = random_int();
         $q = (int) ($lcg['s1'] / 53668);
         $lcg['s1'] = (int) (40014 * ($lcg['s1'] - 53668 * $q) - 12211 * $q);
         if ($lcg['s1'] < 0) {

+ 2 - 2
functions/strings.php

@@ -648,7 +648,7 @@ function OneTimePadDecrypt ($string, $epad) {
 function OneTimePadCreate ($length=100) {
     $pad = '';
     for ($i = 0; $i < $length; $i++) {
-        $pad .= chr(mt_rand(0,255));
+        $pad .= chr(random_int(0,255));
     }
 
     return base64_encode($pad);
@@ -717,7 +717,7 @@ function GenerateRandomString($size, $chars, $flags = 0) {
     $String = '';
     $j = strlen( $chars ) - 1;
     while (strlen($String) < $size) {
-        $String .= $chars{mt_rand(0, $j)};
+        $String .= $chars{random_int(0, $j)};
     }
 
     return $String;