3v4l.org

run code in 300+ PHP versions simultaneously
<?php //bk2020 cc0 // SipHash-2-4 // Aumasson and Bernstein 2012, https://131002.net/siphash/ // https://github.com/jedisct1/libsodium/tree/master/src/libsodium/crypto_shorthash // https://github.com/php/php-src/tree/master/ext/sodium/libsodium.c#L472 function bytes_as_hex(&$str, $len=null) { if( !$len ) { $len = strlen($str); } // zero-based array index for unpack, kennwhite 2005: // https://www.php.net/manual/en/function.unpack.php#45188 $arrhead = array_merge( unpack('C*', substr($str,0,$len)) ); return array_reduce( $arrhead, function($a,$b) { return ($b>15) ? $a.dechex($b) : $a.'0'.dechex($b); }, '' ); } $SIPHASH = null; if( function_exists('\sodium_crypto_shorthash') ) { $SIPHASH = 'sodium_crypto_shorthash'; } else if( function_exists('\Sodium\crypto_shorthash') ) { $SIPHASH = '\Sodium\crypto_shorthash'; } else { die('Unable to test SipHash-2-4 using sodium_crypto_shorthash'); } $SIPKEY = '1234567890abcdef'; // 16-byte key for SipHash-2-4 echo '# ', $SIPHASH, PHP_EOL; // thanks to: https://3v4l.org/EsGSU // (note: bin2hex won't print leading zero on byte values <16) for ($i = 0; $i < 256; ++$i) { $msg = bin2hex( chr(($i & 0x3F) | 0x80) ); $aref = hrtime(); $hsh = $SIPHASH( $msg, $SIPKEY ); $anow = hrtime(); $nanos = ($anow[0]===$aref[0]) ? $anow[1]-$aref[1] : -1; echo $i, "\t", bytes_as_hex($hsh,8), "\t", $nanos, PHP_EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 7
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 62
Branch analysis from position: 62
2 jumps found. (Code = 44) Position 1 = 64, Position 2 = 20
Branch analysis from position: 64
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 44, Position 2 = 49
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
2 jumps found. (Code = 44) Position 1 = 64, Position 2 = 20
Branch analysis from position: 64
Branch analysis from position: 20
Branch analysis from position: 49
2 jumps found. (Code = 44) Position 1 = 64, Position 2 = 20
Branch analysis from position: 64
Branch analysis from position: 20
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 13
1 jumps found. (Code = 79) Position 1 = -2
filename:       /in/XVAq1
function name:  (null)
number of ops:  65
compiled vars:  !0 = $SIPHASH, !1 = $SIPKEY, !2 = $i, !3 = $msg, !4 = $aref, !5 = $hsh, !6 = $anow, !7 = $nanos
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   ASSIGN                                                   !0, null
   21     1        INIT_FCALL                                               'function_exists'
          2        SEND_VAL                                                 '%5Csodium_crypto_shorthash'
          3        DO_ICALL                                         $9      
          4      > JMPZ                                                     $9, ->7
   22     5    >   ASSIGN                                                   !0, 'sodium_crypto_shorthash'
          6      > JMP                                                      ->14
   24     7    >   INIT_FCALL                                               'function_exists'
          8        SEND_VAL                                                 '%5CSodium%5Ccrypto_shorthash'
          9        DO_ICALL                                         $11     
         10      > JMPZ                                                     $11, ->13
   25    11    >   ASSIGN                                                   !0, '%5CSodium%5Ccrypto_shorthash'
         12      > JMP                                                      ->14
   28    13    > > EXIT                                                     'Unable+to+test+SipHash-2-4+using+sodium_crypto_shorthash'
   31    14    >   ASSIGN                                                   !1, '1234567890abcdef'
   33    15        ECHO                                                     '%23+'
         16        ECHO                                                     !0
         17        ECHO                                                     '%0A'
   37    18        ASSIGN                                                   !2, 0
         19      > JMP                                                      ->62
   38    20    >   INIT_FCALL                                               'bin2hex'
         21        INIT_FCALL                                               'chr'
         22        BW_AND                                           ~15     !2, 63
         23        BW_OR                                            ~16     ~15, 128
         24        SEND_VAL                                                 ~16
         25        DO_ICALL                                         $17     
         26        SEND_VAR                                                 $17
         27        DO_ICALL                                         $18     
         28        ASSIGN                                                   !3, $18
   39    29        INIT_FCALL                                               'hrtime'
         30        DO_ICALL                                         $20     
         31        ASSIGN                                                   !4, $20
   40    32        INIT_DYNAMIC_CALL                                        !0
         33        SEND_VAR_EX                                              !3
         34        SEND_VAR_EX                                              !1
         35        DO_FCALL                                      0  $22     
         36        ASSIGN                                                   !5, $22
   41    37        INIT_FCALL                                               'hrtime'
         38        DO_ICALL                                         $24     
         39        ASSIGN                                                   !6, $24
   42    40        FETCH_DIM_R                                      ~26     !6, 0
         41        FETCH_DIM_R                                      ~27     !4, 0
         42        IS_IDENTICAL                                             ~26, ~27
         43      > JMPZ                                                     ~28, ->49
         44    >   FETCH_DIM_R                                      ~29     !6, 1
         45        FETCH_DIM_R                                      ~30     !4, 1
         46        SUB                                              ~31     ~29, ~30
         47        QM_ASSIGN                                        ~32     ~31
         48      > JMP                                                      ->50
         49    >   QM_ASSIGN                                        ~32     -1
         50    >   ASSIGN                                                   !7, ~32
   43    51        ECHO                                                     !2
         52        ECHO                                                     '%09'
         53        INIT_FCALL                                               'bytes_as_hex'
         54        SEND_REF                                                 !5
         55        SEND_VAL                                                 8
         56        DO_FCALL                                      0  $34     
         57        ECHO                                                     $34
         58        ECHO                                                     '%09'
         59        ECHO                                                     !7
         60        ECHO                                                     '%0A'
   37    61        PRE_INC                                                  !2
         62    >   IS_SMALLER                                               !2, 256
         63      > JMPNZ                                                    ~36, ->20
   44    64    > > RETURN                                                   1

