3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); define('SODIUM_CRYPTO_RSIGN_SIGBYTES', 96); function sodium_crypto_rsign(string $message, string $sk): string { return sodium_crypto_sign(random_bytes(32) . $message, $sk); } function sodium_crypto_rsign_open(string $sm, string $pk): string { $opened = sodium_crypto_sign_open($sm, $pk); return mb_substr($opened, 32, null, '8bit'); } function sodium_crypto_rsign_detached(string $message, string $sk): string { $random = random_bytes(32); return sodium_crypto_sign_detached($random . $message, $sk) . $random; } function sodium_crypto_rsign_verify_detached(string $signature, string $message, string $pk): bool { $sig = mb_substr($signature, 0, 64, '8bit'); $random = mb_substr($signature, 64, 32, '8bit'); return sodium_crypto_sign_verify_detached($sig, $random . $message, $pk); } /*** TESTS ***/ $kp = sodium_crypto_sign_keypair(); $sk = sodium_crypto_sign_secretkey($kp); $pk = sodium_crypto_sign_publickey($kp); # First test: Does it work? $message = 'This is a test message.'; $signed = sodium_crypto_rsign($message, $sk); $ropen = sodium_crypto_rsign_open($signed, $pk); if (!hash_equals($message, $ropen)) { echo bin2hex($signed), PHP_EOL; echo bin2hex($ropen), PHP_EOL; exit(255); } # Second test: Is it backwards compatible? $random = mb_substr($signed, 64, 32, '8bit'); $open = sodium_crypto_sign_open($signed, $pk); if (!hash_equals($random . $message, $open)) { echo bin2hex($signed), PHP_EOL; echo bin2hex($open), PHP_EOL; exit(255); } # Third test: Detached API $msg2 = 'Cryptography nerds in the kitchen have too much thyme on their hands.'; // Do you feel timing attacked? $sig = sodium_crypto_rsign_detached($msg2, $sk); $len = mb_strlen($sig, '8bit'); if ($len !== SODIUM_CRYPTO_RSIGN_SIGBYTES) { echo 'Expected ', SODIUM_CRYPTO_RSIGN_SIGBYTES, '; got ', $len, '.', PHP_EOL; exit(255); } if (!sodium_crypto_rsign_verify_detached($sig, $msg2, $pk)) { echo 'Invalid signature.', PHP_EOL; exit(255); } $sig2 = sodium_crypto_rsign_detached($msg2, $sk); if (hash_equals($sig, $sig2)) { echo 'RNG Failure.', PHP_EOL; echo bin2hex($sig), PHP_EOL; echo bin2hex($sig2), PHP_EOL; exit(255); } $sigLeft = mb_substr($sig, 0, 64, '8bit'); $sigRight = mb_substr($sig, 64, 32, '8bit'); if (!sodium_crypto_rsign_verify_detached($sigLeft, $sigRight . $msg2, $pk)) { echo 'Invalid signature.', PHP_EOL; exit(255); } echo 'All tests pass!', PHP_EOL; // Two signatures of the same message: var_dump(bin2hex($sig), bin2hex($sig2));

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.60.0300.01525.92
8.3.50.0140.00325.92
8.3.40.0200.01325.92
8.3.30.0210.01425.92
8.3.20.0380.00325.92
8.3.10.0180.01425.92
8.3.00.0240.00825.92
8.2.180.0100.00725.92
8.2.170.0260.01325.92
8.2.160.0300.01525.92
8.2.150.0320.00625.92
8.2.140.0220.01825.92
8.2.130.0350.01025.92
8.2.120.0380.00825.92
8.2.110.0340.01325.92
8.2.100.0330.00825.92
8.2.90.0210.01525.92
8.2.80.0290.00625.92
8.2.70.0250.01125.92
8.2.60.0220.01525.92
8.2.50.0280.01625.92
8.2.40.0260.00925.92
8.2.30.0260.01125.92
8.2.20.0230.01525.92
8.2.10.0270.00625.92
8.2.00.0240.01025.92
8.1.280.0300.00725.92
8.1.270.0330.00725.92
8.1.260.0210.01325.92
8.1.250.0280.00925.92
8.1.240.0280.01025.92
8.1.230.0220.00925.92
8.1.220.0260.00625.92
8.1.210.0150.01525.92
8.1.200.0180.01225.92
8.1.190.0260.00825.92
8.1.180.0260.00425.92
8.1.170.0170.01325.92
8.1.160.0250.00725.92
8.1.150.0310.00925.92
8.1.140.0300.00025.92
8.1.130.0260.01125.92
8.1.120.0230.01025.92
8.1.110.0190.01125.92
8.1.100.0140.01725.92
8.1.90.0270.01025.92
8.1.80.0260.00825.92
8.1.70.0260.00625.92
8.1.60.0310.01225.92
8.1.50.0330.00325.92
8.1.40.0270.00825.92
8.1.30.0230.01325.92
8.1.20.0280.00825.92
8.1.10.0260.01125.92
8.1.00.0330.00625.92
8.0.300.0210.00925.92
8.0.290.0250.00725.92
8.0.280.0210.01425.92
8.0.270.0310.00725.92
8.0.260.0310.00625.92
8.0.250.0150.01525.92
8.0.240.0210.00825.92
8.0.230.0210.00925.92
8.0.220.0280.00425.92
8.0.210.0200.01025.92
8.0.200.0250.00625.92
8.0.190.0220.00825.92
8.0.180.0260.00625.92
8.0.170.0280.00425.92
8.0.160.0220.00925.92
8.0.150.0270.00725.92
8.0.140.0300.00325.92
8.0.130.0240.00625.92
8.0.120.0130.01725.92
8.0.110.0220.00825.92
8.0.100.0320.00625.92
8.0.90.0340.00025.92
8.0.80.0320.00625.92
8.0.70.0210.01425.92
8.0.60.0220.00925.92
8.0.50.0220.00925.92
8.0.30.0310.00325.92
8.0.20.0290.00325.92
8.0.10.0100.01821.55
8.0.00.0190.00621.57
7.4.330.0250.01125.92
7.4.320.0360.00425.92
7.4.300.0250.00725.92
7.4.290.0270.00425.92
7.4.280.0260.00525.92
7.4.270.0250.00425.92
7.4.260.0250.00325.92
7.4.250.0200.00925.92
7.4.240.0290.00425.92
7.4.230.0210.01425.92
7.4.220.0270.00825.92
7.4.210.0230.00625.92
7.4.200.0160.01025.92
7.4.190.0170.01025.92
7.4.180.0220.00725.92
7.4.160.0250.00425.92
7.4.150.0220.00925.92
7.4.140.0200.00721.28
7.4.130.0170.01421.23
7.4.120.0180.00921.27
7.4.110.0140.01221.21
7.4.100.0150.01021.28
7.4.90.0180.00621.23
7.4.80.0210.00521.25
7.4.70.0190.00521.29
7.4.60.0180.00921.27
7.4.50.0130.01421.19
7.4.40.0160.01121.27
7.4.30.0150.01121.20
7.4.20.0190.00821.17
7.4.10.0180.01021.31
7.4.00.0140.01019.14
7.3.330.0230.01625.92
7.3.320.0260.00625.92
7.3.310.0210.00725.92
7.3.300.0220.00625.92
7.3.290.0220.00625.92
7.3.280.0200.00725.92
7.3.270.0130.01625.92
7.3.260.0140.01321.27
7.3.250.0160.00821.31
7.3.240.0110.01321.20
7.3.230.0140.00921.30
7.3.220.0130.01121.16
7.3.210.0150.01221.26
7.3.200.0140.01021.13
7.3.190.0140.01021.29
7.3.180.0170.01121.17
7.3.170.0160.01021.30
7.3.160.0130.01321.29
7.3.150.0230.00521.20
7.3.140.0130.01021.16
7.3.130.0120.01221.19
7.3.120.0150.00719.18
7.3.110.0140.00819.20
7.3.100.0120.01219.16
7.3.90.0150.00819.11
7.3.80.0130.01019.09
7.3.70.0080.01519.05
7.3.60.0110.01019.07
7.3.50.0110.01119.13
7.3.40.0150.01219.11
7.3.30.0160.01019.12
7.3.20.0190.00619.75
7.3.10.0130.01019.70
7.3.00.0190.00619.80
7.2.340.0220.01421.34
7.2.330.0280.00721.24
7.2.320.0290.00621.32
7.2.310.0280.00621.36
7.2.300.0200.01321.36
7.2.290.0210.01421.32
7.2.280.0240.00721.37
7.2.270.0230.00821.25
7.2.260.0220.01021.34
7.2.250.0180.01019.41
7.2.240.0150.01319.20
7.2.230.0210.00719.15
7.2.220.0150.01419.17
7.2.210.0170.01419.32
7.2.200.0200.00819.27
7.2.190.0150.00819.11
7.2.180.0150.01319.36
7.2.170.0190.00819.16
7.2.160.0190.01421.38
7.2.150.0310.01121.35
7.2.140.0230.00821.27
7.2.130.0230.01221.40
7.2.120.0450.01019.08
7.2.110.0380.00719.08
7.2.100.0410.00719.06
7.2.90.0400.00919.13
7.2.80.0710.00819.13
7.2.70.0620.00819.36
7.2.60.0600.01219.22
7.2.50.0710.01119.31
7.2.40.0680.01119.26
7.2.30.0730.01019.22
7.2.20.0950.00819.29
7.2.10.0560.01019.25
7.2.00.0910.00719.32
7.1.330.0190.00719.09
7.1.320.0210.00919.12
7.1.310.0160.00818.96
7.1.300.0190.00819.06
7.1.290.0150.01019.11
7.1.280.0150.00918.98
7.1.270.0170.00719.05
7.1.260.0190.00519.05
7.1.250.0190.00920.61
7.1.240.0580.00718.35
7.1.230.0630.00518.43
7.1.220.0590.00418.39
7.1.210.0680.01018.39
7.1.200.0680.00918.29
7.1.190.0620.00718.43
7.1.180.0810.00618.40
7.1.170.0660.00918.43
7.1.160.0570.00818.34
7.1.150.0730.00918.36
7.1.140.0630.00418.43
7.1.130.0610.00618.39
7.1.120.0820.00718.42
7.1.110.0740.01118.43
7.1.100.0920.01018.47
7.1.90.0600.00818.45
7.1.80.0460.00718.52
7.1.70.0730.01018.40
7.1.60.0730.00518.31
7.1.50.0730.00818.47
7.1.40.0820.00818.50
7.1.30.0600.00918.45
7.1.20.0750.01218.40
7.1.10.0820.00718.41
7.1.00.0590.00718.36
7.0.330.0160.01120.64
7.0.320.0170.00920.50
7.0.310.0210.00820.57
7.0.300.0180.00920.53
7.0.290.0250.00820.57
7.0.280.0260.00520.53
7.0.270.0250.00920.62
7.0.260.0200.00720.60
7.0.250.0240.00520.55
7.0.240.0130.01620.53
7.0.230.0230.00320.61
7.0.220.0190.01220.54
7.0.210.0250.00520.58
7.0.200.0220.00920.59
7.0.190.0240.00720.62
7.0.180.0260.00320.48
7.0.170.0260.00420.54
7.0.160.0210.00720.59
7.0.150.0200.00820.59
7.0.140.0250.00720.57
7.0.130.0180.01020.63
7.0.120.0200.00720.59
7.0.110.0230.00320.57
7.0.100.0220.00620.54
7.0.90.0170.00920.58
7.0.80.0250.00320.67
7.0.70.0230.00520.57
7.0.60.0210.00620.53
7.0.50.0280.00020.60
7.0.40.0120.01320.55
7.0.30.0140.01120.55
7.0.20.0190.00320.50
7.0.10.0180.01020.57
7.0.00.0230.00420.47
5.6.400.0170.01120.83
5.6.390.0190.00820.87
5.6.380.0120.01118.48
5.6.370.0230.00720.83
5.6.360.0210.01120.72
5.6.350.0210.01120.87
5.6.340.0210.01220.81
5.6.330.0170.01220.94
5.6.320.0200.01020.89
5.6.310.0270.00520.84
5.6.300.0220.00720.90
5.6.290.0230.00720.95
5.6.280.0210.00620.87
5.6.270.0190.00920.79
5.6.260.0240.00420.84
5.6.250.0190.00720.74
5.6.240.0180.01220.81
5.6.230.0220.00720.85
5.6.220.0220.00720.72
5.6.210.0210.00620.83
5.6.200.0240.00320.80
5.6.190.0200.00720.90
5.6.180.0190.00720.71
5.6.170.0160.01120.76
5.6.160.0190.00720.79
5.6.150.0190.00720.73
5.6.140.0230.00620.83
5.6.130.0220.00620.78
5.6.120.0190.00820.85
5.6.110.0140.01320.86
5.6.100.0250.00520.71
5.6.90.0230.00820.85
5.6.80.0190.00920.82
5.6.70.0190.00920.82
5.6.60.0240.00420.75
5.6.50.0200.00520.70
5.6.40.0130.00820.78
5.6.30.0130.01020.67
5.6.20.0180.00420.77
5.6.10.0170.00920.73
5.6.00.0120.01020.77

preferences:
69.23 ms | 401 KiB | 5 Q