3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); namespace ParagonIE\BlogExampleCode; /** * Class RSAPKCS1v15 * @package ParagonIE\BlogExampleCode * * @ref https://paragonie.com/blog/2018/04/protecting-rsa-based-protocols-against-adaptive-chosen-ciphertext-attacks */ class RSAPKCS1v15 { /** * @param string $message * @param string $publicKey * * @return array<int, string> * @throws \Exception */ public static function encrypt(string $message, string $publicKey): array { $key = \random_bytes(32); $C = ''; \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)]; } /** * @param string $CHex * @param string $DHex * @param string $privateKey * * @return string * @throws \Exception */ public static function decrypt(string $CHex, string $DHex, string $privateKey): string { $kPrime = \random_bytes(32); $C = \hex2bin($CHex); $D = \hex2bin($DHex); $k = ''; $return = @\openssl_private_decrypt($C, $k, $privateKey); // Do a constant-time swap: $key = self::cswap32($k, (string) $kPrime, $return ); $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 ); } /** * @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'); } /** * @param string $chr * * @return int */ public static function chrToInt(string $chr): int { $chunk = \unpack('C', $chr); return (int) ($chunk[1]); } /** * @param int $int * * @return string */ 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/mStdU
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
-------------------------------------------------------------------------------------
  119     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-----'
  147     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-----'
  157     2        ASSIGN                                                   !2, 'This+is+a+test+message%21'
  158     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
  159    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
  160    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
  161    23        INIT_NS_FCALL_BY_NAME                                    'ParagonIE%5CBlogExampleCode%5Cmicrotime'
         24        SEND_VAL_EX                                              <true>
         25        DO_FCALL                                      0  $24     
         26        ASSIGN                                                   !6, $24
  163    27        INIT_NS_FCALL_BY_NAME                                    'ParagonIE%5CBlogExampleCode%5Cvar_dump'
         28        SEND_VAR_EX                                              !2
         29        SEND_VAR_EX                                              !7
         30        DO_FCALL                                      0          
  164    31        INIT_NS_FCALL_BY_NAME                                    'ParagonIE%5CBlogExampleCode%5Cvar_dump'
         32        SUB                                              ~27     !6, !5
         33        SEND_VAL_EX                                              ~27
         34        DO_FCALL                                      0          
  167    35        ASSIGN                                                   !8, !4
  168    36        INIT_NS_FCALL_BY_NAME                                    'ParagonIE%5CBlogExampleCode%5Chex2bin'
         37        SEND_VAR_EX                                              !3
         38        DO_FCALL                                      0  $30     
         39        ASSIGN                                                   !3, $30
  169    40        INIT_STATIC_METHOD_CALL                                  'ParagonIE%5CBlogExampleCode%5CRSAPKCS1v15', 'intToChr'
  170    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
         47        DO_FCALL                                      0  $36     
  169    48        ASSIGN_DIM                                               !3, 0
  170    49        OP_DATA                                                  $36
  172    50        INIT_NS_FCALL_BY_NAME                                    'ParagonIE%5CBlogExampleCode%5Cbin2hex'
         51        SEND_VAR_EX                                              !3
         52        DO_FCALL                                      0  $37     
         53        ASSIGN                                                   !3, $37
  174    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
  176    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
  177    66  E > > CATCH                                       last         'Exception'
  178    67    >   INIT_NS_FCALL_BY_NAME                                    'ParagonIE%5CBlogExampleCode%5Cmicrotime'
         68        SEND_VAL_EX                                              <true>
         69        DO_FCALL                                      0  $44     
         70        ASSIGN                                                   !6, $44
  179    71        INIT_NS_FCALL_BY_NAME                                    'ParagonIE%5CBlogExampleCode%5Cvar_dump'
         72        SUB                                              ~46     !6, !5
         73        SEND_VAL_EX                                              ~46
         74        DO_FCALL                                      0          
  180    75        INIT_METHOD_CALL                                         !9, 'getMessage'
         76        DO_FCALL                                      0  $48     
         77        IS_IDENTICAL                                             $48, 'Invalid+MAC'
         78      > JMPZ                                                     ~49, ->82
  181    79    >   ECHO                                                     'Got+the+expected+error+message.+No+RSA+hints+given.'
         80        FETCH_CONSTANT                                   ~50     'ParagonIE%5CBlogExampleCode%5CPHP_EOL'
         81        ECHO                                                     ~50
  184    82    >   ASSIGN                                                   !3, !8
  187    83        ASSIGN                                                   !10, !4
  188    84        INIT_NS_FCALL_BY_NAME                                    'ParagonIE%5CBlogExampleCode%5Chex2bin'
         85        SEND_VAR_EX                                              !4
         86        DO_FCALL                                      0  $53     
         87        ASSIGN                                                   !4, $53
  189    88        INIT_STATIC_METHOD_CALL                                  'ParagonIE%5CBlogExampleCode%5CRSAPKCS1v15', 'intToChr'
  190    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
         95        DO_FCALL                                      0  $59     
  189    96        ASSIGN_DIM                                               !4, 0
  190    97        OP_DATA                                                  $59
  192    98        INIT_NS_FCALL_BY_NAME                                    'ParagonIE%5CBlogExampleCode%5Cbin2hex'
         99        SEND_VAR_EX                                              !4
        100        DO_FCALL                                      0  $60     
        101        ASSIGN                                                   !4, $60
  194   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
  196   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
  197   114  E > > CATCH                                       last         'Exception'
  198   115    >   INIT_NS_FCALL_BY_NAME                                    'ParagonIE%5CBlogExampleCode%5Cmicrotime'
        116        SEND_VAL_EX                                              <true>
        117        DO_FCALL                                      0  $67     
        118        ASSIGN                                                   !6, $67
  199   119        INIT_NS_FCALL_BY_NAME                                    'ParagonIE%5CBlogExampleCode%5Cvar_dump'
        120        SUB                                              ~69     !6, !5
        121        SEND_VAL_EX                                              ~69
        122        DO_FCALL                                      0          
  200   123        INIT_METHOD_CALL                                         !9, 'getMessage'
        124        DO_FCALL                                      0  $71     
        125        IS_IDENTICAL                                             $71, 'Invalid+MAC'
        126      > JMPZ                                                     ~72, ->130
  201   127    >   ECHO                                                     'Got+the+expected+error+message.+No+RSA+hints+given.'
        128        FETCH_CONSTANT                                   ~73     'ParagonIE%5CBlogExampleCode%5CPHP_EOL'
        129        ECHO                                                     ~73
  204   130    >   ASSIGN                                                   !4, !10
  205   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/mStdU
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
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   22     2        INIT_FCALL                                               'random_bytes'
          3        SEND_VAL                                                 32
          4        DO_ICALL                                         $8      
          5        ASSIGN                                                   !2, $8
   23     6        ASSIGN                                                   !3, ''
   24     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          
   26    12        INIT_FCALL                                               'random_bytes'
         13        SEND_VAL                                                 16
         14        DO_ICALL                                         $12     
         15        ASSIGN                                                   !4, $12
   27    16        INIT_FCALL_BY_NAME                                       'openssl_encrypt'
   28    17        SEND_VAR_EX                                              !0
   29    18        SEND_VAL_EX                                              'aes-256-ctr'
   28    19        SEND_VAR_EX                                              !2
   31    20        FETCH_CONSTANT                                   ~14     'ParagonIE%5CBlogExampleCode%5COPENSSL_RAW_DATA'
         21        SEND_VAL_EX                                              ~14
   28    22        SEND_VAR_EX                                              !4
         23        DO_FCALL                                      0  $15     
   27    24        ASSIGN                                                   !5, $15
   34    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
   35    33        CONCAT                                           ~20     !6, !4
         34        CONCAT                                           ~21     ~20, !5
         35        ASSIGN                                                   !7, ~21
   36    36        INIT_NS_FCALL_BY_NAME                                    'ParagonIE%5CBlogExampleCode%5Cbin2hex'
         37        SEND_VAR_EX                                              !3
         38        DO_FCALL                                      0  $23     
         39        INIT_ARRAY                                       ~24     $23
         40        INIT_NS_FCALL_BY_NAME                                    'ParagonIE%5CBlogExampleCode%5Cbin2hex'
         41        SEND_VAR_EX                                              !7
         42        DO_FCALL                                      0  $25     
         43        ADD_ARRAY_ELEMENT                                ~24     $25
         44        VERIFY_RETURN_TYPE                                       ~24
         45      > RETURN                                                   ~24
   37    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 = 66, Position 2 = 70
Branch analysis from position: 66
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 70
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mStdU
function name:  decrypt
number of ops:  82
compiled vars:  !0 = $CHex, !1 = $DHex, !2 = $privateKey, !3 = $kPrime, !4 = $C, !5 = $D, !6 = $k, !7 = $return, !8 = $key, !9 = $mac, !10 = $iv, !11 = $cipher, !12 = $recalc
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   49     3        INIT_FCALL                                               'random_bytes'
          4        SEND_VAL                                                 32
          5        DO_ICALL                                         $13     
          6        ASSIGN                                                   !3, $13
   50     7        INIT_FCALL                                               'hex2bin'
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $15     
         10        ASSIGN                                                   !4, $15
   51    11        INIT_FCALL                                               'hex2bin'
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                         $17     
         14        ASSIGN                                                   !5, $17
   52    15        ASSIGN                                                   !6, ''
   53    16        BEGIN_SILENCE                                    ~20     
         17        INIT_FCALL_BY_NAME                                       'openssl_private_decrypt'
         18        SEND_VAR_EX                                              !4
         19        SEND_VAR_EX                                              !6
         20        SEND_VAR_EX                                              !2
         21        DO_FCALL                                      0  $21     
         22        END_SILENCE                                              ~20
         23        ASSIGN                                                   !7, $21
   56    24        INIT_STATIC_METHOD_CALL                                  'cswap32'
         25        SEND_VAR_EX                                              !6
         26        CAST                                          6  ~23     !3
         27        SEND_VAL_EX                                              ~23
         28        SEND_VAR_EX                                              !7
         29        DO_FCALL                                      0  $24     
         30        ASSIGN                                                   !8, $24
   58    31        INIT_NS_FCALL_BY_NAME                                    'ParagonIE%5CBlogExampleCode%5Cmb_substr'
         32        SEND_VAR_EX                                              !5
         33        SEND_VAL_EX                                              0
         34        SEND_VAL_EX                                              32
         35        SEND_VAL_EX                                              '8bit'
         36        DO_FCALL                                      0  $26     
         37        ASSIGN                                                   !9, $26
   59    38        INIT_NS_FCALL_BY_NAME                                    'ParagonIE%5CBlogExampleCode%5Cmb_substr'
         39        SEND_VAR_EX                                              !5
         40        SEND_VAL_EX                                              32
         41        SEND_VAL_EX                                              16
         42        SEND_VAL_EX                                              '8bit'
         43        DO_FCALL                                      0  $28     
         44        ASSIGN                                                   !10, $28
   60    45        INIT_NS_FCALL_BY_NAME                                    'ParagonIE%5CBlogExampleCode%5Cmb_substr'
         46        SEND_VAR_EX                                              !5
         47        SEND_VAL_EX                                              48
         48        SEND_VAL_EX                                              null
         49        SEND_VAL_EX                                              '8bit'
         50        DO_FCALL                                      0  $30     
         51        ASSIGN                                                   !11, $30
   61    52        INIT_FCALL                                               'hash_hmac'
         53        SEND_VAL                                                 'sha256'
         54        CONCAT                                           ~32     !10, !11
         55        SEND_VAL                                                 ~32
         56        SEND_VAR                                                 !8
         57        SEND_VAL                                                 <true>
         58        DO_ICALL                                         $33     
         59        ASSIGN                                                   !12, $33
   62    60        INIT_FCALL                                               'hash_equals'
         61        SEND_VAR                                                 !12
         62        SEND_VAR                                                 !9
         63        DO_ICALL                                         $35     
         64        BOOL_NOT                                         ~36     $35
         65      > JMPZ                                                     ~36, ->70
   63    66    >   NEW                                              $37     'Exception'
         67        SEND_VAL_EX                                              'Invalid+MAC'
         68        DO_FCALL                                      0          
         69      > THROW                                         0          $37
   65    70    >   INIT_FCALL_BY_NAME                                       'openssl_decrypt'
   66    71        SEND_VAR_EX                                              !11
   67    72        SEND_VAL_EX                                              'aes-256-ctr'
   66    73        SEND_VAR_EX                                              !8
   69    74        FETCH_CONSTANT                                   ~39     'ParagonIE%5CBlogExampleCode%5COPENSSL_RAW_DATA'
         75        SEND_VAL_EX                                              ~39
   66    76        SEND_VAR_EX                                              !10
         77        DO_FCALL                                      0  $40     
         78        VERIFY_RETURN_TYPE                                       $40
         79      > RETURN                                                   $40
   72    80*       VERIFY_RETURN_TYPE                                       
         81*     > 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/mStdU
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
-------------------------------------------------------------------------------------
   81     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   83     3        INIT_FCALL                                               'str_repeat'
          4        SEND_VAL                                                 '%00'
          5        SEND_VAL                                                 32
          6        DO_ICALL                                         $6      
          7        ASSIGN_OP                                     8          !0, $6
   84     8        INIT_FCALL                                               'str_repeat'
          9        SEND_VAL                                                 '%00'
         10        SEND_VAL                                                 32
         11        DO_ICALL                                         $8      
         12        ASSIGN_OP                                     8          !1, $8
   87    13        CAST                                          4  ~10     !2
         14        SUB                                              ~11     ~10, 1
         15        BW_AND                                           ~12     ~11, 255
         16        ASSIGN                                                   !3, ~12
   88    17        ASSIGN                                                   !4, ''
   89    18        ASSIGN                                                   !5, 0
         19      > JMP                                                      ->37
   90    20    >   INIT_STATIC_METHOD_CALL                                  'intToChr'
   91    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
         34        DO_FCALL                                      0  $22     
         35        ASSIGN_OP                                     8          !4, $22
   89    36        PRE_INC                                                  !5
         37    >   IS_SMALLER                                               !5, 32
         38      > JMPNZ                                                    ~25, ->20
   94    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
   95    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/mStdU
function name:  chrToInt
number of ops:  12
compiled var

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.27 ms | 1428 KiB | 31 Q