includes/rijndael.php
changeset 801 eb8b23f11744
parent 613 c08670a77871
child 832 7152ca0a0ce9
--- a/includes/rijndael.php	Sat Jan 03 18:11:18 2009 -0500
+++ b/includes/rijndael.php	Sun Jan 04 00:55:40 2009 -0500
@@ -1658,25 +1658,30 @@
    * @return string a BINARY key
    */
   
-  function randkey($len = 32)
+  static function randkey($len = 32)
+  {
+    if ( @file_exists('/dev/urandom') && @is_readable('/dev/urandom') )
+    {
+      // Let's use something a little more secure
+      $ur = @fopen('/dev/urandom', 'r');
+      if ( !$ur )
+        return self::randkey_safe($len);
+      $ukey = @fread($ur, $len);
+      fclose($ur);
+      if ( strlen($ukey) != $len )
+        return self::randkey_safe($len);
+      return $ukey;
+    }
+    return self::randkey_safe($len);
+  }
+  
+  static function randkey_safe($len = 32)
   {
     $key = '';
     for($i=0;$i<$len;$i++)
     {
       $key .= chr(mt_rand(0, 255));
     }
-    if ( @file_exists('/dev/urandom') && @is_readable('/dev/urandom') )
-    {
-      // Let's use something a little more secure
-      $ur = @fopen('/dev/urandom', 'r');
-      if ( !$ur )
-        return $key;
-      $ukey = @fread($ur, $len);
-      fclose($ur);
-      if ( strlen($ukey) != $len )
-        return $key;
-      return $ukey;
-    }
     return $key;
   }