3v4l.org

run code in 300+ PHP versions simultaneously
<?php function pbkdf2( $algorithm = 'sha512', $password, $salt, $count = 2048, $key_length = 512, $raw_output = false ){ if($count <= 0 || $key_length <= 0) { $count = 2048; $key_length = 512; } $hash_length = strlen(hash($algorithm, "", true)); $block_count = ceil($key_length / $hash_length); $output = ""; for($i = 1; $i <= $block_count; $i++) { $last = $salt . pack("N", $i); $last = $xorsum = hash_hmac($algorithm, $last, $password, true); for ($j = 1; $j < $count; $j++) { $xorsum ^= ($last = hash_hmac($algorithm, $last, $password, true)); } $output .= $xorsum; } if($raw_output) { return substr($output, 0, $key_length); } else { return bin2hex(substr($output, 0, $key_length)); } } function generate_salt(){ $random = file_get_contents( '/dev/urandom', false, null, 0, 256 ); return bin2hex( $random ); } function get_hash( $plain_text, $salt ){ if( !isset($plain_text) || !isset($salt) ){ return false; } if( gettype($salt) == "string" ){ $salt = array( $salt, $salt ); } $iterations = 1024; $hash = pbkdf2( "whirlpool", $plain_text, $salt[0], $iterations, 512, true ); $hash = pbkdf2( "sha512", $hash, $salt[1], $iterations, 512 ); return $hash; } function test(){ $salt = array( 0 => generate_salt(), 1 => generate_salt() ); $salt = array( 0 => '5162e9d43703517e8efa9c0ff835e6d49914e60ae567574466e21bdbb6d6e647d58e468c3b5ff1b4b5bf667ce7d9896d0a8535bb9e862c65f998ba45fafa5fee1eef524873f3daf5405a36a471dc87803ac25df9d05463649e80941982c97315fb94b0d8d812420e1433fa45b75cbfba70723d5ad7fefe10a4e4d6e4759bacaa93903947e1f9157b204fbd17c489cc5edeb02f35301b45a4e3f0097aadf74e7bbdc25050c685e236fd90125e236e2eb349ec1bf2a7a33f3e6e1555b8658c0fcb155220b14cf03f420a7fda1012b089238c2c6226bf0d5c38742df8853caccd6f23baa0b2430731d4ba9c52d5b1d7e07622524969399971ad42a4af1195b14e7b', 1 => '81c36d5f5612aeae6b5d5595f0ed1541f6f732f1512695baceb514e1964f9a0551d902945df52c81a77f3b66936040be1eb723e571e5d1de7769fe016ccfa7b9468e1d912b17d608f052a3ae834254445be575c47f75f88464116698dba29694e5da8082c1e97430ab46cf7d5be5d0e2c4f94db93eb8c7bfdd5bb84d68d4685a31f6fb06e2408a268a651395b9faef509acbfdbb9d32fd0ffe5b8b7f7f71e72c825fe2e516e3be082041807978bc17a48f2ed53ed00a8533cbaa90b49b6ebda6028406a1845ada1ac77ca7433ee27449913afd82726d47c96237b9f5059404033e1bc62a60ffcd9d174f6ca49b6b07a0ae3042bc1ba06ad56e85466cf4cc6025' ); $plain_text = "mysupersecurepassword"; echo "start\n"; $result = get_hash( $plain_text, $salt ); echo $result; } test(); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/a4LlG
function name:  (null)
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   69     0  E >   INIT_FCALL                                               'test'
          1        DO_FCALL                                      0          
   70     2      > RETURN                                                   1

