- Timestamp:
- 11/08/2017 11:47:04 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/random_compat/random_bytes_mcrypt.php
r36886 r42130 5 5 * 6 6 * The MIT License (MIT) 7 * 8 * Copyright (c) 2015 Paragon Initiative Enterprises7 * 8 * Copyright (c) 2015 - 2017 Paragon Initiative Enterprises 9 9 * 10 10 * Permission is hereby granted, free of charge, to any person obtaining a copy … … 27 27 */ 28 28 29 if (!is_callable('random_bytes')) { 30 /** 31 * Powered by ext/mcrypt (and thankfully NOT libmcrypt) 32 * 33 * @ref https://bugs.php.net/bug.php?id=55169 34 * @ref https://github.com/php/php-src/blob/c568ffe5171d942161fc8dda066bce844bdef676/ext/mcrypt/mcrypt.c#L1321-L1386 35 * 36 * @param int $bytes 37 * 38 * @throws Exception 39 * 40 * @return string 41 */ 42 function random_bytes($bytes) 43 { 44 try { 45 $bytes = RandomCompat_intval($bytes); 46 } catch (TypeError $ex) { 47 throw new TypeError( 48 'random_bytes(): $bytes must be an integer' 49 ); 50 } 29 51 30 /** 31 * Powered by ext/mcrypt (and thankfully NOT libmcrypt) 32 * 33 * @ref https://bugs.php.net/bug.php?id=55169 34 * @ref https://github.com/php/php-src/blob/c568ffe5171d942161fc8dda066bce844bdef676/ext/mcrypt/mcrypt.c#L1321-L1386 35 * 36 * @param int $bytes 37 * 38 * @throws Exception 39 * 40 * @return string 41 */ 42 function random_bytes($bytes) 43 { 44 try { 45 $bytes = RandomCompat_intval($bytes); 46 } catch (TypeError $ex) { 47 throw new TypeError( 48 'random_bytes(): $bytes must be an integer' 52 if ($bytes < 1) { 53 throw new Error( 54 'Length must be greater than 0' 55 ); 56 } 57 58 $buf = @mcrypt_create_iv($bytes, MCRYPT_DEV_URANDOM); 59 if ( 60 $buf !== false 61 && 62 RandomCompat_strlen($buf) === $bytes 63 ) { 64 /** 65 * Return our random entropy buffer here: 66 */ 67 return $buf; 68 } 69 70 /** 71 * If we reach here, PHP has failed us. 72 */ 73 throw new Exception( 74 'Could not gather sufficient random data' 49 75 ); 50 76 } 51 52 if ($bytes < 1) {53 throw new Error(54 'Length must be greater than 0'55 );56 }57 58 $buf = @mcrypt_create_iv($bytes, MCRYPT_DEV_URANDOM);59 if (60 $buf !== false61 &&62 RandomCompat_strlen($buf) === $bytes63 ) {64 /**65 * Return our random entropy buffer here:66 */67 return $buf;68 }69 70 /**71 * If we reach here, PHP has failed us.72 */73 throw new Exception(74 'Could not gather sufficient random data'75 );76 77 }
Note: See TracChangeset
for help on using the changeset viewer.