3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Random_* Compatibility Library * for using the new PHP 7 random_* API in PHP 5 projects * * The MIT License (MIT) * * Copyright (c) 2015 Paragon Initiative Enterprises * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ if (!defined('RANDOM_COMPAT_READ_BUFFER')) { define('RANDOM_COMPAT_READ_BUFFER', 8); } if (!function_exists('random_bytes')) { /** * PHP 5.2.0 - 5.6.x way to implement random_bytes() * * We use conditional statements here to define the function in accordance * to the operating environment. It's a micro-optimization. * * In order of preference: * 1. fread() /dev/urandom if available * 2. mcrypt_create_iv($bytes, MCRYPT_CREATE_IV) * 3. COM('CAPICOM.Utilities.1')->GetRandom() * 4. openssl_random_pseudo_bytes() * * See ERRATA.md for our reasoning behind this particular order */ if (!ini_get('open_basedir') && is_readable('/dev/urandom')) { /** * Unless open_basedir is enabled, use /dev/urandom for * random numbers in accordance with best practices * * Why we use /dev/urandom and not /dev/random * @ref http://sockpuppet.org/blog/2014/02/25/safely-generate-random-numbers * * @param int $bytes * * @throws Exception * * @return string */ function random_bytes($bytes) { static $fp = null; /** * This block should only be run once */ if (empty($fp)) { /** * We use /dev/urandom if it is a char device. * We never fall back to /dev/random */ $fp = fopen('/dev/urandom', 'rb'); if (!empty($fp)) { $st = fstat($fp); if (($st['mode'] & 020000) === 0) { fclose($fp); $fp = false; } } /** * stream_set_read_buffer() does not exist in HHVM * * If we don't set the stream's read buffer to 0, PHP will * internally buffer 8192 bytes, which can waste entropy * * stream_set_read_buffer returns 0 on success */ if (!empty($fp) && function_exists('stream_set_read_buffer')) { stream_set_read_buffer($fp, RANDOM_COMPAT_READ_BUFFER); } } /** * This if() block only runs if we managed to open a file handle * * It does not belong in an else {} block, because the above * if (empty($fp)) line is logic that should only be run once per * page load. */ if (!empty($fp)) { $remaining = $bytes; $buf = ''; /** * We use fread() in a loop to protect against partial reads */ do { $read = fread($fp, $remaining); if ($read === false) { /** * We cannot safely read from the file. Exit the * do-while loop and trigger the exception condition */ $buf = false; break; } /** * Decrease the number of bytes returned from remaining */ $remaining -= RandomCompat_strlen($read); $buf .= $read; } while ($remaining > 0); /** * Is our result valid? */ if ($buf !== false) { if (RandomCompat_strlen($buf) === $bytes) { /** * Return our random entropy buffer here: */ return $buf; } } } /** * If we reach here, PHP has failed us. */ throw new Exception( 'PHP failed to generate random data.' ); } } elseif (function_exists('mcrypt_create_iv') && version_compare(PHP_VERSION, '5.3.7') >= 0) { /** * Powered by ext/mcrypt (and thankfully NOT libmcrypt) * * @ref https://bugs.php.net/bug.php?id=55169 * @ref https://github.com/php/php-src/blob/c568ffe5171d942161fc8dda066bce844bdef676/ext/mcrypt/mcrypt.c#L1321-L1386 * * @param int $bytes * * @throws Exception * * @return string */ function random_bytes($bytes) { if (!is_int($bytes)) { throw new Exception( 'Length must be an integer' ); } if ($bytes < 1) { throw new Exception( 'Length must be greater than 0' ); } $buf = mcrypt_create_iv($bytes, MCRYPT_DEV_URANDOM); if ($buf !== false) { if (RandomCompat_strlen($buf) === $bytes) { /** * Return our random entropy buffer here: */ return $buf; } } /** * If we reach here, PHP has failed us. */ throw new Exception( 'PHP failed to generate random data.' ); } } elseif (extension_loaded('com_dotnet')) { /** * Windows with PHP < 5.3.0 will not have the function * openssl_random_pseudo_bytes() available, so let's use * CAPICOM to work around this deficiency. * * @param int $bytes * * @throws Exception * * @return string */ function random_bytes($bytes) { $buf = ''; $util = new COM('CAPICOM.Utilities.1'); $execCount = 0; /** * Let's not let it loop forever. If we run N times and fail to * get N bytes of random data, then CAPICOM has failed us. */ do { $buf .= base64_decode($util->GetRandom($bytes, 0)); if (RandomCompat_strlen($buf) >= $bytes) { /** * Return our random entropy buffer here: */ return RandomCompat_substr($buf, 0, $bytes); } ++$execCount; } while ($execCount < $bytes); /** * If we reach here, PHP has failed us. */ throw new Exception( 'PHP failed to generate random data.' ); } } elseif (function_exists('openssl_random_pseudo_bytes')) { /** * Since openssl_random_pseudo_bytes() uses openssl's * RAND_pseudo_bytes() API, which has been marked as deprecated by the * OpenSSL team, this is our last resort before failure. * * @ref https://www.openssl.org/docs/crypto/RAND_bytes.html * * @param int $bytes * * @throws Exception * * @return string */ function random_bytes($bytes) { $secure = true; /** * $secure is passed by reference. If it's set to false, fail. Note * that this will only return false if this function fails to return * any data. * * @ref https://github.com/paragonie/random_compat/issues/6#issuecomment-119564973 */ $buf = openssl_random_pseudo_bytes($bytes, $secure); if ($buf !== false && $secure) { if (RandomCompat_strlen($buf) === $bytes) { return $buf; } } /** * If we reach here, PHP has failed us. */ throw new Exception( 'PHP failed to generate random data.' ); } } else { /** * 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. */ throw new Exception( 'There is no suitable CSPRNG installed on your system' ); } } if (!function_exists('random_int')) { /** * Fetch a random integer between $min and $max inclusive * * @param int $min * @param int $max * * @throws Exception * * @return int */ function random_int($min, $max) { /** * Type and input logic checks */ if (!is_int($min)) { throw new Exception( 'random_int(): $min must be an integer' ); } if (!is_int($max)) { throw new Exception( 'random_int(): $max must be an integer' ); } if ($min > $max) { throw new Exception( 'Minimum value must be less than or equal to the maximum value' ); } if ($max === $min) { return $min; } /** * Initialize variables to 0 * * We want to store: * $bytes => the number of random bytes we need * $mask => an integer bitmask (for use with the &) operator * so we can minimize the number of discards */ $attempts = $bits = $bytes = $mask = $valueShift = 0; /** * At this point, $range is a positive number greater than 0. It might * overflow, however, if $max - $min > PHP_INT_MAX. PHP will cast it to * a float and we will lose some precision. */ $range = $max - $min; /** * Test for integer overflow: */ if (!is_int($range)) { /** * Still safely calculate wider ranges. * Provided by @CodesInChaos, @oittaa * * @ref https://gist.github.com/CodesInChaos/03f9ea0b58e8b2b8d435 * * We use ~0 as a mask in this case because it generates all 1s * * @ref https://eval.in/400356 (32-bit) * @ref http://3v4l.org/XX9r5 (64-bit) */ $bytes = PHP_INT_SIZE; $mask = ~0; } else { /** * $bits is effectively ceil(log($range, 2)) without dealing with * type juggling */ while ($range > 0) { if ($bits % 8 === 0) { ++$bytes; } ++$bits; $range >>= 1; $mask = $mask << 1 | 1; } $valueShift = $min; } /** * Now that we have our parameters set up, let's begin generating * random integers until one falls between $min and $max */ do { /** * The rejection probability is at most 0.5, so this corresponds * to a failure probability of 2^-128 for a working RNG */ if ($attempts > 128) { throw new Exception( 'random_int: RNG is broken - too many rejections' ); } /** * Let's grab the necessary number of random bytes */ $randomByteString = random_bytes($bytes); if ($randomByteString === false) { throw new Exception( 'Random number generator failure' ); } /** * Let's turn $randomByteString into an integer * * This uses bitwise operators (<< and |) to build an integer * out of the values extracted from ord() * * Example: [9F] | [6D] | [32] | [0C] => * 159 + 27904 + 3276800 + 201326592 => * 204631455 */ $val = 0; for ($i = 0; $i < $bytes; ++$i) { $val |= ord($randomByteString[$i]) << ($i * 8); } /** * Apply mask */ $val &= $mask; $val += $valueShift; ++$attempts; /** * If $val overflows to a floating point number, * ... or is larger than $max, * ... or smaller than $int, * then try again. */ } while (!is_int($val) || $val > $max || $val < $min); return (int) $val; } } if (!function_exists('RandomCompat_strlen')) { if (function_exists('mb_strlen')) { /** * strlen() implementation that isn't brittle to mbstring.func_overload * * This version uses mb_strlen() in '8bit' mode to treat strings as raw * binary rather than UTF-8, ISO-8859-1, etc * * @param string $binary_string * * @throws InvalidArgumentException * * @return int */ function RandomCompat_strlen($binary_string) { if (!is_string($binary_string)) { throw new InvalidArgumentException( 'RandomCompat_strlen() expects a string' ); } return mb_strlen($binary_string, '8bit'); } } else { /** * strlen() implementation that isn't brittle to mbstring.func_overload * * This version just used the default strlen() * * @param string $binary_string * * @throws InvalidArgumentException * * @return int */ function RandomCompat_strlen($binary_string) { if (!is_string($binary_string)) { throw new InvalidArgumentException( 'RandomCompat_strlen() expects a string' ); } return strlen($binary_string); } } } if (!function_exists('RandomCompat_substr')) { if (function_exists('mb_substr')) { /** * substr() implementation that isn't brittle to mbstring.func_overload * * This version uses mb_substr() in '8bit' mode to treat strings as raw * binary rather than UTF-8, ISO-8859-1, etc * * @param string $binary_string * @param int $start * @param int $length (optional) * * @throws InvalidArgumentException * * @return string */ function RandomCompat_substr($binary_string, $start, $length = null) { if (!is_string($binary_string)) { throw new InvalidArgumentException( 'RandomCompat_substr(): First argument should be a string' ); } if (!is_int($start)) { throw new InvalidArgumentException( 'RandomCompat_substr(): Second argument should be an integer' ); } if ($length === null) { /** * mb_substr($str, 0, NULL, '8bit') returns an empty string on * PHP 5.3, so we have to find the length ourselves. */ $length = RandomCompat_strlen($length) - $start; } elseif (!is_int($length)) { throw new InvalidArgumentException( 'RandomCompat_substr(): Third argument should be an integer, or omitted' ); } return mb_substr($binary_string, $start, $length, '8bit'); } } else { /** * substr() implementation that isn't brittle to mbstring.func_overload * * This version just uses the default substr() * * @param string $binary_string * @param int $start * @param int $length (optional) * * @throws InvalidArgumentException * * @return string */ function RandomCompat_substr($binary_string, $start, $length = null) { if (!is_string($binary_string)) { throw new InvalidArgumentException( 'RandomCompat_substr(): First argument should be a string' ); } if (!is_int($start)) { throw new InvalidArgumentException( 'RandomCompat_substr(): Second argument should be an integer' ); } if ($length !== null) { if (!is_int($length)) { throw new InvalidArgumentException( 'RandomCompat_substr(): Third argument should be an integer, or omitted' ); } return substr($binary_string, $start, $length); } return substr($binary_string, $start); } } } var_dump([ random_int(-PHP_INT_MAX, PHP_INT_MAX), random_int(-2147483648, 2147483647) ]);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 53
Branch analysis from position: 12
2 jumps found. (Code = 46) Position 1 = 17, Position 2 = 21
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 24
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
2 jumps found. (Code = 43) Position 1 = 58, Position 2 = 59
Branch analysis from position: 58
2 jumps found. (Code = 43) Position 1 = 64, Position 2 = 71
Branch analysis from position: 64
2 jumps found. (Code = 43) Position 1 = 68, Position 2 = 70
Branch analysis from position: 68
1 jumps found. (Code = 42) Position 1 = 71
Branch analysis from position: 71
2 jumps found. (Code = 43) Position 1 = 76, Position 2 = 83
Branch analysis from position: 76
2 jumps found. (Code = 43) Position 1 = 80, Position 2 = 82
Branch analysis from position: 80
1 jumps found. (Code = 42) Position 1 = 83
Branch analysis from position: 83
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 82
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 83
Branch analysis from position: 70
2 jumps found. (Code = 43) Position 1 = 76, Position 2 = 83
Branch analysis from position: 76
Branch analysis from position: 83
Branch analysis from position: 71
Branch analysis from position: 59
Branch analysis from position: 24
2 jumps found. (Code = 46) Position 1 = 28, Position 2 = 34
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 37
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 43
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
Branch analysis from position: 43
2 jumps found. (Code = 43) Position 1 = 47, Position 2 = 49
Branch analysis from position: 47
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
Branch analysis from position: 49
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 34
Branch analysis from position: 21
Branch analysis from position: 53
Branch analysis from position: 7
filename:       /in/VJGCb
function name:  (null)
number of ops:  97
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   DEFINED                                          ~0      'RANDOM_COMPAT_READ_BUFFER'
          1        BOOL_NOT                                         ~1      ~0
          2      > JMPZ                                                     ~1, ->7
   30     3    >   INIT_FCALL                                               'define'
          4        SEND_VAL                                                 'RANDOM_COMPAT_READ_BUFFER'
          5        SEND_VAL                                                 8
          6        DO_ICALL                                                 
   33     7    >   INIT_FCALL                                               'function_exists'
          8        SEND_VAL                                                 'random_bytes'
          9        DO_ICALL                                         $3      
         10        BOOL_NOT                                         ~4      $3
         11      > JMPZ                                                     ~4, ->53
   48    12    >   INIT_FCALL                                               'ini_get'
         13        SEND_VAL                                                 'open_basedir'
         14        DO_ICALL                                         $5      
         15        BOOL_NOT                                         ~6      $5
         16      > JMPZ_EX                                          ~6      ~6, ->21
         17    >   INIT_FCALL                                               'is_readable'
         18        SEND_VAL                                                 '%2Fdev%2Furandom'
         19        DO_ICALL                                         $7      
         20        BOOL                                             ~6      $7
         21    > > JMPZ                                                     ~6, ->24
   62    22    >   DECLARE_FUNCTION                                         'random_bytes'
  141    23      > JMP                                                      ->53
  142    24    >   INIT_FCALL                                               'function_exists'
         25        SEND_VAL                                                 'mcrypt_create_iv'
         26        DO_ICALL                                         $8      
         27      > JMPZ_EX                                          ~9      $8, ->34
         28    >   INIT_FCALL                                               'version_compare'
         29        SEND_VAL                                                 '8.0.0'
         30        SEND_VAL                                                 '5.3.7'
         31        DO_ICALL                                         $10     
         32        IS_SMALLER_OR_EQUAL                              ~11     0, $10
         33        BOOL                                             ~9      ~11
         34    > > JMPZ                                                     ~9, ->37
  155    35    >   DECLARE_FUNCTION                                         'random_bytes'
  183    36      > JMP                                                      ->53
  184    37    >   INIT_FCALL                                               'extension_loaded'
         38        SEND_VAL                                                 'com_dotnet'
         39        DO_ICALL                                         $12     
         40      > JMPZ                                                     $12, ->43
  196    41    >   DECLARE_FUNCTION                                         'random_bytes'
  221    42      > JMP                                                      ->53
  222    43    >   INIT_FCALL                                               'function_exists'
         44        SEND_VAL                                                 'openssl_random_pseudo_bytes'
         45        DO_ICALL                                         $13     
         46      > JMPZ                                                     $13, ->49
  236    47    >   DECLARE_FUNCTION                                         'random_bytes'
  258    48      > JMP                                                      ->53
  264    49    >   NEW                                              $14     'Exception'
  265    50        SEND_VAL_EX                                              'There+is+no+suitable+CSPRNG+installed+on+your+system'
         51        DO_FCALL                                      0          
         52      > THROW                                         0          $14
  270    53    >   INIT_FCALL                                               'function_exists'
         54        SEND_VAL                                                 'random_int'
         55        DO_ICALL                                         $16     
         56        BOOL_NOT                                         ~17     $16
         57      > JMPZ                                                     ~17, ->59
  281    58    >   DECLARE_FUNCTION                                         'random_int'
  413    59    >   INIT_FCALL                                               'function_exists'
         60        SEND_VAL                                                 'RandomCompat_strlen'
         61        DO_ICALL                                         $18     
         62        BOOL_NOT                                         ~19     $18
         63      > JMPZ                                                     ~19, ->71
  414    64    >   INIT_FCALL                                               'function_exists'
         65        SEND_VAL                                                 'mb_strlen'
         66        DO_ICALL                                         $20     
         67      > JMPZ                                                     $20, ->70
  427    68    >   DECLARE_FUNCTION                                         'randomcompat_strlen'
  435    69      > JMP                                                      ->71
  448    70    >   DECLARE_FUNCTION                                         'randomcompat_strlen'
  460    71    >   INIT_FCALL                                               'function_exists'
         72        SEND_VAL                                                 'RandomCompat_substr'
         73        DO_ICALL                                         $21     
         74        BOOL_NOT                                         ~22     $21
         75      > JMPZ                                                     ~22, ->83
  461    76    >   INIT_FCALL                                               'function_exists'
         77        SEND_VAL                                                 'mb_substr'
         78        DO_ICALL                                         $23     
         79      > JMPZ                                                     $23, ->82
  476    80    >   DECLARE_FUNCTION                                         'randomcompat_substr'
  500    81      > JMP                                                      ->83
  515    82    >   DECLARE_FUNCTION                                         'randomcompat_substr'
  540    83    >   INIT_FCALL                                               'var_dump'
  541    84        INIT_FCALL                                               'random_int'
         85        SEND_VAL                                                 -9223372036854775807
         86        SEND_VAL                                                 9223372036854775807
         87        DO_ICALL                                         $24     
         88        INIT_ARRAY                                       ~25     $24
  542    89        INIT_FCALL                                               'random_int'
         90        SEND_VAL                                                 -2147483648
         91        SEND_VAL                                                 2147483647
         92        DO_ICALL                                         $26     
         93        ADD_ARRAY_ELEMENT                                ~25     $26
         94        SEND_VAL                                                 ~25
         95        DO_ICALL                                                 
  543    96      > RETURN                                                   1

