Prechádzať zdrojové kódy

Added mopre entropy collection before creating onte time pad.

gustavf 25 rokov pred
rodič
commit
7f2b62ea70
1 zmenil súbory, kde vykonal 19 pridanie a 1 odobranie
  1. 19 1
      functions/strings.php

+ 19 - 1
functions/strings.php

@@ -256,7 +256,25 @@
    }
 
    function OneTimePadCreate ($length=100) {
-      srand ((double) microtime() * 1000000);
+      global $REMOTE_PORT, $REMOTE_IP, $UNIQUE_ID;
+
+      // Entropy gathering
+      if (function_exists("crc32")) {
+	 $seed1 = (double) microtime() * 1000000;
+	 $seed2 = md5($REMOTE_PORT . $REMOTE_IP . $UNIQUE_ID);
+	 if (function_exists("getrusage")) {
+	    $dat = getrusage();
+	    $seed3 = md5($dat["ru_nswap"].$dat["ru_majflt"].$dat["ru_utime.tv_sec"].$dat["ru_utime.tv_usec"].getmypid());
+	 } else {
+	    $seed3 = getmypid();
+	 }
+
+	 $seed = crc32($seed1)*1000000 + crc32($seed2)*10000 + crc32($seed3);
+      } else {
+	 $seed = (double) microtime() * 1000000;
+      }
+
+      srand ($seed);
       
       for ($i = 0; $i < $length; $i++) {
 	 $pad .= chr(rand(0,255));