Function pbkdf2:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 57
Branch analysis from position: 57
2 jumps found. (Code = 44) Position 1 = 59, Position 2 = 28
Branch analysis from position: 59
2 jumps found. (Code = 43) Position 1 = 60, Position 2 = 67
Branch analysis from position: 60
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 67
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
2 jumps found. (Code = 44) Position 1 = 55, Position 2 = 44
Branch analysis from position: 55
2 jumps found. (Code = 44) Position 1 = 59, Position 2 = 28
Branch analysis from position: 59
Branch analysis from position: 28
Branch analysis from position: 44
2 jumps found. (Code = 44) Position 1 = 55, Position 2 = 44
Branch analysis from position: 55
Branch analysis from position: 44
Branch analysis from position: 13
Branch analysis from position: 10
filename:       /in/a4LlG
function name:  pbkdf2
number of ops:  77
compiled vars:  !0 = $algorithm, !1 = $password, !2 = $salt, !3 = $count, !4 = $key_length, !5 = $raw_output, !6 = $hash_length, !7 = $block_count, !8 = $output, !9 = $i, !10 = $last, !11 = $xorsum, !12 = $j
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV_INIT                                        !0      'sha512'
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV_INIT                                        !3      2048
          4        RECV_INIT                                        !4      512
          5        RECV_INIT                                        !5      <false>
    4     6        IS_SMALLER_OR_EQUAL                              ~13     !3, 0
          7      > JMPNZ_EX                                         ~13     ~13, ->10
          8    >   IS_SMALLER_OR_EQUAL                              ~14     !4, 0
          9        BOOL                                             ~13     ~14
         10    > > JMPZ                                                     ~13, ->13
    5    11    >   ASSIGN                                                   !3, 2048
    6    12        ASSIGN                                                   !4, 512
    9    13    >   INIT_FCALL                                               'hash'
         14        SEND_VAR                                                 !0
         15        SEND_VAL                                                 ''
         16        SEND_VAL                                                 <true>
         17        DO_ICALL                                         $17     
         18        STRLEN                                           ~18     $17
         19        ASSIGN                                                   !6, ~18
   10    20        INIT_FCALL                                               'ceil'
         21        DIV                                              ~20     !4, !6
         22        SEND_VAL                                                 ~20
         23        DO_ICALL                                         $21     
         24        ASSIGN                                                   !7, $21
   12    25        ASSIGN                                                   !8, ''
   13    26        ASSIGN                                                   !9, 1
         27      > JMP                                                      ->57
   14    28    >   INIT_FCALL                                               'pack'
         29        SEND_VAL                                                 'N'
         30        SEND_VAR                                                 !9
         31        DO_ICALL                                         $25     
         32        CONCAT                                           ~26     !2, $25
         33        ASSIGN                                                   !10, ~26
   15    34        INIT_FCALL                                               'hash_hmac'
         35        SEND_VAR                                                 !0
         36        SEND_VAR                                                 !10
         37        SEND_VAR                                                 !1
         38        SEND_VAL                                                 <true>
         39        DO_ICALL                                         $28     
         40        ASSIGN                                           ~29     !11, $28
         41        ASSIGN                                                   !10, ~29
   16    42        ASSIGN                                                   !12, 1
         43      > JMP                                                      ->53
   17    44    >   INIT_FCALL                                               'hash_hmac'
         45        SEND_VAR                                                 !0
         46        SEND_VAR                                                 !10
         47        SEND_VAR                                                 !1
         48        SEND_VAL                                                 <true>
         49        DO_ICALL                                         $32     
         50        ASSIGN                                           ~33     !10, $32
         51        ASSIGN_OP                                    11          !11, ~33
   16    52        PRE_INC                                                  !12
         53    >   IS_SMALLER                                               !12, !3
         54      > JMPNZ                                                    ~36, ->44
   19    55    >   ASSIGN_OP                                     8          !8, !11
   13    56        PRE_INC                                                  !9
         57    >   IS_SMALLER_OR_EQUAL                                      !9, !7
         58      > JMPNZ                                                    ~39, ->28
   22    59    > > JMPZ                                                     !5, ->67
   23    60    >   INIT_FCALL                                               'substr'
         61        SEND_VAR                                                 !8
         62        SEND_VAL                                                 0
         63        SEND_VAR                                                 !4
         64        DO_ICALL                                         $40     
         65      > RETURN                                                   $40
         66*       JMP                                                      ->76
   25    67    >   INIT_FCALL                                               'bin2hex'
         68        INIT_FCALL                                               'substr'
         69        SEND_VAR                                                 !8
         70        SEND_VAL                                                 0
         71        SEND_VAR                                                 !4
         72        DO_ICALL                                         $41     
         73        SEND_VAR                                                 $41
         74        DO_ICALL                                         $42     
         75      > RETURN                                                   $42
   27    76*     > RETURN                                                   null

