diff options
author | James Walker <walkah@walkah.net> | 2010-03-12 19:34:24 -0500 |
---|---|---|
committer | James Walker <walkah@walkah.net> | 2010-03-12 19:34:24 -0500 |
commit | 41d2ff662c7783f4aa0341b9b542ff157d01593c (patch) | |
tree | f59c21d76fbdb56fcb3ab530d0c5b70b1f75f872 /plugins/OStatus/extlib/Crypt/Random.php | |
parent | 114f046691282ef96a7e5795082f97bd9c41ab97 (diff) |
Adding Crypt library from http://phpseclib.sourceforge.net/
Diffstat (limited to 'plugins/OStatus/extlib/Crypt/Random.php')
-rw-r--r-- | plugins/OStatus/extlib/Crypt/Random.php | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/plugins/OStatus/extlib/Crypt/Random.php b/plugins/OStatus/extlib/Crypt/Random.php new file mode 100644 index 000000000..fbb41074e --- /dev/null +++ b/plugins/OStatus/extlib/Crypt/Random.php @@ -0,0 +1,70 @@ +<?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.4 2008/05/21 05:15:32 terrafrost Exp $
+ * @link http://phpseclib.sourceforge.net
+ */
+
+/**
+ * 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');
+ $temp = unpack('Nint', fread($fp, 4));
+ mt_srand($temp['int']);
+ fclose($fp);
+ } else {
+ list($sec, $usec) = explode(' ', microtime());
+ mt_srand((float) $sec + ((float) $usec * 100000));
+ }
+ }
+
+ return mt_rand($min, $max);
+}
+?>
\ No newline at end of file |