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(); echo $i, "\t", bytes_as_hex($hsh,8), $aref, $anow, 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 = 51
Branch analysis from position: 51
2 jumps found. (Code = 44) Position 1 = 53, Position 2 = 20
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 53, Position 2 = 20
Branch analysis from position: 53
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/pkpGt
function name:  (null)
number of ops:  54
compiled vars:  !0 = $SIPHASH, !1 = $SIPKEY, !2 = $i, !3 = $msg, !4 = $aref, !5 = $hsh, !6 = $anow
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                                         $8      
          4      > JMPZ                                                     $8, ->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                                         $10     
         10      > JMPZ                                                     $10, ->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                                                      ->51
   38    20    >   INIT_FCALL                                               'bin2hex'
         21        INIT_FCALL                                               'chr'
         22        BW_AND                                           ~14     !2, 63
         23        BW_OR                                            ~15     ~14, 128
         24        SEND_VAL                                                 ~15
         25        DO_ICALL                                         $16     
         26        SEND_VAR                                                 $16
         27        DO_ICALL                                         $17     
         28        ASSIGN                                                   !3, $17
   39    29        INIT_FCALL                                               'hrtime'
         30        DO_ICALL                                         $19     
         31        ASSIGN                                                   !4, $19
   40    32        INIT_DYNAMIC_CALL                                        !0
         33        SEND_VAR_EX                                              !3
         34        SEND_VAR_EX                                              !1
         35        DO_FCALL                                      0  $21     
         36        ASSIGN                                                   !5, $21
   41    37        INIT_FCALL                                               'hrtime'
         38        DO_ICALL                                         $23     
         39        ASSIGN                                                   !6, $23
   42    40        ECHO                                                     !2
         41        ECHO                                                     '%09'
         42        INIT_FCALL                                               'bytes_as_hex'
         43        SEND_REF                                                 !5
         44        SEND_VAL                                                 8
         45        DO_FCALL                                      0  $25     
         46        ECHO                                                     $25
         47        ECHO                                                     !4
         48        ECHO                                                     !6
         49        ECHO                                                     '%0A'
   37    50        PRE_INC                                                  !2
         51    >   IS_SMALLER                                               !2, 256
         52      > JMPNZ                                                    ~27, ->20
   43    53    > > 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/pkpGt
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%2FpkpGt%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%2FpkpGt%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/pkpGt
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%2FpkpGt%3A15%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
172.8 ms | 1407 KiB | 32 Q