End of function pbkdf2

Function generate_salt:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/a4LlG
function name:  generate_salt
number of ops:  13
compiled vars:  !0 = $random
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   INIT_FCALL                                               'file_get_contents'
          1        SEND_VAL                                                 '%2Fdev%2Furandom'
          2        SEND_VAL                                                 <false>
          3        SEND_VAL                                                 null
          4        SEND_VAL                                                 0
          5        SEND_VAL                                                 256
          6        DO_ICALL                                         $1      
          7        ASSIGN                                                   !0, $1
   31     8        INIT_FCALL                                               'bin2hex'
          9        SEND_VAR                                                 !0
         10        DO_ICALL                                         $3      
         11      > RETURN                                                   $3
   32    12*     > RETURN                                                   null

End of function generate_salt

Function get_hash:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 10
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 16
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
Branch analysis from position: 8
filename:       /in/a4LlG
function name:  get_hash
number of ops:  38
compiled vars:  !0 = $plain_text, !1 = $salt, !2 = $iterations, !3 = $hash
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   36     2        ISSET_ISEMPTY_CV                                 ~4      !0
          3        BOOL_NOT                                         ~5      ~4
          4      > JMPNZ_EX                                         ~5      ~5, ->8
          5    >   ISSET_ISEMPTY_CV                                 ~6      !1
          6        BOOL_NOT                                         ~7      ~6
          7        BOOL                                             ~5      ~7
          8    > > JMPZ                                                     ~5, ->10
   37     9    > > RETURN                                                   <false>
   40    10    >   GET_TYPE                                         ~8      !1
         11        IS_EQUAL                                                 ~8, 'string'
         12      > JMPZ                                                     ~9, ->16
   41    13    >   INIT_ARRAY                                       ~10     !1
         14        ADD_ARRAY_ELEMENT                                ~10     !1
         15        ASSIGN                                                   !1, ~10
   44    16    >   ASSIGN                                                   !2, 1024
   46    17        INIT_FCALL                                               'pbkdf2'
         18        SEND_VAL                                                 'whirlpool'
         19        SEND_VAR                                                 !0
         20        FETCH_DIM_R                                      ~13     !1, 0
         21        SEND_VAL                                                 ~13
         22        SEND_VAR                                                 !2
         23        SEND_VAL                                                 512
         24        SEND_VAL                                                 <true>
         25        DO_FCALL                                      0  $14     
         26        ASSIGN                                                   !3, $14
   47    27        INIT_FCALL                                               'pbkdf2'
         28        SEND_VAL                                                 'sha512'
         29        SEND_VAR                                                 !3
         30        FETCH_DIM_R                                      ~16     !1, 1
         31        SEND_VAL                                                 ~16
         32        SEND_VAR                                                 !2
         33        SEND_VAL                                                 512
         34        DO_FCALL                                      0  $17     
         35        ASSIGN                                                   !3, $17
   49    36      > RETURN                                                   !3
   50    37*     > RETURN                                                   null

End of function get_hash

Function test:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/a4LlG
function name:  test
number of ops:  17
compiled vars:  !0 = $salt, !1 = $plain_text, !2 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   INIT_FCALL                                               'generate_salt'
          1        DO_FCALL                                      0  $3      
          2        INIT_ARRAY                                       ~4      $3, 0
   55     3        INIT_FCALL                                               'generate_salt'
          4        DO_FCALL                                      0  $5      
          5        ADD_ARRAY_ELEMENT                                ~4      $5, 1
   53     6        ASSIGN                                                   !0, ~4
   58     7        ASSIGN                                                   !0, <array>
   62     8        ASSIGN                                                   !1, 'mysupersecurepassword'
   64     9        ECHO                                                     'start%0A'
   65    10        INIT_FCALL                                               'get_hash'
         11        SEND_VAR                                                 !1
         12        SEND_VAR                                                 !0
         13        DO_FCALL                                      0  $9      
         14        ASSIGN                                                   !2, $9
   66    15        ECHO                                                     !2
   67    16      > RETURN                                                   null

End of function test

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
277.83 ms | 1411 KiB | 34 Q