Function %00random_bytes%2Fin%2FVJGCb%3A62%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 37
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 24
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 24
Branch analysis from position: 20
2 jumps found. (Code = 46) Position 1 = 27, Position 2 = 31
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 37
Branch analysis from position: 32
2 jumps found. (Code = 43) Position 1 = 40, Position 2 = 66
Branch analysis from position: 40
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 51
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 58
Branch analysis from position: 58
2 jumps found. (Code = 43) Position 1 = 60, Position 2 = 66
Branch analysis from position: 60
2 jumps found. (Code = 43) Position 1 = 65, Position 2 = 66
Branch analysis from position: 65
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 66
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 66
Branch analysis from position: 51
2 jumps found. (Code = 44) Position 1 = 58, Position 2 = 42
Branch analysis from position: 58
Branch analysis from position: 42
Branch analysis from position: 66
Branch analysis from position: 37
Branch analysis from position: 31
Branch analysis from position: 24
Branch analysis from position: 24
Branch analysis from position: 37
filename:       /in/VJGCb
function name:  random_bytes
number of ops:  71
compiled vars:  !0 = $bytes, !1 = $fp, !2 = $st, !3 = $remaining, !4 = $buf, !5 = $read
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   62     0  E >   RECV                                             !0      
   64     1        BIND_STATIC                                              !1
   68     2        ISSET_ISEMPTY_CV                                         !1
          3      > JMPZ                                                     ~6, ->37
   73     4    >   INIT_FCALL                                               'fopen'
          5        SEND_VAL                                                 '%2Fdev%2Furandom'
          6        SEND_VAL                                                 'rb'
          7        DO_ICALL                                         $7      
          8        ASSIGN                                                   !1, $7
   74     9        ISSET_ISEMPTY_CV                                 ~9      !1
         10        BOOL_NOT                                         ~10     ~9
         11      > JMPZ                                                     ~10, ->24
   75    12    >   INIT_FCALL                                               'fstat'
         13        SEND_VAR                                                 !1
         14        DO_ICALL                                         $11     
         15        ASSIGN                                                   !2, $11
   76    16        FETCH_DIM_R                                      ~13     !2, 'mode'
         17        BW_AND                                           ~14     ~13, 8192
         18        IS_IDENTICAL                                             ~14, 0
         19      > JMPZ                                                     ~15, ->24
   77    20    >   INIT_FCALL                                               'fclose'
         21        SEND_VAR                                                 !1
         22        DO_ICALL                                                 
   78    23        ASSIGN                                                   !1, <false>
   89    24    >   ISSET_ISEMPTY_CV                                 ~18     !1
         25        BOOL_NOT                                         ~19     ~18
         26      > JMPZ_EX                                          ~19     ~19, ->31
         27    >   INIT_FCALL                                               'function_exists'
         28        SEND_VAL                                                 'stream_set_read_buffer'
         29        DO_ICALL                                         $20     
         30        BOOL                                             ~19     $20
         31    > > JMPZ                                                     ~19, ->37
   90    32    >   INIT_FCALL                                               'stream_set_read_buffer'
         33        SEND_VAR                                                 !1
         34        FETCH_CONSTANT                                   ~21     'RANDOM_COMPAT_READ_BUFFER'
         35        SEND_VAL                                                 ~21
         36        DO_ICALL                                                 
  100    37    >   ISSET_ISEMPTY_CV                                 ~23     !1
         38        BOOL_NOT                                         ~24     ~23
         39      > JMPZ                                                     ~24, ->66
  101    40    >   ASSIGN                                                   !3, !0
  102    41        ASSIGN                                                   !4, ''
  107    42    >   INIT_FCALL                                               'fread'
         43        SEND_VAR                                                 !1
         44        SEND_VAR                                                 !3
         45        DO_ICALL                                         $27     
         46        ASSIGN                                                   !5, $27
  108    47        TYPE_CHECK                                    4          !5
         48      > JMPZ                                                     ~29, ->51
  113    49    >   ASSIGN                                                   !4, <false>
  114    50      > JMP                                                      ->58
  119    51    >   INIT_FCALL_BY_NAME                                       'RandomCompat_strlen'
         52        SEND_VAR_EX                                              !5
         53        DO_FCALL                                      0  $31     
         54        ASSIGN_OP                                     2          !3, $31
  120    55        ASSIGN_OP                                     8          !4, !5
  121    56        IS_SMALLER                                               0, !3
         57      > JMPNZ                                                    ~34, ->42
  126    58    >   TYPE_CHECK                                  1018          !4
         59      > JMPZ                                                     ~35, ->66
  127    60    >   INIT_FCALL_BY_NAME                                       'RandomCompat_strlen'
         61        SEND_VAR_EX                                              !4
         62        DO_FCALL                                      0  $36     
         63        IS_IDENTICAL                                             !0, $36
         64      > JMPZ                                                     ~37, ->66
  131    65    > > RETURN                                                   !4
  138    66    >   NEW                                              $38     'Exception'
  139    67        SEND_VAL_EX                                              'PHP+failed+to+generate+random+data.'
         68        DO_FCALL                                      0          
         69      > THROW                                         0          $38
  141    70*     > RETURN                                                   null

