phpseclib/phpseclib/Crypt/Random.php
Jim Wigginton df0fe2386a - added SSH2.php and HMAC.php
- fixed issue with the IV's in TripleDES.php and DES.php
- fixed decryption in TripleDES.php using CRYPT_DES_MODE_INTERNAL
- renamed CRYPT_DES_MODE_SSH to CRYPT_DES_MODE_3CBC
- added CRYPT_DES_MODE_CBC3 as an alias for CRYPT_DES_MODE_CBC
- fixed issue with RC4.php using CRYPT_RC4_MODE_MCRYPT


git-svn-id: http://phpseclib.svn.sourceforge.net/svnroot/phpseclib/trunk@4 21d32557-59b3-4da0-833f-c5933fad653e
2007-07-23 05:21:39 +00:00

69 lines
2.1 KiB
PHP

<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Random Number Generator
*
* PHP versions 4 and 5
*
* Here's a short example of how to use this library:
* <code>
* <?php
* include('Crypt/Random.php');
*
* echo crypt_random();
* ?>
* </code>
*
* LICENSE: This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* @category Crypt
* @package Crypt_Random
* @author Jim Wigginton <terrafrost@php.net>
* @copyright MMVII Jim Wigginton
* @license http://www.gnu.org/licenses/lgpl.txt
* @version $Id: Random.php,v 1.2 2007-07-23 05:21:39 terrafrost Exp $
* @link http://pear.php.net/package/Crypt_Random
*/
/**
* Generate a random value. Feel free to replace this function with a cryptographically secure PRNG.
*
* @param optional Integer $min
* @param optional Integer $max
* @param optional String $randomness_path
* @return Integer
* @access public
*/
function crypt_random($min = 0, $max = 0x7FFFFFFF, $randomness_path = '/dev/urandom')
{
static $seeded = false;
if (!$seeded) {
$seeded = true;
if (file_exists($randomness_path)) {
$fp = fopen($randomness_path, 'r');
mt_srand(pack('N', fread($fp, 4)));
fclose($fp);
} else {
list($sec, $usec) = explode(' ', microtime());
mt_srand((float) $sec + ((float) $usec * 100000));
}
}
return mt_rand($min, $max);
}
?>