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); } return $digest_length; print $salt; // 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 = ''; 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 ); // T = T(1) | T(2) | T(3) | ... | T(N) $t .= $last_block; } // 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/nsLdk
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
   78    28      > RETURN                                                   1

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

End of function hkdf

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.28 ms | 1400 KiB | 27 Q