3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); namespace ParagonIE\BlogExampleCode; /** * Implements encryption RSA with PKCS1v1.5 padding * using the Anti-BB'98 dance. * * @ref https://paragonie.com/b/_8qH-xPuGPUoSSsc */ class RSAPKCS1v15 { public static function encrypt(string $message, string $publicKey): array { $key = \random_bytes(32); $C = ''; // This defaults to PKCS1v1.5: \openssl_public_encrypt($key, $C, $publicKey); $iv = \random_bytes(16); $cipher = \openssl_encrypt( $message, 'aes-256-ctr', $key, OPENSSL_RAW_DATA, $iv ); $mac = \hash_hmac('sha256', $iv . $cipher, $key, true); $D = $mac . $iv . $cipher; return [\bin2hex($C), \bin2hex($D)]; } public static function decrypt(string $CHex, string $DHex, string $privateKey): string { $kPrime = \random_bytes(32); $C = \hex2bin($CHex); $D = \hex2bin($DHex); $k = ''; $success = \openssl_private_decrypt($C, $k, $privateKey); // Do a constant-time swap: $key = self::cswap32($k, (string) $kPrime, $success); $mac = \mb_substr($D, 0, 32, '8bit'); $iv = \mb_substr($D, 32, 16, '8bit'); $cipher = \mb_substr($D, 48, null, '8bit'); $recalc = \hash_hmac('sha256', $iv . $cipher, $key, true); if (!\hash_equals($recalc, $mac)) { throw new \Exception('Invalid MAC'); } return \openssl_decrypt( $cipher, 'aes-256-ctr', $key, OPENSSL_RAW_DATA, $iv ); } /** * Branch-less, timing safe version of * $A = ($switch === 0 ? $A : $B); * * @param string $A * @param string $B * @param bool $success * @return string */ public static function cswap32(string $A, string $B, bool $success): string { $A .= \str_repeat("\x00", 32); $B .= \str_repeat("\x00", 32); /** @var int $mask 0 if $success is true, otherwise 255 */ $mask = (((int) $success) - 1) & 0xff; $C = ''; for ($i = 0; $i < 32; ++$i) { $C .= self::intToChr( (self::chrToInt($A[$i]) ^ self::chrToInt($B[$i])) & $mask ); } return (string) mb_substr($A ^ $C, 0, 32, '8bit'); } public static function chrToInt(string $chr): int { $chunk = \unpack('C', $chr); return (int) ($chunk[1]); } public static function intToChr(int $int): string { return \pack('C', $int); } } $private_key = '-----BEGIN RSA PRIVATE KEY----- MIIEowIBAAKCAQEAyaTgTt53ph3p5GHgwoGWwz5hRfWXSQA08NCOwe0FEgALWos9 GCjNFCd723nCHxBtN1qd74MSh/uN88JPIbwxKheDp4kxo4YMN5trPaF0e9G6Bj1N 02HnanxFLW+gmLbgYO/SZYfWF/M8yLBcu5Y1Ot0ZxDDDXS9wIQTtBE0ne3YbxgZJ AZTU5XqyQ1DxdzYyC5lF6yBaR5UQtCYTnXAApVRuUI2Sd6L1E2vl9bSBumZ5IpNx kRnAwIMjeTJB/0AIELh0mE5vwdihOCbdV6alUyhKC1+1w/FW6HWcp/JG1kKC8DPI idZ78Bbqv9YFzkAbNni5eSBOsXVBKG78Zsc8owIDAQABAoIBAF22jLDa34yKdns3 qfd7to+C3D5hRzAcMn6Azvf9qc+VybEI6RnjTHxDZWK5EajSP4/sQ15e8ivUk0Jo WdJ53feL+hnQvwsab28gghSghrxM2kGwGA1XgO+SVawqJt8SjvE+Q+//01ZKK0Oy A0cDJjX3L9RoPUN/moMeAPFw0hqkFEhm72GSVCEY1eY+cOXmL3icxnsnlUD//SS9 q33RxF2y5oiW1edqcRqhW/7L1yYMbxHFUcxWh8WUwjn1AAhoCOUzF8ZB+0X/PPh+ 1nYoq6xwqL0ZKDwrQ8SDhW/rNDLeO9gic5rl7EetRQRbFvsZ40AdsX2wU+lWFUkB 42AjuoECgYEA5z/CXqDFfZ8MXCPAOeui8y5HNDtu30aR+HOXsBDnRI8huXsGND04 FfmXR7nkghr08fFVDmE4PeKUk810YJb+IAJo8wrOZ0682n6yEMO58omqKin+iIUV rPXLSLo5CChrqw2J4vgzolzPw3N5I8FJdLomb9FkrV84H+IviPIylyECgYEA3znw AG29QX6ATEfFpGVOcogorHCntd4niaWCq5ne5sFL+EwLeVc1zD9yj1axcDelICDZ xCZynU7kDnrQcFkT0bjH/gC8Jk3v7XT9l1UDDqC1b7rm/X5wFIZ/rmNa1rVZhL1o /tKx5tvM2syJ1q95v7NdygFIEIW+qbIKbc6Wz0MCgYBsUZdQD+qx/xAhELX364I2 epTryHMUrs+tGygQVrqdiJX5dcDgM1TUJkdQV6jLsKjPs4Vt6OgZRMrnuLMsk02R 3M8gGQ25ok4f4nyyEZxGGWnVujn55KzUiYWhGWmhgp18UCkoYa59/Q9ss+gocV9h B9j9Q43vD80QUjiF4z0DQQKBgC7XQX1VibkMim93QAnXGDcAS0ij+w02qKVBjcHk b9mMBhz8GAxGOIu7ZJafYmxhwMyVGB0I1FQeEczYCJUKnBYN6Clsjg6bnBT/z5bJ x/Jx1qCzX3Uh6vLjpjc5sf4L39Tyye1u2NXQmZPwB5x9BdcsFConSq/s4K1LJtUT 3KFxAoGBANGcQ8nObi3m4wROyKrkCWcWxFFMnpwxv0pW727Hn9wuaOs4UbesCnwm pcMTfzGUDuzYXCtAq2pJl64HG6wsdkWmjBTJEpm6b9ibOBN3qFV2zQ0HyyKlMWxI uVSj9gOo61hF7UH9XB6R4HRdlpBOuIbgAWZ46dkj9/HM9ovdP0Iy -----END RSA PRIVATE KEY-----'; $public_key = '-----BEGIN PUBLIC KEY----- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyaTgTt53ph3p5GHgwoGW wz5hRfWXSQA08NCOwe0FEgALWos9GCjNFCd723nCHxBtN1qd74MSh/uN88JPIbwx KheDp4kxo4YMN5trPaF0e9G6Bj1N02HnanxFLW+gmLbgYO/SZYfWF/M8yLBcu5Y1 Ot0ZxDDDXS9wIQTtBE0ne3YbxgZJAZTU5XqyQ1DxdzYyC5lF6yBaR5UQtCYTnXAA pVRuUI2Sd6L1E2vl9bSBumZ5IpNxkRnAwIMjeTJB/0AIELh0mE5vwdihOCbdV6al UyhKC1+1w/FW6HWcp/JG1kKC8DPIidZ78Bbqv9YFzkAbNni5eSBOsXVBKG78Zsc8 owIDAQAB -----END PUBLIC KEY-----'; $in = 'This is a test message!'; list ($C, $D) = RSAPKCS1v15::encrypt($in, $public_key); $start = $end = microtime(true); $out = RSAPKCS1v15::decrypt($C, $D, $private_key); $end = microtime(true); var_dump($in, $out); var_dump($end - $start); // Flip the bits in one character of C to force an error $Corig = $D; $C = hex2bin($C); $C[0] = RSAPKCS1v15::intToChr( RSAPKCS1v15::chrToInt($C[0]) ^ 0xff ); $C = bin2hex($C); $start = $end = microtime(true); try { $out = RSAPKCS1v15::decrypt($C, $D, $private_key); } catch (\Exception $ex) { $end = microtime(true); var_dump($end - $start); if ($ex->getMessage() === 'Invalid MAC') { echo 'Got the expected error message. No RSA hints given.', PHP_EOL; } } $C = $Corig; // Flip the bits in one character of D to force an error $Dorig = $D; $D = hex2bin($D); $D[0] = RSAPKCS1v15::intToChr( RSAPKCS1v15::chrToInt($D[0]) ^ 0xff ); $D = bin2hex($D); $start = $end = microtime(true); try { $out = RSAPKCS1v15::decrypt($C, $D, $private_key); } catch (\Exception $ex) { $end = microtime(true); var_dump($end - $start); if ($ex->getMessage() === 'Invalid MAC') { echo 'Got the expected error message. No RSA hints given.', PHP_EOL; } } $D = $Dorig;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 82
Branch analysis from position: 82
1 jumps found. (Code = 42) Position 1 = 130
Branch analysis from position: 130
1 jumps found. (Code = 62) Position 1 = -2
Found catch point at position: 66
Branch analysis from position: 66
2 jumps found. (Code = 107) Position 1 = 67, Position 2 = -2
Branch analysis from position: 67
2 jumps found. (Code = 43) Position 1 = 79, Position 2 = 82
Branch analysis from position: 79
1 jumps found. (Code = 42) Position 1 = 130
Branch analysis from position: 130
Branch analysis from position: 82
Found catch point at position: 114
Branch analysis from position: 114
2 jumps found. (Code = 107) Position 1 = 115, Position 2 = -2
Branch analysis from position: 115
2 jumps found. (Code = 43) Position 1 = 127, Position 2 = 130
Branch analysis from position: 127
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 130
filename:       /in/k4c0tj
function name:  (null)
number of ops:  132
compiled vars:  !0 = $private_key, !1 = $public_key, !2 = $in, !3 = $C, !4 = $D, !5 = $start, !6 = $end, !7 = $out, !8 = $Corig, !9 = $ex, !10 = $Dorig
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   98     0  E >   ASSIGN                                                   !0, '-----BEGIN+RSA+PRIVATE+KEY-----%0AMIIEowIBAAKCAQEAyaTgTt53ph3p5GHgwoGWwz5hRfWXSQA08NCOwe0FEgALWos9%0AGCjNFCd723nCHxBtN1qd74MSh%2FuN88JPIbwxKheDp4kxo4YMN5trPaF0e9G6Bj1N%0A02HnanxFLW%2BgmLbgYO%2FSZYfWF%2FM8yLBcu5Y1Ot0ZxDDDXS9wIQTtBE0ne3YbxgZJ%0AAZTU5XqyQ1DxdzYyC5lF6yBaR5UQtCYTnXAApVRuUI2Sd6L1E2vl9bSBumZ5IpNx%0AkRnAwIMjeTJB%2F0AIELh0mE5vwdihOCbdV6alUyhKC1%2B1w%2FFW6HWcp%2FJG1kKC8DPI%0AidZ78Bbqv9YFzkAbNni5eSBOsXVBKG78Zsc8owIDAQABAoIBAF22jLDa34yKdns3%0Aqfd7to%2BC3D5hRzAcMn6Azvf9qc%2BVybEI6RnjTHxDZWK5EajSP4%2FsQ15e8ivUk0Jo%0AWdJ53feL%2BhnQvwsab28gghSghrxM2kGwGA1XgO%2BSVawqJt8SjvE%2BQ%2B%2F%2F01ZKK0Oy%0AA0cDJjX3L9RoPUN%2FmoMeAPFw0hqkFEhm72GSVCEY1eY%2BcOXmL3icxnsnlUD%2F%2FSS9%0Aq33RxF2y5oiW1edqcRqhW%2F7L1yYMbxHFUcxWh8WUwjn1AAhoCOUzF8ZB%2B0X%2FPPh%2B%0A1nYoq6xwqL0ZKDwrQ8SDhW%2FrNDLeO9gic5rl7EetRQRbFvsZ40AdsX2wU%2BlWFUkB%0A42AjuoECgYEA5z%2FCXqDFfZ8MXCPAOeui8y5HNDtu30aR%2BHOXsBDnRI8huXsGND04%0AFfmXR7nkghr08fFVDmE4PeKUk810YJb%2BIAJo8wrOZ0682n6yEMO58omqKin%2BiIUV%0ArPXLSLo5CChrqw2J4vgzolzPw3N5I8FJdLomb9FkrV84H%2BIviPIylyECgYEA3znw%0AAG29QX6ATEfFpGVOcogorHCntd4niaWCq5ne5sFL%2BEwLeVc1zD9yj1axcDelICDZ%0AxCZynU7kDnrQcFkT0bjH%2FgC8Jk3v7XT9l1UDDqC1b7rm%2FX5wFIZ%2FrmNa1rVZhL1o%0A%2FtKx5tvM2syJ1q95v7NdygFIEIW%2BqbIKbc6Wz0MCgYBsUZdQD%2Bqx%2FxAhELX364I2%0AepTryHMUrs%2BtGygQVrqdiJX5dcDgM1TUJkdQV6jLsKjPs4Vt6OgZRMrnuLMsk02R%0A3M8gGQ25ok4f4nyyEZxGGWnVujn55KzUiYWhGWmhgp18UCkoYa59%2FQ9ss%2BgocV9h%0AB9j9Q43vD80QUjiF4z0DQQKBgC7XQX1VibkMim93QAnXGDcAS0ij%2Bw02qKVBjcHk%0Ab9mMBhz8GAxGOIu7ZJafYmxhwMyVGB0I1FQeEczYCJUKnBYN6Clsjg6bnBT%2Fz5bJ%0Ax%2FJx1qCzX3Uh6vLjpjc5sf4L39Tyye1u2NXQmZPwB5x9BdcsFConSq%2Fs4K1LJtUT%0A3KFxAoGBANGcQ8nObi3m4wROyKrkCWcWxFFMnpwxv0pW727Hn9wuaOs4UbesCnwm%0ApcMTfzGUDuzYXCtAq2pJl64HG6wsdkWmjBTJEpm6b9ibOBN3qFV2zQ0HyyKlMWxI%0AuVSj9gOo61hF7UH9XB6R4HRdlpBOuIbgAWZ46dkj9%2FHM9ovdP0Iy%0A-----END+RSA+PRIVATE+KEY-----'
  126     1        ASSIGN                                                   !1, '-----BEGIN+PUBLIC+KEY-----%0AMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyaTgTt53ph3p5GHgwoGW%0Awz5hRfWXSQA08NCOwe0FEgALWos9GCjNFCd723nCHxBtN1qd74MSh%2FuN88JPIbwx%0AKheDp4kxo4YMN5trPaF0e9G6Bj1N02HnanxFLW%2BgmLbgYO%2FSZYfWF%2FM8yLBcu5Y1%0AOt0ZxDDDXS9wIQTtBE0ne3YbxgZJAZTU5XqyQ1DxdzYyC5lF6yBaR5UQtCYTnXAA%0ApVRuUI2Sd6L1E2vl9bSBumZ5IpNxkRnAwIMjeTJB%2F0AIELh0mE5vwdihOCbdV6al%0AUyhKC1%2B1w%2FFW6HWcp%2FJG1kKC8DPIidZ78Bbqv9YFzkAbNni5eSBOsXVBKG78Zsc8%0AowIDAQAB%0A-----END+PUBLIC+KEY-----'
  136     2        ASSIGN                                                   !2, 'This+is+a+test+message%21'
  137     3        INIT_STATIC_METHOD_CALL                                  'ParagonIE%5CBlogExampleCode%5CRSAPKCS1v15', 'encrypt'
          4        SEND_VAR                                                 !2
          5        SEND_VAR                                                 !1
          6        DO_FCALL                                      0  $14     
          7        FETCH_LIST_R                                     $15     $14, 0
          8        ASSIGN                                                   !3, $15
          9        FETCH_LIST_R                                     $17     $14, 1
         10        ASSIGN                                                   !4, $17
         11        FREE                                                     $14
  138    12        INIT_NS_FCALL_BY_NAME                                    'ParagonIE%5CBlogExampleCode%5Cmicrotime'
         13        SEND_VAL_EX                                              <true>
         14        DO_FCALL                                      0  $19     
         15        ASSIGN                                           ~20     !6, $19
         16        ASSIGN                                                   !5, ~20
  139    17        INIT_STATIC_METHOD_CALL                                  'ParagonIE%5CBlogExampleCode%5CRSAPKCS1v15', 'decrypt'
         18        SEND_VAR                                                 !3
         19        SEND_VAR                                                 !4
         20        SEND_VAR                                                 !0
         21        DO_FCALL                                      0  $22     
         22        ASSIGN                                                   !7, $22
  140    23        INIT_NS_FCALL_BY_NAME                                    'ParagonIE%5CBlogExampleCode%5Cmicrotime'
         24        SEND_VAL_EX                                              <true>
         25        DO_FCALL                                      0  $24     
         26        ASSIGN                                                   !6, $24
  142    27        INIT_NS_FCALL_BY_NAME                                    'ParagonIE%5CBlogExampleCode%5Cvar_dump'
         28        SEND_VAR_EX                                              !2
         29        SEND_VAR_EX                                              !7
         30        DO_FCALL                                      0          
  143    31        INIT_NS_FCALL_BY_NAME                                    'ParagonIE%5CBlogExampleCode%5Cvar_dump'
         32        SUB                                              ~27     !6, !5
         33        SEND_VAL_EX                                              ~27
         34        DO_FCALL                                      0          
  146    35        ASSIGN                                                   !8, !4
  147    36        INIT_NS_FCALL_BY_NAME                                    'ParagonIE%5CBlogExampleCode%5Chex2bin'
         37        SEND_VAR_EX                                              !3
         38        DO_FCALL                                      0  $30     
         39        ASSIGN                                                   !3, $30
  148    40        INIT_STATIC_METHOD_CALL                                  'ParagonIE%5CBlogExampleCode%5CRSAPKCS1v15', 'intToChr'
  149    41        INIT_STATIC_METHOD_CALL                                  'ParagonIE%5CBlogExampleCode%5CRSAPKCS1v15', 'chrToInt'
         42        FETCH_DIM_R                                      ~33     !3, 0
         43        SEND_VAL                                                 ~33
         44        DO_FCALL                                      0  $34     
         45        BW_XOR                                           ~35     $34, 255
         46        SEND_VAL                                                 ~35
  148    47        DO_FCALL                                      0  $36     
         48        ASSIGN_DIM                                               !3, 0
  149    49        OP_DATA                                                  $36
  151    50        INIT_NS_FCALL_BY_NAME                                    'ParagonIE%5CBlogExampleCode%5Cbin2hex'
         51        SEND_VAR_EX                                              !3
         52        DO_FCALL                                      0  $37     
         53        ASSIGN                                                   !3, $37
  153    54        INIT_NS_FCALL_BY_NAME                                    'ParagonIE%5CBlogExampleCode%5Cmicrotime'
         55        SEND_VAL_EX                                              <true>
         56        DO_FCALL                                      0  $39     
         57        ASSIGN                                           ~40     !6, $39
         58        ASSIGN                                                   !5, ~40
  155    59        INIT_STATIC_METHOD_CALL                                  'ParagonIE%5CBlogExampleCode%5CRSAPKCS1v15', 'decrypt'
         60        SEND_VAR                                                 !3
         61        SEND_VAR                                                 !4
         62        SEND_VAR                                                 !0
         63        DO_FCALL                                      0  $42     
         64        ASSIGN                                                   !7, $42
         65      > JMP                                                      ->82
  156    66  E > > CATCH                                       last         'Exception'
  157    67    >   INIT_NS_FCALL_BY_NAME                                    'ParagonIE%5CBlogExampleCode%5Cmicrotime'
         68        SEND_VAL_EX                                              <true>
         69        DO_FCALL                                      0  $44     
         70        ASSIGN                                                   !6, $44
  158    71        INIT_NS_FCALL_BY_NAME                                    'ParagonIE%5CBlogExampleCode%5Cvar_dump'
         72        SUB                                              ~46     !6, !5
         73        SEND_VAL_EX                                              ~46
         74        DO_FCALL                                      0          
  159    75        INIT_METHOD_CALL                                         !9, 'getMessage'
         76        DO_FCALL                                      0  $48     
         77        IS_IDENTICAL                                             $48, 'Invalid+MAC'
         78      > JMPZ                                                     ~49, ->82
  160    79    >   ECHO                                                     'Got+the+expected+error+message.+No+RSA+hints+given.'
         80        FETCH_CONSTANT                                   ~50     'ParagonIE%5CBlogExampleCode%5CPHP_EOL'
         81        ECHO                                                     ~50
  163    82    >   ASSIGN                                                   !3, !8
  166    83        ASSIGN                                                   !10, !4
  167    84        INIT_NS_FCALL_BY_NAME                                    'ParagonIE%5CBlogExampleCode%5Chex2bin'
         85        SEND_VAR_EX                                              !4
         86        DO_FCALL                                      0  $53     
         87        ASSIGN                                                   !4, $53
  168    88        INIT_STATIC_METHOD_CALL                                  'ParagonIE%5CBlogExampleCode%5CRSAPKCS1v15', 'intToChr'
  169    89        INIT_STATIC_METHOD_CALL                                  'ParagonIE%5CBlogExampleCode%5CRSAPKCS1v15', 'chrToInt'
         90        FETCH_DIM_R                                      ~56     !4, 0
         91        SEND_VAL                                                 ~56
         92        DO_FCALL                                      0  $57     
         93        BW_XOR                                           ~58     $57, 255
         94        SEND_VAL                                                 ~58
  168    95        DO_FCALL                                      0  $59     
         96        ASSIGN_DIM                                               !4, 0
  169    97        OP_DATA                                                  $59
  171    98        INIT_NS_FCALL_BY_NAME                                    'ParagonIE%5CBlogExampleCode%5Cbin2hex'
         99        SEND_VAR_EX                                              !4
        100        DO_FCALL                                      0  $60     
        101        ASSIGN                                                   !4, $60
  173   102        INIT_NS_FCALL_BY_NAME                                    'ParagonIE%5CBlogExampleCode%5Cmicrotime'
        103        SEND_VAL_EX                                              <true>
        104        DO_FCALL                                      0  $62     
        105        ASSIGN                                           ~63     !6, $62
        106        ASSIGN                                                   !5, ~63
  175   107        INIT_STATIC_METHOD_CALL                                  'ParagonIE%5CBlogExampleCode%5CRSAPKCS1v15', 'decrypt'
        108        SEND_VAR                                                 !3
        109        SEND_VAR                                                 !4
        110        SEND_VAR                                                 !0
        111        DO_FCALL                                      0  $65     
        112        ASSIGN                                                   !7, $65
        113      > JMP                                                      ->130
  176   114  E > > CATCH                                       last         'Exception'
  177   115    >   INIT_NS_FCALL_BY_NAME                                    'ParagonIE%5CBlogExampleCode%5Cmicrotime'
        116        SEND_VAL_EX                                              <true>
        117        DO_FCALL                                      0  $67     
        118        ASSIGN                                                   !6, $67
  178   119        INIT_NS_FCALL_BY_NAME                                    'ParagonIE%5CBlogExampleCode%5Cvar_dump'
        120        SUB                                              ~69     !6, !5
        121        SEND_VAL_EX                                              ~69
        122        DO_FCALL                                      0          
  179   123        INIT_METHOD_CALL                                         !9, 'getMessage'
        124        DO_FCALL                                      0  $71     
        125        IS_IDENTICAL                                             $71, 'Invalid+MAC'
        126      > JMPZ                                                     ~72, ->130
  180   127    >   ECHO                                                     'Got+the+expected+error+message.+No+RSA+hints+given.'
        128        FETCH_CONSTANT                                   ~73     'ParagonIE%5CBlogExampleCode%5CPHP_EOL'
        129        ECHO                                                     ~73
  183   130    >   ASSIGN                                                   !4, !10
  184   131      > RETURN                                                   1

Class ParagonIE\BlogExampleCode\RSAPKCS1v15:
Function encrypt:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/k4c0tj
function name:  encrypt
number of ops:  48
compiled vars:  !0 = $message, !1 = $publicKey, !2 = $key, !3 = $C, !4 = $iv, !5 = $cipher, !6 = $mac, !7 = $D
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   15     2        INIT_FCALL                                               'random_bytes'
          3        SEND_VAL                                                 32
          4        DO_ICALL                                         $8      
          5        ASSIGN                                                   !2, $8
   16     6        ASSIGN                                                   !3, ''
   19     7        INIT_FCALL_BY_NAME                                       'openssl_public_encrypt'
          8        SEND_VAR_EX                                              !2
          9        SEND_VAR_EX                                              !3
         10        SEND_VAR_EX                                              !1
         11        DO_FCALL                                      0          
   21    12        INIT_FCALL                                               'random_bytes'
         13        SEND_VAL                                                 16
         14        DO_ICALL                                         $12     
         15        ASSIGN                                                   !4, $12
   22    16        INIT_FCALL_BY_NAME                                       'openssl_encrypt'
   23    17        SEND_VAR_EX                                              !0
   24    18        SEND_VAL_EX                                              'aes-256-ctr'
   23    19        SEND_VAR_EX                                              !2
   26    20        FETCH_CONSTANT                                   ~14     'ParagonIE%5CBlogExampleCode%5COPENSSL_RAW_DATA'
         21        SEND_VAL_EX                                              ~14
   23    22        SEND_VAR_EX                                              !4
   22    23        DO_FCALL                                      0  $15     
         24        ASSIGN                                                   !5, $15
   29    25        INIT_FCALL                                               'hash_hmac'
         26        SEND_VAL                                                 'sha256'
         27        CONCAT                                           ~17     !4, !5
         28        SEND_VAL                                                 ~17
         29        SEND_VAR                                                 !2
         30        SEND_VAL                                                 <true>
         31        DO_ICALL                                         $18     
         32        ASSIGN                                                   !6, $18
   30    33        CONCAT                                           ~20     !6, !4
         34        CONCAT                                           ~21     ~20, !5
         35        ASSIGN                                                   !7, ~21
   31    36        INIT_FCALL                                               'bin2hex'
         37        SEND_VAR                                                 !3
         38        DO_ICALL                                         $23     
         39        INIT_ARRAY                                       ~24     $23
         40        INIT_FCALL                                               'bin2hex'
         41        SEND_VAR                                                 !7
         42        DO_ICALL                                         $25     
         43        ADD_ARRAY_ELEMENT                                ~24     $25
         44        VERIFY_RETURN_TYPE                                       ~24
         45      > RETURN                                                   ~24
   32    46*       VERIFY_RETURN_TYPE                                       
         47*     > RETURN                                                   null

End of function encrypt

Function decrypt:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 64, Position 2 = 68
Branch analysis from position: 64
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 68
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/k4c0tj
function name:  decrypt
number of ops:  80
compiled vars:  !0 = $CHex, !1 = $DHex, !2 = $privateKey, !3 = $kPrime, !4 = $C, !5 = $D, !6 = $k, !7 = $success, !8 = $key, !9 = $mac, !10 = $iv, !11 = $cipher, !12 = $recalc
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   36     3        INIT_FCALL                                               'random_bytes'
          4        SEND_VAL                                                 32
          5        DO_ICALL                                         $13     
          6        ASSIGN                                                   !3, $13
   37     7        INIT_FCALL                                               'hex2bin'
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $15     
         10        ASSIGN                                                   !4, $15
   38    11        INIT_FCALL                                               'hex2bin'
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                         $17     
         14        ASSIGN                                                   !5, $17
   39    15        ASSIGN                                                   !6, ''
   40    16        INIT_FCALL_BY_NAME                                       'openssl_private_decrypt'
         17        SEND_VAR_EX                                              !4
         18        SEND_VAR_EX                                              !6
         19        SEND_VAR_EX                                              !2
         20        DO_FCALL                                      0  $20     
         21        ASSIGN                                                   !7, $20
   43    22        INIT_STATIC_METHOD_CALL                                  'cswap32'
         23        SEND_VAR_EX                                              !6
         24        CAST                                          6  ~22     !3
         25        SEND_VAL_EX                                              ~22
         26        SEND_VAR_EX                                              !7
         27        DO_FCALL                                      0  $23     
         28        ASSIGN                                                   !8, $23
   45    29        INIT_FCALL                                               'mb_substr'
         30        SEND_VAR                                                 !5
         31        SEND_VAL                                                 0
         32        SEND_VAL                                                 32
         33        SEND_VAL                                                 '8bit'
         34        DO_ICALL                                         $25     
         35        ASSIGN                                                   !9, $25
   46    36        INIT_FCALL                                               'mb_substr'
         37        SEND_VAR                                                 !5
         38        SEND_VAL                                                 32
         39        SEND_VAL                                                 16
         40        SEND_VAL                                                 '8bit'
         41        DO_ICALL                                         $27     
         42        ASSIGN                                                   !10, $27
   47    43        INIT_FCALL                                               'mb_substr'
         44        SEND_VAR                                                 !5
         45        SEND_VAL                                                 48
         46        SEND_VAL                                                 null
         47        SEND_VAL                                                 '8bit'
         48        DO_ICALL                                         $29     
         49        ASSIGN                                                   !11, $29
   48    50        INIT_FCALL                                               'hash_hmac'
         51        SEND_VAL                                                 'sha256'
         52        CONCAT                                           ~31     !10, !11
         53        SEND_VAL                                                 ~31
         54        SEND_VAR                                                 !8
         55        SEND_VAL                                                 <true>
         56        DO_ICALL                                         $32     
         57        ASSIGN                                                   !12, $32
   49    58        INIT_FCALL                                               'hash_equals'
         59        SEND_VAR                                                 !12
         60        SEND_VAR                                                 !9
         61        DO_ICALL                                         $34     
         62        BOOL_NOT                                         ~35     $34
         63      > JMPZ                                                     ~35, ->68
   50    64    >   NEW                                              $36     'Exception'
         65        SEND_VAL_EX                                              'Invalid+MAC'
         66        DO_FCALL                                      0          
         67      > THROW                                         0          $36
   52    68    >   INIT_FCALL_BY_NAME                                       'openssl_decrypt'
   53    69        SEND_VAR_EX                                              !11
   54    70        SEND_VAL_EX                                              'aes-256-ctr'
   53    71        SEND_VAR_EX                                              !8
   56    72        FETCH_CONSTANT                                   ~38     'ParagonIE%5CBlogExampleCode%5COPENSSL_RAW_DATA'
         73        SEND_VAL_EX                                              ~38
   53    74        SEND_VAR_EX                                              !10
   52    75        DO_FCALL                                      0  $39     
   53    76        VERIFY_RETURN_TYPE                                       $39
         77      > RETURN                                                   $39
   59    78*       VERIFY_RETURN_TYPE                                       
         79*     > RETURN                                                   null

End of function decrypt

Function cswap32:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
2 jumps found. (Code = 44) Position 1 = 39, Position 2 = 20
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 39, Position 2 = 20
Branch analysis from position: 39
Branch analysis from position: 20
filename:       /in/k4c0tj
function name:  cswap32
number of ops:  51
compiled vars:  !0 = $A, !1 = $B, !2 = $success, !3 = $mask, !4 = $C, !5 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   70     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   72     3        INIT_FCALL                                               'str_repeat'
          4        SEND_VAL                                                 '%00'
          5        SEND_VAL                                                 32
          6        DO_ICALL                                         $6      
          7        ASSIGN_OP                                     8          !0, $6
   73     8        INIT_FCALL                                               'str_repeat'
          9        SEND_VAL                                                 '%00'
         10        SEND_VAL                                                 32
         11        DO_ICALL                                         $8      
         12        ASSIGN_OP                                     8          !1, $8
   75    13        CAST                                          4  ~10     !2
         14        SUB                                              ~11     ~10, 1
         15        BW_AND                                           ~12     ~11, 255
         16        ASSIGN                                                   !3, ~12
   77    17        ASSIGN                                                   !4, ''
   78    18        ASSIGN                                                   !5, 0
         19      > JMP                                                      ->37
   79    20    >   INIT_STATIC_METHOD_CALL                                  'intToChr'
   80    21        INIT_STATIC_METHOD_CALL                                  'chrToInt'
         22        CHECK_FUNC_ARG                                           
         23        FETCH_DIM_FUNC_ARG                               $16     !0, !5
         24        SEND_FUNC_ARG                                            $16
         25        DO_FCALL                                      0  $17     
         26        INIT_STATIC_METHOD_CALL                                  'chrToInt'
         27        CHECK_FUNC_ARG                                           
         28        FETCH_DIM_FUNC_ARG                               $18     !1, !5
         29        SEND_FUNC_ARG                                            $18
         30        DO_FCALL                                      0  $19     
         31        BW_XOR                                           ~20     $17, $19
         32        BW_AND                                           ~21     !3, ~20
         33        SEND_VAL_EX                                              ~21
   79    34        DO_FCALL                                      0  $22     
   80    35        ASSIGN_OP                                     8          !4, $22
   78    36        PRE_INC                                                  !5
         37    >   IS_SMALLER                                               !5, 32
         38      > JMPNZ                                                    ~25, ->20
   83    39    >   INIT_NS_FCALL_BY_NAME                                    'ParagonIE%5CBlogExampleCode%5Cmb_substr'
         40        BW_XOR                                           ~26     !0, !4
         41        SEND_VAL_EX                                              ~26
         42        SEND_VAL_EX                                              0
         43        SEND_VAL_EX                                              32
         44        SEND_VAL_EX                                              '8bit'
         45        DO_FCALL                                      0  $27     
         46        CAST                                          6  ~28     $27
         47        VERIFY_RETURN_TYPE                                       ~28
         48      > RETURN                                                   ~28
   84    49*       VERIFY_RETURN_TYPE                                       
         50*     > RETURN                                                   null

End of function cswap32

Function chrtoint:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/k4c0tj
function name:  chrToInt
number of ops:  12
compiled vars:  !0 = $chr, !1 = $chunk
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   86     0  E >   RECV                                             !0      
   88     1        INIT_FCALL  

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.34 ms | 1501 KiB | 22 Q