3v4l.org

run code in 300+ PHP versions simultaneously
<?php function shitmac_xor(string $str, int $with){ $ret = ""; for($i=0,$imax=strlen($str);$i<$imax;++$i){ $ret .= chr( ord($str[$i]) ^ $with ); } return $ret; } function shitmac(string $key, string $message, string $hash_algorithm = "SHA1", int $hash_algorithm_block_size = 64, int $hash_algorithm_output_size = 20){ if(strlen($key) > $hash_algorithm_block_size){ // this is probably a bad idea, but php is doing it anyway. // > RFC 2104 requires that "keys longer than B bytes are first hashed using H" which leads to a confusing pseudo-collision: if the key is longer than the hash block size (e.g. 64 characters for SHA-1), then HMAC(k, m) is computed as HMAC(H(k), m).This property is sometimes raised as a possible weakness of HMAC in password-hashing scenarios: it has been demonstrated that it's possible to find a long ASCII string and a random value whose hash will be also an ASCII string, and both values will produce the same HMAC output. // die("TODO: hash(hash_algo, key"); $key = hash($hash_algorithm, $key, true); } if(strlen($key) < $hash_algorithm_block_size){ // die("TODO: key=str_pad(key,x00,block_size,pad_left"); $key = str_pad($key, $hash_algorithm_block_size, "\x00", STR_PAD_RIGHT); } $o_key_pad = shitmac_xor($key, 0x5C); $i_key_pad = shitmac_xor($key, 0x36); $ret = hash($hash_algorithm, $i_key_pad.$message, true); $ret = hash($hash_algorithm, $o_key_pad . $ret, true); return $ret; } $hash_algorithm = "SHA1"; $hash_algorithm_block_size = 64; $hash_algorithm_output_size = 20; $results=[]; for($i=0;$i<100;++$i){ $key=str_repeat("\x00", $i); $message = "Hello World".random_bytes($i); $hmac = hash_hmac($hash_algorithm, $message, $key, true); $shitmac = shitmac($key, $message, $hash_algorithm, $hash_algorithm_block_size, $hash_algorithm_output_size); if($hmac === $shitmac){ echo "{$i}: success!\n"; }else{ var_dump($i,$hmac,$shitmac); die("ERROR!"); } }

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)
7.4.110.0100.01516.48
7.4.100.0130.00416.61
7.4.90.0090.01216.38
7.4.80.0090.00916.52
7.4.70.0170.00316.41
7.4.60.0060.01316.36
7.4.50.0030.01416.49
7.4.40.0090.01516.42
7.4.30.0110.00716.44
7.4.20.0180.00016.55
7.4.10.0070.01316.28
7.4.00.0030.01416.44
7.3.230.0120.01216.29
7.3.220.0150.00316.40
7.3.210.0040.01816.31
7.3.200.0070.01016.43
7.3.190.0060.01616.21
7.3.180.0100.01016.31
7.3.170.0170.00816.36
7.3.160.0080.01116.36
7.3.150.0040.01316.43
7.3.140.0120.00816.37
7.3.130.0150.00716.54
7.3.120.0060.01116.43
7.3.110.0100.00716.54
7.3.100.0030.01416.54
7.3.90.0110.00516.60
7.3.80.0060.01116.30
7.3.70.0040.01516.31
7.3.60.0060.01016.44
7.3.50.0090.00916.18
7.3.40.0080.00816.30
7.3.30.0000.01716.33
7.3.20.1130.01016.27
7.3.10.0070.01016.36
7.3.00.0130.00816.24
7.2.340.0170.00716.61
7.2.330.0120.00916.65
7.2.320.0060.01416.54
7.2.310.0140.00316.55
7.2.300.0110.01516.54
7.2.290.0040.01616.61
7.2.280.0040.01516.63
7.2.270.0090.00916.65
7.2.260.0150.00316.65
7.2.250.0080.01016.43
7.2.240.0130.00616.65
7.2.230.0190.00016.72
7.2.220.0030.01416.66
7.2.210.0130.00316.53
7.2.200.0080.00816.59
7.2.190.0030.01316.65
7.2.180.0060.01616.50
7.2.170.0110.00816.61
7.2.160.0110.00916.46
7.2.150.0150.00416.73
7.2.140.0070.01116.51
7.2.130.0100.01016.69
7.2.120.0770.01016.44
7.2.110.0090.00916.59
7.2.100.0070.01116.48
7.2.90.0130.00816.54
7.2.80.0120.00616.64
7.2.70.0140.00716.64
7.2.60.0060.01116.49
7.2.50.0120.00416.61
7.2.40.0080.01116.61
7.2.30.0140.00816.59
7.2.20.0140.00616.40
7.2.10.0180.00616.47
7.2.00.0090.00916.64

preferences:
28.9 ms | 403 KiB | 5 Q