Added mopre entropy collection before creating onte time pad.
authorgustavf <gustavf@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Wed, 27 Sep 2000 13:34:29 +0000 (13:34 +0000)
committergustavf <gustavf@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Wed, 27 Sep 2000 13:34:29 +0000 (13:34 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@764 7612ce4b-ef26-0410-bec9-ea0150e637f0

functions/strings.php

index 8a21485f7a55f81d351b899a5e1eb4737705bed1..d5cb78f0bff7662f9d2f62f7636a2cb55f47ea15 100644 (file)
    }
 
    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));