End of function %00random_bytes%2Fin%2FVJGCb%3A62%240

Function %00random_bytes%2Fin%2FVJGCb%3A155%241:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 14
Branch analysis from position: 10
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 28
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 28
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 28
filename:       /in/VJGCb
function name:  random_bytes
number of ops:  33
compiled vars:  !0 = $bytes, !1 = $buf
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  155     0  E >   RECV                                             !0      
  157     1        TYPE_CHECK                                   16  ~2      !0
          2        BOOL_NOT                                         ~3      ~2
          3      > JMPZ                                                     ~3, ->8
  158     4    >   NEW                                              $4      'Exception'
  159     5        SEND_VAL_EX                                              'Length+must+be+an+integer'
          6        DO_FCALL                                      0          
          7      > THROW                                         0          $4
  162     8    >   IS_SMALLER                                               !0, 1
          9      > JMPZ                                                     ~6, ->14
  163    10    >   NEW                                              $7      'Exception'
  164    11        SEND_VAL_EX                                              'Length+must+be+greater+than+0'
         12        DO_FCALL                                      0          
         13      > THROW                                         0          $7
  168    14    >   INIT_FCALL_BY_NAME                                       'mcrypt_create_iv'
         15        SEND_VAR_EX                                              !0
         16        FETCH_CONSTANT                                   ~9      'MCRYPT_DEV_URANDOM'
         17        SEND_VAL_EX                                              ~9
         18        DO_FCALL                                      0  $10     
         19        ASSIGN                                                   !1, $10
  169    20        TYPE_CHECK                                  1018          !1
         21      > JMPZ                                                     ~12, ->28
  170    22    >   INIT_FCALL_BY_NAME                                       'RandomCompat_strlen'
         23        SEND_VAR_EX                                              !1
         24        DO_FCALL                                      0  $13     
         25        IS_IDENTICAL                                             !0, $13
         26      > JMPZ                                                     ~14, ->28
  174    27    > > RETURN                                                   !1
  180    28    >   NEW                                              $15     'Exception'
  181    29        SEND_VAL_EX                                              'PHP+failed+to+generate+random+data.'
         30        DO_FCALL                                      0          
         31      > THROW                                         0          $15
  183    32*     > RETURN                                                   null

