3v4l.org

run code in 300+ PHP versions simultaneously
<?php $algo = 'aes-256-gcm'; $iv = random_bytes(openssl_cipher_iv_length($algo)); echo(openssl_cipher_iv_length($algo)); echo("\n"); $key = random_bytes(32); // 256 bit //$data = random_bytes(1024); // 1 Kb of random data $data = "well hello there with insane length and soooooooooooooooooooooooooooooooooooooooo much data in it. Bigger better stronger D:"; $ciphertext = openssl_encrypt( $data, $algo, $key, OPENSSL_RAW_DATA, $iv, $tag ); // Change 1 bit in ciphertext // $i = rand(0, mb_strlen($ciphertext, '8bit') - 1); // $ciphertext[$i] = $ciphertext[$i] ^ chr(1); echo(base64_encode($ciphertext)); echo("\n"); echo(base64_encode($tag)); $i = rand(0, mb_strlen($tag, '8bit') - 1); //$tag[$i] = $tag[$i] ^ chr(1); echo("\n"); echo(base64_encode($tag)); $decrypt = openssl_decrypt( $ciphertext, $algo, $key, OPENSSL_RAW_DATA, $iv, $tag ); if (false === $decrypt) { throw new Exception(sprintf( "OpenSSL error: %s", openssl_error_string() )); } printf ("Decryption %s\n", $data === $decrypt ? 'Ok' : 'Failed');
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 64, Position 2 = 74
Branch analysis from position: 64
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 74
2 jumps found. (Code = 43) Position 1 = 78, Position 2 = 80
Branch analysis from position: 78
1 jumps found. (Code = 42) Position 1 = 81
Branch analysis from position: 81
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 80
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XUe6r
function name:  (null)
number of ops:  84
compiled vars:  !0 = $algo, !1 = $iv, !2 = $key, !3 = $data, !4 = $ciphertext, !5 = $tag, !6 = $i, !7 = $decrypt
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, 'aes-256-gcm'
    3     1        INIT_FCALL                                               'random_bytes'
          2        INIT_FCALL_BY_NAME                                       'openssl_cipher_iv_length'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $9      
          5        SEND_VAR                                                 $9
          6        DO_ICALL                                         $10     
          7        ASSIGN                                                   !1, $10
    5     8        INIT_FCALL_BY_NAME                                       'openssl_cipher_iv_length'
          9        SEND_VAR_EX                                              !0
         10        DO_FCALL                                      0  $12     
         11        ECHO                                                     $12
    6    12        ECHO                                                     '%0A'
    7    13        INIT_FCALL                                               'random_bytes'
         14        SEND_VAL                                                 32
         15        DO_ICALL                                         $13     
         16        ASSIGN                                                   !2, $13
    9    17        ASSIGN                                                   !3, 'well+hello+there+with+insane+length+and+soooooooooooooooooooooooooooooooooooooooo+much+data+in+it.+Bigger+better+stronger+D%3A'
   10    18        INIT_FCALL_BY_NAME                                       'openssl_encrypt'
   11    19        SEND_VAR_EX                                              !3
         20        SEND_VAR_EX                                              !0
         21        SEND_VAR_EX                                              !2
   14    22        FETCH_CONSTANT                                   ~16     'OPENSSL_RAW_DATA'
         23        SEND_VAL_EX                                              ~16
   11    24        SEND_VAR_EX                                              !1
         25        SEND_VAR_EX                                              !5
         26        DO_FCALL                                      0  $17     
   10    27        ASSIGN                                                   !4, $17
   21    28        INIT_FCALL                                               'base64_encode'
         29        SEND_VAR                                                 !4
         30        DO_ICALL                                         $19     
         31        ECHO                                                     $19
   22    32        ECHO                                                     '%0A'
   23    33        INIT_FCALL                                               'base64_encode'
         34        SEND_VAR                                                 !5
         35        DO_ICALL                                         $20     
         36        ECHO                                                     $20
   24    37        INIT_FCALL                                               'rand'
         38        SEND_VAL                                                 0
         39        INIT_FCALL                                               'mb_strlen'
         40        SEND_VAR                                                 !5
         41        SEND_VAL                                                 '8bit'
         42        DO_ICALL                                         $21     
         43        SUB                                              ~22     $21, 1
         44        SEND_VAL                                                 ~22
         45        DO_ICALL                                         $23     
         46        ASSIGN                                                   !6, $23
   26    47        ECHO                                                     '%0A'
   27    48        INIT_FCALL                                               'base64_encode'
         49        SEND_VAR                                                 !5
         50        DO_ICALL                                         $25     
         51        ECHO                                                     $25
   28    52        INIT_FCALL_BY_NAME                                       'openssl_decrypt'
   29    53        SEND_VAR_EX                                              !4
         54        SEND_VAR_EX                                              !0
         55        SEND_VAR_EX                                              !2
   32    56        FETCH_CONSTANT                                   ~26     'OPENSSL_RAW_DATA'
         57        SEND_VAL_EX                                              ~26
   29    58        SEND_VAR_EX                                              !1
         59        SEND_VAR_EX                                              !5
         60        DO_FCALL                                      0  $27     
   28    61        ASSIGN                                                   !7, $27
   36    62        TYPE_CHECK                                    4          !7
         63      > JMPZ                                                     ~29, ->74
   37    64    >   NEW                                              $30     'Exception'
         65        INIT_FCALL                                               'sprintf'
   38    66        SEND_VAL                                                 'OpenSSL+error%3A+%25s'
         67        INIT_FCALL_BY_NAME                                       'openssl_error_string'
         68        DO_FCALL                                      0  $31     
         69        SEND_VAR                                                 $31
         70        DO_ICALL                                         $32     
         71        SEND_VAR_NO_REF_EX                                       $32
         72        DO_FCALL                                      0          
         73      > THROW                                         0          $30
   41    74    >   INIT_FCALL                                               'printf'
         75        SEND_VAL                                                 'Decryption+%25s%0A'
         76        IS_IDENTICAL                                             !3, !7
         77      > JMPZ                                                     ~34, ->80
         78    >   QM_ASSIGN                                        ~35     'Ok'
         79      > JMP                                                      ->81
         80    >   QM_ASSIGN                                        ~35     'Failed'
         81    >   SEND_VAL                                                 ~35
         82        DO_ICALL                                                 
         83      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.59 ms | 1400 KiB | 25 Q