3v4l.org

run code in 300+ PHP versions simultaneously
<?php const CIPHER = MCRYPT_RIJNDAEL_128; const KEY_BYTE_SIZE = 16; const CIPHER_MODE = 'cbc'; const HASH_FUNCTION = 'sha256'; const MAC_BYTE_SIZE = 32; const ENCRYPTION_INFO = 'PIPS|KeyForEncryption'; const AUTHENTICATION_INFO = 'PIPS|KeyForAuthentication'; $key = base64_decode('wdmd3XIhnOAelom4Y8yPbw=='); $ekey = HKDF(HASH_FUNCTION, $key, KEY_BYTE_SIZE, ENCRYPTION_INFO); print "$ekey\n"; print urlsafe_b64encode($ekey); function urlsafe_b64encode($string) { $data = base64_encode($string); $data = str_replace(array('+','/','='),array('-','_',''),$data); return $data; } function HKDF($hash, $ikm, $length, $info = '', $salt = NULL) { // Find the correct digest length as quickly as we can. $digest_length = MAC_BYTE_SIZE; if ($hash != HASH_FUNCTION) { $digest_length = strlen(hash_hmac($hash, '', '', true)); } // Sanity-check the desired output length. if (empty($length) || !is_int($length) || $length < 0 || $length > 255 * $digest_length) { return CannotPerformOperationException(); } // "if [salt] not provided, is set to a string of HashLen zeroes." if (is_null($salt)) { $salt = str_repeat("\x00", $digest_length); } // HKDF-Extract: // PRK = HMAC-Hash(salt, IKM) // The salt is the HMAC key. $prk = hash_hmac($hash, $ikm, $salt, true); // HKDF-Expand: // This check is useless, but it serves as a reminder to the spec. if (strlen($prk) < $digest_length) { throw new CannotPerformOperationException(); } // T(0) = '' $t = ''; $last_block = ''; $record = ''; $iterations = 0; for ($block_index = 1; strlen($t) < $length; $block_index++) { // T(i) = HMAC-Hash(PRK, T(i-1) | info | 0x??) $last_block = hash_hmac( $hash, $last_block . $info . chr($block_index), $prk, true ); $record .= urlsafe_b64encode($last_block) . "\n"; $iterations++; // T = T(1) | T(2) | T(3) | ... | T(N) $t .= $last_block; } return $iterations; //return $record; // ORM = first L octets of T $orm = substr($t, 0, $length); if ($orm === FALSE) { throw new CannotPerformOperationException(); } return $orm; } ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HUNud
function name:  (null)
number of ops:  29
compiled vars:  !0 = $key, !1 = $ekey
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CONST                                            'CIPHER', <const ast>
    4     1        DECLARE_CONST                                            'KEY_BYTE_SIZE', 16
    5     2        DECLARE_CONST                                            'CIPHER_MODE', 'cbc'
    6     3        DECLARE_CONST                                            'HASH_FUNCTION', 'sha256'
    7     4        DECLARE_CONST                                            'MAC_BYTE_SIZE', 32
    8     5        DECLARE_CONST                                            'ENCRYPTION_INFO', 'PIPS%7CKeyForEncryption'
    9     6        DECLARE_CONST                                            'AUTHENTICATION_INFO', 'PIPS%7CKeyForAuthentication'
   11     7        INIT_FCALL                                               'base64_decode'
          8        SEND_VAL                                                 'wdmd3XIhnOAelom4Y8yPbw%3D%3D'
          9        DO_ICALL                                         $2      
         10        ASSIGN                                                   !0, $2
   12    11        INIT_FCALL_BY_NAME                                       'HKDF'
         12        FETCH_CONSTANT                                   ~4      'HASH_FUNCTION'
         13        SEND_VAL_EX                                              ~4
         14        SEND_VAR_EX                                              !0
         15        FETCH_CONSTANT                                   ~5      'KEY_BYTE_SIZE'
         16        SEND_VAL_EX                                              ~5
         17        FETCH_CONSTANT                                   ~6      'ENCRYPTION_INFO'
         18        SEND_VAL_EX                                              ~6
         19        DO_FCALL                                      0  $7      
         20        ASSIGN                                                   !1, $7
   13    21        NOP                                                      
         22        FAST_CONCAT                                      ~9      !1, '%0A'
         23        ECHO                                                     ~9
   14    24        INIT_FCALL_BY_NAME                                       'urlsafe_b64encode'
         25        SEND_VAR_EX                                              !1
         26        DO_FCALL                                      0  $10     
         27        ECHO                                                     $10
   81    28      > RETURN                                                   1

Function urlsafe_b64encode:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HUNud
function name:  urlsafe_b64encode
number of ops:  13
compiled vars:  !0 = $string, !1 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   17     1        INIT_FCALL                                               'base64_encode'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $2      
          4        ASSIGN                                                   !1, $2
   18     5        INIT_FCALL                                               'str_replace'
          6        SEND_VAL                                                 <array>
          7        SEND_VAL                                                 <array>
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                         $4      
         10        ASSIGN                                                   !1, $4
   19    11      > RETURN                                                   !1
   20    12*     > RETURN                                                   null

End of function urlsafe_b64encode

Function hkdf:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 18
Branch analysis from position: 10
2 jumps found. (Code = 47) Position 1 = 20, Position 2 = 23
Branch analysis from position: 20
2 jumps found. (Code = 47) Position 1 = 24, Position 2 = 26
Branch analysis from position: 24
2 jumps found. (Code = 47) Position 1 = 27, Position 2 = 30
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 34
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 41
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 51, Position 2 = 54
Branch analysis from position: 51
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 54
1 jumps found. (Code = 42) Position 1 = 80
Branch analysis from position: 80
2 jumps found. (Code = 44) Position 1 = 83, Position 2 = 60
Branch analysis from position: 83
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 60
2 jumps found. (Code = 44) Position 1 = 83, Position 2 = 60
Branch analysis from position: 83
Branch analysis from position: 60
Branch analysis from position: 41
Branch analysis from position: 30
Branch analysis from position: 26
Branch analysis from position: 23
Branch analysis from position: 18
filename:       /in/HUNud
function name:  HKDF
number of ops:  97
compiled vars:  !0 = $hash, !1 = $ikm, !2 = $length, !3 = $info, !4 = $salt, !5 = $digest_length, !6 = $prk, !7 = $t, !8 = $last_block, !9 = $record, !10 = $iterations, !11 = $block_index, !12 = $orm
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV_INIT                                        !3      ''
          4        RECV_INIT                                        !4      null
   25     5        FETCH_CONSTANT                                   ~13     'MAC_BYTE_SIZE'
          6        ASSIGN                                                   !5, ~13
   26     7        FETCH_CONSTANT                                   ~15     'HASH_FUNCTION'
          8        IS_NOT_EQUAL                                             !0, ~15
          9      > JMPZ                                                     ~16, ->18
   27    10    >   INIT_FCALL                                               'hash_hmac'
         11        SEND_VAR                                                 !0
         12        SEND_VAL                                                 ''
         13        SEND_VAL                                                 ''
         14        SEND_VAL                                                 <true>
         15        DO_ICALL                                         $17     
         16        STRLEN                                           ~18     $17
         17        ASSIGN                                                   !5, ~18
   31    18    >   ISSET_ISEMPTY_CV                                 ~20     !2
         19      > JMPNZ_EX                                         ~20     ~20, ->23
         20    >   TYPE_CHECK                                   16  ~21     !2
         21        BOOL_NOT                                         ~22     ~21
         22        BOOL                                             ~20     ~22
         23    > > JMPNZ_EX                                         ~20     ~20, ->26
   32    24    >   IS_SMALLER                                       ~23     !2, 0
         25        BOOL                                             ~20     ~23
         26    > > JMPNZ_EX                                         ~20     ~20, ->30
         27    >   MUL                                              ~24     !5, 255
         28        IS_SMALLER                                       ~25     ~24, !2
         29        BOOL                                             ~20     ~25
         30    > > JMPZ                                                     ~20, ->34
   33    31    >   INIT_FCALL_BY_NAME                                       'CannotPerformOperationException'
         32        DO_FCALL                                      0  $26     
         33      > RETURN                                                   $26
   37    34    >   TYPE_CHECK                                    2          !4
         35      > JMPZ                                                     ~27, ->41
   38    36    >   INIT_FCALL                                               'str_repeat'
         37        SEND_VAL                                                 '%00'
         38        SEND_VAR                                                 !5
         39        DO_ICALL                                         $28     
         40        ASSIGN                                                   !4, $28
   44    41    >   INIT_FCALL                                               'hash_hmac'
         42        SEND_VAR                                                 !0
         43        SEND_VAR                                                 !1
         44        SEND_VAR                                                 !4
         45        SEND_VAL                                                 <true>
         46        DO_ICALL                                         $30     
         47        ASSIGN                                                   !6, $30
   49    48        STRLEN                                           ~32     !6
         49        IS_SMALLER                                               ~32, !5
         50      > JMPZ                                                     ~33, ->54
   50    51    >   NEW                                              $34     'CannotPerformOperationException'
         52        DO_FCALL                                      0          
         53      > THROW                                         0          $34
   54    54    >   ASSIGN                                                   !7, ''
   55    55        ASSIGN                                                   !8, ''
   56    56        ASSIGN                                                   !9, ''
   57    57        ASSIGN                                                   !10, 0
   58    58        ASSIGN                                                   !11, 1
         59      > JMP                                                      ->80
   60    60    >   INIT_FCALL                                               'hash_hmac'
   61    61        SEND_VAR                                                 !0
   62    62        CONCAT                                           ~41     !8, !3
         63        INIT_FCALL                                               'chr'
         64        SEND_VAR                                                 !11
         65        DO_ICALL                                         $42     
         66        CONCAT                                           ~43     ~41, $42
         67        SEND_VAL                                                 ~43
   63    68        SEND_VAR                                                 !6
   64    69        SEND_VAL                                                 <true>
         70        DO_ICALL                                         $44     
   60    71        ASSIGN                                                   !8, $44
   66    72        INIT_FCALL                                               'urlsafe_b64encode'
         73        SEND_VAR                                                 !8
         74        DO_FCALL                                      0  $46     
         75        CONCAT                                           ~47     $46, '%0A'
         76        ASSIGN_OP                                     8          !9, ~47
   67    77        PRE_INC                                                  !10
   69    78        ASSIGN_OP                                     8          !7, !8
   58    79        PRE_INC                                                  !11
         80    >   STRLEN                                           ~52     !7
         81        IS_SMALLER                                               ~52, !2
         82      > JMPNZ                                                    ~53, ->60
   72    83    > > RETURN                                                   !10
   75    84*       INIT_FCALL                                               'substr'
         85*       SEND_VAR                                                 !7
         86*       SEND_VAL                                                 0
         87*       SEND_VAR                                                 !2
         88*       DO_ICALL                                         $54     
         89*       ASSIGN                                                   !12, $54
   76    90*       TYPE_CHECK                                    4          !12
         91*       JMPZ                                                     ~56, ->95
   77    92*       NEW                                              $57     'CannotPerformOperationException'
         93*       DO_FCALL                                      0          
         94*       THROW                                         0          $57
   79    95*       RETURN                                                   !12
   80    96*     > RETURN                                                   null

End of function hkdf

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.11 ms | 1411 KiB | 28 Q