End of function %00random_bytes%2Fin%2FVJGCb%3A155%241

Function %00random_bytes%2Fin%2FVJGCb%3A196%242:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 26
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 7
Branch analysis from position: 29
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 7
filename:       /in/VJGCb
function name:  random_bytes
number of ops:  34
compiled vars:  !0 = $bytes, !1 = $buf, !2 = $util, !3 = $execCount
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  196     0  E >   RECV                                             !0      
  198     1        ASSIGN                                                   !1, ''
  199     2        NEW                                              $5      'COM'
          3        SEND_VAL_EX                                              'CAPICOM.Utilities.1'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !2, $5
  200     6        ASSIGN                                                   !3, 0
  206     7    >   INIT_FCALL                                               'base64_decode'
          8        INIT_METHOD_CALL                                         !2, 'GetRandom'
          9        SEND_VAR_EX                                              !0
         10        SEND_VAL_EX                                              0
         11        DO_FCALL                                      0  $9      
         12        SEND_VAR                                                 $9
         13        DO_ICALL                                         $10     
         14        ASSIGN_OP                                     8          !1, $10
  207    15        INIT_FCALL_BY_NAME                                       'RandomCompat_strlen'
         16        SEND_VAR_EX                                              !1
         17        DO_FCALL                                      0  $12     
         18        IS_SMALLER_OR_EQUAL                                      !0, $12
         19      > JMPZ                                                     ~13, ->26
  211    20    >   INIT_FCALL_BY_NAME                                       'RandomCompat_substr'
         21        SEND_VAR_EX                                              !1
         22        SEND_VAL_EX                                              0
         23        SEND_VAR_EX                                              !0
         24        DO_FCALL                                      0  $14     
         25      > RETURN                                                   $14
  213    26    >   PRE_INC                                                  !3
  214    27        IS_SMALLER                                               !3, !0
         28      > JMPNZ                                                    ~16, ->7
  218    29    >   NEW                                              $17     'Exception'
  219    30        SEND_VAL_EX                                              'PHP+failed+to+generate+random+data.'
         31        DO_FCALL                                      0          
         32      > THROW                                         0          $17
  221    33*     > RETURN                                                   null

