Changeset 35365 for trunk/src/wp-includes/random_compat/random.php
- Timestamp:
- 10/23/2015 04:21:01 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/random_compat/random.php
r34922 r35365 29 29 if (!defined('PHP_VERSION_ID')) { 30 30 // This constant was introduced in PHP 5.2.7 31 $version = explode('.', PHP_VERSION); 32 define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2])); 31 $RandomCompatversion = explode('.', PHP_VERSION); 32 define('PHP_VERSION_ID', ($RandomCompatversion[0] * 10000 + $RandomCompatversion[1] * 100 + $RandomCompatversion[2])); 33 unset($RandomCompatversion); 33 34 } 34 35 if (PHP_VERSION_ID < 70000) { … … 36 37 define('RANDOM_COMPAT_READ_BUFFER', 8); 37 38 } 38 require_once "byte_safe_strings.php"; 39 require_once "error_polyfill.php"; 39 $__DIR__ = dirname(__FILE__); 40 require_once $__DIR__.'/byte_safe_strings.php'; 41 require_once $__DIR__.'/cast_to_int.php'; 42 require_once $__DIR__.'/error_polyfill.php'; 40 43 if (!function_exists('random_bytes')) { 41 44 /** … … 46 49 * 47 50 * In order of preference: 48 * 1. fread() /dev/urandom if available 49 * 2. mcrypt_create_iv($bytes, MCRYPT_CREATE_IV) 50 * 3. COM('CAPICOM.Utilities.1')->GetRandom() 51 * 4. openssl_random_pseudo_bytes() 51 * 1. Use libsodium if available. 52 * 2. fread() /dev/urandom if available (never on Windows) 53 * 3. mcrypt_create_iv($bytes, MCRYPT_CREATE_IV) 54 * 4. COM('CAPICOM.Utilities.1')->GetRandom() 55 * 5. openssl_random_pseudo_bytes() (absolute last resort) 52 56 * 53 57 * See ERRATA.md for our reasoning behind this particular order 54 58 */ 55 if (!ini_get('open_basedir') && is_readable('/dev/urandom')) { 59 if (extension_loaded('libsodium')) { 60 // See random_bytes_libsodium.php 61 require_once $__DIR__.'/random_bytes_libsodium.php'; 62 } 63 if ( 64 !function_exists('random_bytes') && 65 DIRECTORY_SEPARATOR === '/' && 66 @is_readable('/dev/urandom') 67 ) { 68 // DIRECTORY_SEPARATOR === '/' on Unix-like OSes -- this is a fast 69 // way to exclude Windows. 70 // 71 // Error suppression on is_readable() in case of an open_basedir or 72 // safe_mode failure. All we care about is whether or not we can 73 // read it at this point. If the PHP environment is going to panic 74 // over trying to see if the file can be read in the first place, 75 // that is not helpful to us here. 76 56 77 // See random_bytes_dev_urandom.php 57 require_once "random_bytes_dev_urandom.php"; 58 } elseif (PHP_VERSION_ID >= 50307 && function_exists('mcrypt_create_iv')) { 78 require_once $__DIR__.'/random_bytes_dev_urandom.php'; 79 } 80 if ( 81 !function_exists('random_bytes') && 82 PHP_VERSION_ID >= 50307 && 83 extension_loaded('mcrypt') 84 ) { 59 85 // See random_bytes_mcrypt.php 60 require_once "random_bytes_mcrypt.php"; 61 } elseif (extension_loaded('com_dotnet')) { 62 // See random_bytes_com_dotnet.php 63 require_once "random_bytes_com_dotnet.php"; 64 } elseif (function_exists('openssl_random_pseudo_bytes')) { 86 require_once $__DIR__.'/random_bytes_mcrypt.php'; 87 } 88 if ( 89 !function_exists('random_bytes') && 90 extension_loaded('com_dotnet') && 91 class_exists('COM') 92 ) { 93 try { 94 $RandomCompatCOMtest = new COM('CAPICOM.Utilities.1'); 95 if (method_exists($RandomCompatCOMtest, 'GetRandom')) { 96 // See random_bytes_com_dotnet.php 97 require_once $__DIR__.'/random_bytes_com_dotnet.php'; 98 } 99 } catch (com_exception $e) { 100 // Don't try to use it. 101 } 102 unset($RandomCompatCOMtest); 103 } 104 if ( 105 !function_exists('random_bytes') && 106 extension_loaded('openssl') && 107 PHP_VERSION_ID >= 50300 108 ) { 65 109 // See random_bytes_openssl.php 66 require_once "random_bytes_openssl.php"; 67 } else { 110 require_once $__DIR__.'/random_bytes_openssl.php'; 111 } 112 if (!function_exists('random_bytes')) { 68 113 /** 69 114 * We don't have any more options, so let's throw an exception right now … … 79 124 } 80 125 if (!function_exists('random_int')) { 81 require_once "random_int.php";126 require_once $__DIR__.'/random_int.php'; 82 127 } 128 unset($__DIR__); 83 129 }
Note: See TracChangeset
for help on using the changeset viewer.