--- 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;
}