End of function %00random_bytes%2Fin%2FVJGCb%3A196%242

Function %00random_bytes%2Fin%2FVJGCb%3A236%243:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 9, Position 2 = 10
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 17
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 17
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 17
Branch analysis from position: 10
filename:       /in/VJGCb
function name:  random_bytes
number of ops:  22
compiled vars:  !0 = $bytes, !1 = $secure, !2 = $buf
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  236     0  E >   RECV                                             !0      
  238     1        ASSIGN                                                   !1, <true>
  246     2        INIT_FCALL_BY_NAME                                       'openssl_random_pseudo_bytes'
          3        SEND_VAR_EX                                              !0
          4        SEND_VAR_EX                                              !1
          5        DO_FCALL                                      0  $4      
          6        ASSIGN                                                   !2, $4
  247     7        TYPE_CHECK                                  1018  ~6      !2
          8      > JMPZ_EX                                          ~6      ~6, ->10
          9    >   BOOL                                             ~6      !1
         10    > > JMPZ                                                     ~6, ->17
  248    11    >   INIT_FCALL_BY_NAME                                       'RandomCompat_strlen'
         12        SEND_VAR_EX                                              !2
         13        DO_FCALL                                      0  $7      
         14        IS_IDENTICAL                                             !0, $7
         15      > JMPZ                                                     ~8, ->17
  249    16    > > RETURN                                                   !2
  255    17    >   NEW                                              $9      'Exception'
  256    18        SEND_VAL_EX                                              'PHP+failed+to+generate+random+data.'
         19        DO_FCALL                                      0          
         20      > THROW                                         0          $9
  258    21*     > RETURN                                                   null