Function bytes_as_hex:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
filename:       /in/XVAq1
function name:  bytes_as_hex
number of ops:  27
compiled vars:  !0 = $str, !1 = $len, !2 = $arrhead
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
    9     2        BOOL_NOT                                         ~3      !1
          3      > JMPZ                                                     ~3, ->6
          4    >   STRLEN                                           ~4      !0
          5        ASSIGN                                                   !1, ~4
   13     6    >   INIT_FCALL                                               'array_merge'
          7        INIT_FCALL                                               'unpack'
          8        SEND_VAL                                                 'C%2A'
          9        INIT_FCALL                                               'substr'
         10        SEND_VAR                                                 !0
         11        SEND_VAL                                                 0
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                         $6      
         14        SEND_VAR                                                 $6
         15        DO_ICALL                                         $7      
         16        SEND_VAR                                                 $7
         17        DO_ICALL                                         $8      
         18        ASSIGN                                                   !2, $8
   15    19        INIT_FCALL                                               'array_reduce'
         20        SEND_VAR                                                 !2
         21        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FXVAq1%3A15%240'
   17    22        SEND_VAL                                                 ~10
         23        SEND_VAL                                                 ''
         24        DO_ICALL                                         $11     
         25      > RETURN                                                   $11
   18    26*     > RETURN                                                   null

End of function bytes_as_hex

Function %00%7Bclosure%7D%2Fin%2FXVAq1%3A15%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XVAq1
function name:  {closure}
number of ops:  18
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   16     2        IS_SMALLER                                               15, !1
          3      > JMPZ                                                     ~2, ->10
          4    >   INIT_FCALL                                               'dechex'
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $3      
          7        CONCAT                                           ~4      !0, $3
          8        QM_ASSIGN                                        ~5      ~4
          9      > JMP                                                      ->16
         10    >   CONCAT                                           ~6      !0, '0'
         11        INIT_FCALL                                               'dechex'
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                         $7      
         14        CONCAT                                           ~8      ~6, $7
         15        QM_ASSIGN                                        ~5      ~8
         16    > > RETURN                                                   ~5
   17    17*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FXVAq1%3A15%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
205.77 ms | 1407 KiB | 32 Q