From: gustavf Date: Wed, 27 Sep 2000 13:34:29 +0000 (+0000) Subject: Added mopre entropy collection before creating onte time pad. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=580e17932dfc086808628d350f3cb66707de8d4a;p=squirrelmail.git Added mopre entropy collection before creating onte time pad. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@764 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- diff --git a/functions/strings.php b/functions/strings.php index 8a21485f..d5cb78f0 100644 --- a/functions/strings.php +++ b/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));