End of function %00random_bytes%2Fin%2FVJGCb%3A236%243

Function %00random_int%2Fin%2FVJGCb%3A281%244:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 9
Branch analysis from position: 5
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 16
Branch analysis from position: 12
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 22
Branch analysis from position: 18
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 25
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 38
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 51
Branch analysis from position: 51
2 jumps found. (Code = 43) Position 1 = 53, Position 2 = 57
Branch analysis from position: 53
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 57
2 jumps found. (Code = 43) Position 1 = 63, Position 2 = 67
Branch analysis from position: 63
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 67
1 jumps found. (Code = 42) Position 1 = 78
Branch analysis from position: 78
2 jumps found. (Code = 44) Position 1 = 80, Position 2 = 70
Branch analysis from position: 80
2 jumps found. (Code = 47) Position 1 = 86, Position 2 = 88
Branch analysis from position: 86
2 jumps found. (Code = 47) Position 1 = 89, Position 2 = 91
Branch analysis from position: 89
2 jumps found. (Code = 44) Position 1 = 92, Position 2 = 51
Branch analysis from position: 92
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 51
Branch analysis from position: 91
Branch analysis from position: 88
Branch analysis from position: 70
2 jumps found. (Code = 44) Position 1 = 80, Position 2 = 70
Branch analysis from position: 80
Branch analysis from position: 70
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
2 jumps found. (Code = 44) Position 1 = 50, Position 2 = 39
Branch analysis from position: 50
2 jumps found. (Code = 43) Position 1 = 53, Position 2 = 57
Branch analysis from position: 53
Branch analysis from position: 57
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 43
Branch analysis from position: 42
2 jumps found. (Code = 44) Position 1 = 50, Position 2 = 39
Branch analysis from position: 50
Branch analysis from position: 39
Branch analysis from position: 43
filename:       /in/VJGCb
function name:  random_int
number of ops:  95
compiled vars:  !0 = $min, !1 = $max, !2 = $attempts, !3 = $bits, !4 = $bytes, !5 = $mask, !6 = $valueShift, !7 = $range, !8 = $randomByteString, !9 = $val, !10 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  281     0  E >   RECV                                             !0      
          1        RECV                                             !1      
  286     2        TYPE_CHECK                                   16  ~11     !0
          3        BOOL_NOT                                         ~12     ~11
          4      > JMPZ                                               

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
202.43 ms | 1434 KiB | 41 Q