3v4l.org

run code in 300+ PHP versions simultaneously
<?php const CIPHER = MCRYPT_RIJNDAEL_128; const KEY_BYTE_SIZE = 16; const CIPHER_MODE = 'cbc'; const HASH_FUNCTION = 'sha256'; const MAC_BYTE_SIZE = 32; const ENCRYPTION_INFO = 'PIPS|KeyForEncryption'; const AUTHENTICATION_INFO = 'PIPS|KeyForAuthentication'; $key = base64_decode('wdmd3XIhnOAelom4Y8yPbw=='); $ekey = HKDF(HASH_FUNCTION, $key, KEY_BYTE_SIZE, ENCRYPTION_INFO); //print "$ekey\n"; print urlsafe_b64encode($ekey) . "\n"; //$ivsize = mcrypt_get_iv_size(CIPHER, CIPHER_MODE); //if ($ivsize === FALSE || $ivsize <= 0) { // throw new CannotPerformOperationException(); //} $ivsize= 16; $iv = SecureRandom($ivsize); print urlsafe_b64encode($iv) . "\n"; print urlsafe_b64encode(PlainEncrypt('It is a kitten', $ekey, $iv)); function urlsafe_b64encode($string) { $data = base64_encode($string); $data = str_replace(array('+','/','='),array('-','_',''),$data); return $data; } function urlsafe_b64decode($string) { $data = str_replace(array('-','_'),array('+','/'),$string); return base64_decode($data); } function HKDF($hash, $ikm, $length, $info = '', $salt = NULL) { // Find the correct digest length as quickly as we can. $digest_length = MAC_BYTE_SIZE; if ($hash != HASH_FUNCTION) { $digest_length = strlen(hash_hmac($hash, '', '', true)); } // Sanity-check the desired output length. if (empty($length) || !is_int($length) || $length < 0 || $length > 255 * $digest_length) { return CannotPerformOperationException(); } // "if [salt] not provided, is set to a string of HashLen zeroes." if (is_null($salt)) { $salt = str_repeat("\x00", $digest_length); } // HKDF-Extract: // PRK = HMAC-Hash(salt, IKM) // The salt is the HMAC key. $prk = hash_hmac($hash, $ikm, $salt, true); // HKDF-Expand: // This check is useless, but it serves as a reminder to the spec. if (strlen($prk) < $digest_length) { throw new CannotPerformOperationException(); } // T(0) = '' $t = ''; $last_block = ''; for ($block_index = 1; strlen($t) < $length; $block_index++) { // T(i) = HMAC-Hash(PRK, T(i-1) | info | 0x??) $last_block = hash_hmac( $hash, $last_block . $info . chr($block_index), $prk, true ); // T = T(1) | T(2) | T(3) | ... | T(N) $t .= $last_block; } // ORM = first L octets of T $orm = substr($t, 0, $length); if ($orm === FALSE) { throw new CannotPerformOperationException(); } return $orm; } function SecureRandom($octets) { return urlsafe_b64decode('FSDTs5UoRN07CAeB84KVIw'); $random = mcrypt_create_iv($octets, MCRYPT_DEV_URANDOM); if ($random === FALSE) { throw new CannotPerformOperationException(); } else { return $random; } } function PlainEncrypt($plaintext, $key, $iv) { $crypt = mcrypt_module_open(CIPHER, "", CIPHER_MODE, ""); if ($crypt === FALSE) { throw new CannotPerformOperationException(); } // Pad the plaintext to a multiple of the block size. $block = mcrypt_enc_get_block_size($crypt); $pad = $block - (strlen($plaintext) % $block); $plaintext .= str_repeat(chr($pad), $pad); return $pad; $ret = mcrypt_generic_init($crypt, $key, $iv); if ($ret !== 0) { throw new CannotPerformOperationException(); } $ciphertext = mcrypt_generic($crypt, $plaintext); $ret = mcrypt_generic_deinit($crypt); if ($ret !== TRUE) { throw new CannotPerformOperationException(); } $ret = mcrypt_module_close($crypt); if ($ret !== TRUE) { throw new CannotPerformOperationException(); } return $ciphertext; } ?>

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.40.0110.00418.67
8.3.30.0140.00018.84
8.3.20.0080.00020.20
8.3.10.0030.00523.51
8.3.00.0040.00419.38
8.2.170.0100.00322.96
8.2.160.0070.01120.52
8.2.150.0000.00824.18
8.2.140.0080.00024.66
8.2.130.0040.00426.16
8.2.120.0030.00617.50
8.2.110.0100.01022.20
8.2.100.0140.00317.84
8.2.90.0050.00617.73
8.2.80.0000.01017.97
8.2.70.0060.00317.63
8.2.60.0080.00018.04
8.2.50.0060.00318.07
8.2.40.0030.00619.39
8.2.30.0040.00420.61
8.2.20.0060.00317.66
8.2.10.0050.00317.98
8.2.00.0040.00418.11
8.1.270.0080.00023.76
8.1.260.0050.00326.35
8.1.250.0050.00228.09
8.1.240.0000.00823.91
8.1.230.0090.00319.48
8.1.220.0000.00817.74
8.1.210.0000.00818.77
8.1.200.0040.00417.23
8.1.190.0040.00417.36
8.1.180.0040.00418.10
8.1.170.0030.00619.09
8.1.160.0040.00421.99
8.1.150.0030.00618.88
8.1.140.0080.00019.61
8.1.130.0070.00017.74
8.1.120.0050.00317.48
8.1.110.0040.00417.45
8.1.100.0040.00417.48
8.1.90.0080.00017.35
8.1.80.0000.00717.32
8.1.70.0070.00017.48
8.1.60.0060.00317.57
8.1.50.0120.00017.51
8.1.40.0060.00617.50
8.1.30.0000.00817.62
8.1.20.0080.00017.69
8.1.10.0040.00417.46
8.1.00.0000.00917.38
8.0.300.0030.00619.91
8.0.290.0040.00416.75
8.0.280.0070.00018.44
8.0.270.0050.00317.25
8.0.260.0000.00617.16
8.0.250.0000.00717.03
8.0.240.0000.00817.00
8.0.230.0030.00317.04
8.0.220.0070.00016.99
8.0.210.0040.00416.88
8.0.200.0030.00516.96
8.0.190.0000.00816.96
8.0.180.0070.00016.91
8.0.170.0050.00316.95
8.0.160.0000.00716.92
8.0.150.0040.00416.92
8.0.140.0000.01016.86
8.0.130.0030.00313.39
8.0.120.0080.00016.94
8.0.110.0000.00716.98
8.0.100.0050.00217.11
8.0.90.0040.00417.00
8.0.80.0060.01017.04
8.0.70.0030.00516.84
8.0.60.0040.00416.79
8.0.50.0000.00816.88
8.0.30.0110.00716.90
8.0.20.0080.01617.40
8.0.10.0040.00417.13
8.0.00.0070.01216.80
7.4.330.0000.00515.18
7.4.320.0000.00716.53
7.4.300.0000.00616.66
7.4.290.0070.00016.67
7.4.280.0000.00816.54
7.4.270.0070.00016.66
7.4.260.0000.00716.59
7.4.250.0090.00016.63
7.4.240.0040.00316.62
7.4.230.0080.00016.74
7.4.220.0150.00316.70
7.4.210.0060.01316.66
7.4.200.0070.00016.63
7.4.160.0030.01316.68
7.4.150.0110.01117.40
7.4.140.0070.01717.86
7.4.130.0070.01016.81
7.4.120.0140.00916.63
7.4.110.0120.00916.63
7.4.100.0090.00916.59
7.4.90.0120.00916.50
7.4.80.0030.01719.39
7.4.70.0080.01216.66
7.4.60.0070.01016.54
7.4.50.0030.00316.79
7.4.40.0090.00916.79
7.4.30.0130.01016.76
7.4.00.0100.00715.14
7.3.330.0030.00313.50
7.3.320.0030.00313.48
7.3.310.0030.00316.58
7.3.300.0030.00316.43
7.3.290.0070.00016.36
7.3.280.0070.01016.49
7.3.270.0100.01317.40
7.3.260.0080.00816.69
7.3.250.0100.01016.44
7.3.240.0130.00516.44
7.3.230.0120.00616.49
7.3.210.0030.01316.46
7.3.200.0030.01316.43
7.3.190.0150.00916.46
7.3.180.0080.00816.73
7.3.170.0130.00716.50
7.3.160.0070.01016.74
7.3.120.0080.00815.00
7.3.110.0080.00314.69
7.3.100.0060.00914.94
7.3.90.0060.00614.91
7.3.80.0000.01114.97
7.3.70.0040.00714.80
7.3.60.0100.00014.93
7.3.50.0070.00414.94
7.3.40.0030.01014.90
7.3.30.0000.01415.04
7.3.20.0070.00716.82
7.3.10.0030.01316.76
7.3.00.0060.00916.57
7.2.330.0090.00916.59
7.2.320.0110.00816.50
7.2.310.0170.00616.84
7.2.300.0100.01216.86
7.2.290.0120.00616.95
7.2.240.0040.00715.43
7.2.230.0140.00015.18
7.2.220.0090.00315.39
7.2.210.0060.00815.11
7.2.200.0040.01415.30
7.2.190.0030.01015.11
7.2.180.0080.00615.29
7.2.170.0090.00615.33
7.2.160.0030.01214.93
7.2.150.0110.00717.11
7.2.140.0060.00616.95
7.2.130.0000.01216.98
7.2.120.0030.01016.97
7.2.110.0030.01016.86
7.2.100.0100.00616.80
7.2.90.0030.00917.11
7.2.80.0090.00617.05
7.2.70.0110.00716.76
7.2.60.0030.01116.95
7.2.50.0070.00716.88
7.2.40.0060.00916.89
7.2.30.0000.00917.08
7.2.20.0030.01316.99
7.2.10.0110.00616.97
7.2.00.0090.01218.25
7.1.330.0030.01016.02
7.1.320.0070.00716.02
7.1.310.0030.01015.97
7.1.300.0000.01216.00
7.1.290.0070.00715.74
7.1.280.0000.01615.88
7.1.270.0090.00315.67
7.1.260.0060.00615.97
7.1.250.0070.00715.93
7.1.200.0070.00715.88
7.1.100.0000.01218.25
7.1.70.0070.00416.76
7.1.60.0000.02519.43
7.1.50.0040.00717.02
7.1.00.0030.07722.31
7.0.200.0290.00714.45
7.0.60.0070.04020.09
7.0.50.0030.05717.99
7.0.40.0030.04320.36
7.0.30.0000.06020.08
7.0.20.0300.04320.25
7.0.10.0100.09020.16
7.0.00.0070.08720.12
5.6.280.0000.03721.13
5.6.210.0070.08320.75
5.6.200.0100.07718.25
5.6.190.0100.07320.55
5.6.180.0230.06320.41
5.6.170.0300.07320.54
5.6.160.0030.06020.49
5.6.150.0070.07018.38
5.6.140.0070.07018.21
5.6.130.0030.09018.30
5.6.120.0200.07721.06
5.6.110.0200.07721.03
5.6.100.0170.07321.20
5.6.90.0070.07321.05
5.6.80.0070.04320.41
5.5.350.0100.07720.42
5.5.340.0070.04018.05
5.5.330.0030.04320.25
5.5.320.0030.04720.38
5.5.310.0130.04320.37
5.5.300.0100.07318.04
5.5.290.0100.07317.98
5.5.280.0030.05020.87
5.5.270.0070.05020.86
5.5.260.0130.07320.91
5.5.250.0100.07320.76
5.5.240.0130.07720.22

preferences:
49.14 ms | 400 KiB | 5 Q