X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/dc1231b7312fbdca99e9e887cc2bb35a28f85cdc..03f2fa83c13c1b532284205fa7efcab9b8b2c41f:/wp-includes/random_compat/random.php diff --git a/wp-includes/random_compat/random.php b/wp-includes/random_compat/random.php new file mode 100644 index 00000000..d1f7555a --- /dev/null +++ b/wp-includes/random_compat/random.php @@ -0,0 +1,137 @@ +GetRandom() + * 5. openssl_random_pseudo_bytes() (absolute last resort) + * + * See ERRATA.md for our reasoning behind this particular order + */ + if (extension_loaded('libsodium')) { + // See random_bytes_libsodium.php + require_once $RandomCompatDIR.'/random_bytes_libsodium.php'; + } + if ( + !function_exists('random_bytes') && + DIRECTORY_SEPARATOR === '/' && + @is_readable('/dev/urandom') + ) { + // DIRECTORY_SEPARATOR === '/' on Unix-like OSes -- this is a fast + // way to exclude Windows. + // + // Error suppression on is_readable() in case of an open_basedir or + // safe_mode failure. All we care about is whether or not we can + // read it at this point. If the PHP environment is going to panic + // over trying to see if the file can be read in the first place, + // that is not helpful to us here. + + // See random_bytes_dev_urandom.php + require_once $RandomCompatDIR.'/random_bytes_dev_urandom.php'; + } + if ( + !function_exists('random_bytes') && + PHP_VERSION_ID >= 50307 && + extension_loaded('mcrypt') + ) { + // See random_bytes_mcrypt.php + require_once $RandomCompatDIR.'/random_bytes_mcrypt.php'; + } + if ( + !function_exists('random_bytes') && + extension_loaded('com_dotnet') && + class_exists('COM') + ) { + try { + $RandomCompatCOMtest = new COM('CAPICOM.Utilities.1'); + if (method_exists($RandomCompatCOMtest, 'GetRandom')) { + // See random_bytes_com_dotnet.php + require_once $RandomCompatDIR.'/random_bytes_com_dotnet.php'; + } + } catch (com_exception $e) { + // Don't try to use it. + } + $RandomCompatCOMtest = null; + } + if ( + !function_exists('random_bytes') && + extension_loaded('openssl') && + ( + // Unix-like with PHP >= 5.3.0 or + ( + DIRECTORY_SEPARATOR === '/' && + PHP_VERSION_ID >= 50300 + ) || + // Windows with PHP >= 5.4.1 + PHP_VERSION_ID >= 50401 + ) + ) { + // See random_bytes_openssl.php + require_once $RandomCompatDIR.'/random_bytes_openssl.php'; + } + if (!function_exists('random_bytes')) { + /** + * We don't have any more options, so let's throw an exception right now + * and hope the developer won't let it fail silently. + */ + function random_bytes() + { + throw new Exception( + 'There is no suitable CSPRNG installed on your system' + ); + } + } + } + if (!function_exists('random_int')) { + require_once $RandomCompatDIR.'/random_int.php'; + } + $RandomCompatDIR = null; +}