| 44 | 44 | /** |
| 45 | 45 | * PHP 5.2.0 - 5.6.x way to implement random_bytes() |
| 46 | 46 | * |
| 47 | 47 | * We use conditional statements here to define the function in accordance |
| 48 | 48 | * to the operating environment. It's a micro-optimization. |
| 49 | 49 | * |
| 50 | 50 | * In order of preference: |
| 51 | 51 | * 1. Use libsodium if available. |
| 52 | 52 | * 2. fread() /dev/urandom if available (never on Windows) |
| 53 | 53 | * 3. mcrypt_create_iv($bytes, MCRYPT_CREATE_IV) |
| 54 | 54 | * 4. COM('CAPICOM.Utilities.1')->GetRandom() |
| 55 | 55 | * 5. openssl_random_pseudo_bytes() (absolute last resort) |
| 56 | 56 | * |
| 57 | 57 | * See ERRATA.md for our reasoning behind this particular order |
| 58 | 58 | */ |
| 60 | 60 | // See random_bytes_libsodium.php |
| 61 | 61 | require_once $RandomCompatDIR.'/random_bytes_libsodium.php'; |
| 62 | 62 | } |
| 63 | 63 | if ( |
| 64 | 64 | !function_exists('random_bytes') && |
| 65 | 65 | DIRECTORY_SEPARATOR === '/' && |
| 66 | 66 | @is_readable('/dev/urandom') |
| 67 | 67 | ) { |
| 68 | 68 | // DIRECTORY_SEPARATOR === '/' on Unix-like OSes -- this is a fast |
| 69 | 69 | // way to exclude Windows. |
| 70 | 70 | // |
| 71 | 71 | // Error suppression on is_readable() in case of an open_basedir or |
| 72 | 72 | // safe_mode failure. All we care about is whether or not we can |
| 73 | 73 | // read it at this point. If the PHP environment is going to panic |
| 74 | 74 | // over trying to see if the file can be read in the first place, |