3v4l.org

run code in 300+ PHP versions simultaneously
<?php function hmac_compare(string $a, string $b): bool { $random = random_bytes(32); return hash_hmac('sha256', $a, $random) === hash_hmac('sha256', $b, $random); } $key = random_bytes(32); $x = hash_hmac('sha256', 'test', $key); $y = hash_hmac('sha256', 'test', $key); $z = hash_hmac('sha256', 'test2', $key); var_dump( hmac_compare($x, $y), // true hmac_compare($y, $z) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/28leS
function name:  (null)
number of ops:  35
compiled vars:  !0 = $key, !1 = $x, !2 = $y, !3 = $z
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   INIT_FCALL                                               'random_bytes'
          1        SEND_VAL                                                 32
          2        DO_ICALL                                         $4      
          3        ASSIGN                                                   !0, $4
   10     4        INIT_FCALL                                               'hash_hmac'
          5        SEND_VAL                                                 'sha256'
          6        SEND_VAL                                                 'test'
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $6      
          9        ASSIGN                                                   !1, $6
   11    10        INIT_FCALL                                               'hash_hmac'
         11        SEND_VAL                                                 'sha256'
         12        SEND_VAL                                                 'test'
         13        SEND_VAR                                                 !0
         14        DO_ICALL                                         $8      
         15        ASSIGN                                                   !2, $8
   12    16        INIT_FCALL                                               'hash_hmac'
         17        SEND_VAL                                                 'sha256'
         18        SEND_VAL                                                 'test2'
         19        SEND_VAR                                                 !0
         20        DO_ICALL                                         $10     
         21        ASSIGN                                                   !3, $10
   14    22        INIT_FCALL                                               'var_dump'
   15    23        INIT_FCALL                                               'hmac_compare'
         24        SEND_VAR                                                 !1
         25        SEND_VAR                                                 !2
         26        DO_FCALL                                      0  $12     
         27        SEND_VAR                                                 $12
   16    28        INIT_FCALL                                               'hmac_compare'
         29        SEND_VAR                                                 !2
         30        SEND_VAR                                                 !3
         31        DO_FCALL                                      0  $13     
         32        SEND_VAR                                                 $13
   14    33        DO_ICALL                                                 
   17    34      > RETURN                                                   1

Function hmac_compare:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/28leS
function name:  hmac_compare
number of ops:  21
compiled vars:  !0 = $a, !1 = $b, !2 = $random
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        INIT_FCALL                                               'random_bytes'
          3        SEND_VAL                                                 32
          4        DO_ICALL                                         $3      
          5        ASSIGN                                                   !2, $3
    6     6        INIT_FCALL                                               'hash_hmac'
          7        SEND_VAL                                                 'sha256'
          8        SEND_VAR                                                 !0
          9        SEND_VAR                                                 !2
         10        DO_ICALL                                         $5      
         11        INIT_FCALL                                               'hash_hmac'
         12        SEND_VAL                                                 'sha256'
         13        SEND_VAR                                                 !1
         14        SEND_VAR                                                 !2
         15        DO_ICALL                                         $6      
         16        IS_IDENTICAL                                     ~7      $5, $6
         17        VERIFY_RETURN_TYPE                                       ~7
         18      > RETURN                                                   ~7
    7    19*       VERIFY_RETURN_TYPE                                       
         20*     > RETURN                                                   null

End of function hmac_compare

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
140.45 ms | 1446 KiB | 18 Q