3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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));
Output for 7.3.0rc6
All tests pass! string(192) "9621e4ca0dc8fc354780ec3da94b7c25c70dc1b9ed5374c9d177b8cc2619682fa800ad49b0e77f0297eb1d735459a6dfc1a73dac99f89e7036758c402a9a71075830b2d970721b256fedefc68497112fa57770a045874a5fb0e3fcf497685670" string(192) "b8275df773dd6cc2acf3c8abcbd9ad6750fef0b61eef711128e13261287373d4b7320397b0374f0234104930bbe598a74eaabdff32a06cdf3e2c41cbba51550a4537170544b0d5aa048a346e31165569833cf15adb44310083144cfcbf678300"
Output for 7.3.0rc5
All tests pass! string(192) "37eca0262905505e728dbd713e64d494e4973b938094abb9927a226e55b4c71a78f3261dcefa71272a3f136766545eca4431551e3f7526c5ef0f136e661ae401455f0ce9d0fef5f97eb3093cfa6892df485525981c198daab242df0d071ea5d8" string(192) "a9230b9fd039e0d5f3d3f0de1f879566f04da3f522f21a2ca009ae2b0cda99fd3d283ab525d2fdc5f268b83385944cdb057b98efdab729f72994aecea6c9d706470b743d747e0e05e3e800be282b24edcb3750ab97a81b3e6ac164dd19db56b8"
Output for 7.3.0rc4
All tests pass! string(192) "a831d761b6fe1156fa124b5ad3c61361daf8cb60dc6f84508eb95ba26d0fe2d315f617208286d6cdb788f26936103ad0c8e0fa86e28872d4df2db17954628301651d9e6f2014a505eaca8a0266aa8e84711a4879f18eea65e465b0295db4e4c6" string(192) "cc97b9b4440488c6c590011b712eec4f5a2653b858112b378da39a6c6b6bb5a39df9dec03866249ae5c1358a3daa13ae83180eb973bd09df5d312c73964b220efae58b05f47789699021278b90dab11a4fdb74009ddd35ee09232899ec33f2b1"
Output for 7.3.0rc3
All tests pass! string(192) "88c67e91f5d236a7df10f63f25480f84be305b89b8a4b37701a93876e6229300ec156692dd6c794f06752caee936aff3b9f5ae07fdbe95312ab78a2ce05d5f08d5d4231cad6eb4d59d0c872efe62ef8d14750a7b4b13d26ae9e33321c0d3eb5b" string(192) "7991a56890a2c6d474082f21b823c154e02f2cc1fc6a08db9a3ddf1e5d48bc9e09405aa4efd37c682b8f793583d4cc4e75c29ac9ef5e1921021c02dea59c7407541fafb85b4b4da178652fcce5bcc1888b602c03ddd836f895e5b09a4d9ae086"
Output for 7.3.0rc2
All tests pass! string(192) "a02497ac69b6ed3d2f6980b5bc9a63b64c55464c497d1886286906346828298db89fa856a04f29f1e8d41c63757567980c6db0942713d7b480b82f5c3c403400e37a6d31c9f05b4deb557ba81106a32a7248682007e7bb12bc6ffa9ee67c05de" string(192) "4876e36d84122c6f7d48d551e691bd3d4a9eba41314254128c6f083f302b7e7d030dec6985c918a9a4362a297ffd62ad78c04dabb16bdb0ecb2495210b97b50f13ba26250e87dfc5cbf67a92b31e6e6cfcabd74b81e1d293d5d42f5eca10ebda"
Output for 7.3.0rc1
All tests pass! string(192) "79fa51a0951ccc52ddcbc8d86fd8902bd39de983ab22513249026945be2e1a335484ee3104944a31603102f80c5774fd14e50128661dc05cdd03c22ab48c670e485160851fef8c471d2e7c198a5712f7379842d2ce1ae705410d66a159f8700e" string(192) "9c6ed56afdfad1fa516ec2fd8d37893c86d8e5b4eb3c70c1a082238a382471d3f811cd97dfe3b9882306dc822f29a7d8ac8289ceaf2cbe4c0e86dba03a57ea0dde1a644bae879905ad4284c5fe0f02b4cb91754e22a3723e49063f2aa46f6fe2"
Output for 7.3.0beta3
All tests pass! string(192) "dfebc4c31eeb7cfa94f6f4ceccd997263c4aa23c5776f631a50575f0831e7841821334b6eb72a0b2acd57b95b5727a18b07da43e0ddbf129cb6465dd5cb8320ac58a280fc49f89d5662578ccc59a8e792ab5c98cce95df4a8025600ead125037" string(192) "b5b996dc7288ee2710a7c46b5a892e5fb92b0e2414857f0c85a9e20de046833d20c9f32600f01bec394ed6dbb48b1a814d0f01fd369477760d29d1b21914c2058bec1f39682f8cd0c26e23ecd7df9c3f0d06e544f51a2612f7b59c9fe08331ab"
Output for 7.3.0beta2
All tests pass! string(192) "40808a930386913d1cae6447819fb0f4a98f23cce38c900a04f7ca3e9499994ae010eff06cbb834f3c611f417bce13f0e0be875cb17c5d75afc61d8e4adfeb09e3c1025120d6e0e8317977cda3a4690031490fd29c56a4b54e082fdc9b3ed692" string(192) "aa3f68f14028560f6bb2e20fa9d6efdbfbdf4f0e5f383e49eaca7b26e0b9f03f43246a02b96d33c568450857881f2c90277be25684e52f9cde746a21cd3f9f0c45b9516e55c248263f6251a783160f0e02dabeebfcb4e313969000848b13c5c2"
Output for 7.3.0beta1
All tests pass! string(192) "f191663ba1fcbb2360f99165a7a365fc1c076d2128e31f42d61c23a43fc3bb87955dfbf018973e395c185eef6104b0c342f2ee71ca069f4842f16f7d78a3a809c628f7f3301ab4df657769f908160036fd86459ec61480dcb77d111188194120" string(192) "991b064d2c9b960be86171814c6c7e2a7c9682ceb2647f5c6b2ffd59d1f3dc975d1823b65c379dc16a90a4d5c17c3e5e660158c25cf1d70ade1d2857e32a9908e7f52a45ad08981bd29e3cda5a58de7437c1937f8f97e5202c86dca6c98fada0"
Output for 7.3.0alpha4
All tests pass! string(192) "f7e1900b46c622b60c18b1cfad6f0371a49108d838c1a915f95c37257d480f133e87e13d4fdf087d30d91fca7de84b2d19221b98ebdbd8234e49de2364653f018208d1510484eabbe57b313911f7b8cac291d626d9e6b8433bc4fd3f9cb24bb9" string(192) "a7c048f8fcf9d964a2d6faafc4f3b9556970cbeefc42f86720d0cbb05aa98546732641b0efc7dcf1bd683abb56cdcbad050e5e6dc5f6c24f2381b2d2823b090850f8ca3d44ddc3c8c62d1bb3039d4211f24d35209af0b54c22ede501cd64f1c0"
Output for 7.3.0alpha3
All tests pass! string(192) "4dd0bbfed842718de2dd305bbc5b17d5de7963abc51717e10d3a6bfdaed12be48bfe9ddb8ab931621c95228bb454098465f0e990866f067a247692a66492fa0472770548a347385983e90eb8e9a68333f3b9722c982271eb9d4d06ea2d9d0f29" string(192) "740d7d108201c15f12caabb5090add139964ed225a4b078ee97eecd831c377551e4f8a301034f3bf199ae60e96015a113091da6c4d23485d978ac03962164102c17bb8f44305847b1212a4f86904bb3250be7efa3a8b044e9901dcb7a319113e"
Output for 7.3.0alpha2
All tests pass! string(192) "9d84d9d746f86ef872c453bb462d7422f56d1dc2011a9348fd2c0b358ce228999aea9809617919a5b8884bc59fea5d84f1b10aabb24be4ab876a8eb463e5700de1270cbea12033161f1d187033bab85cbc52a209680bdf18731f2e308371ca65" string(192) "d1851ea6eba371f2f5b8f7e4979474ab60d95537c9134980f84cd6608afbbc2777322a25d0f34b1fe72ba0e1a0fb4ed2faa642695731197ae947999fa8abf508bc2a4c4319f97fc8eb0f426704ce178ad04facbb0a78682706eb79e521d348ba"
Output for 7.3.0alpha1
All tests pass! string(192) "85a52e8873856445c3b5b14e9260c5f9f3d26e44c3dffe07ad81bec244645ea45f726d2c29d718cd8992fb7ef8ee892386c367a0c37a4a53ae7b76711f69570659265beb5eb994d196ffc230da815f57bcb16caa6113be748fcc087875071ba4" string(192) "5ac167a2b86ed28458943863ef6366483f18dd12bca7c15db2ebe540e6b2c418e146f700fbd1a45516ad65c24185ad9ac33fc799665daddd146d632aa476360764cff9a3ca25cee5e3ea9f3d44b2a49604cb5b44e16b4a0683a73de614a07ed4"
Output for 7.0.32 - 7.1.24, 7.2.8 - 7.2.12
Fatal error: Uncaught Error: Call to undefined function sodium_crypto_sign_keypair() in /in/e9q13:31 Stack trace: #0 {main} thrown in /in/e9q13 on line 31
Process exited with code 255.
Output for 7.2.7
All tests pass! string(192) "c32f622432f6444f32bad5ef4dcc6c8713f1bb2b341c9db6c8fbdfc7d0d66fd0f7f3d3f06861ebd03d3f2d403bae83151086f9c1526adbd2b09f2ce3866dae0412a62ca8e6ec5713796b65397edba0a279aff995fec555fbd6861ac2a3827dbe" string(192) "114145e74c9ab3b5d15bb446007ae948c8cc60c388fc63141837e7086411717dafcdd794aaa5c083baf88efae12812ed03fa304102a3f86b2ef6f3bc59cd0e03f6a9643990331d8fbdd11dfa879beab77c19c15a88791e82052369f04bc0a92b"
Output for 7.2.6
All tests pass! string(192) "f09b0f4b53b9a30b297a553db564ef810b931ab89cd24f10cacd93943bb6b8ac5b23e7138c2e6313f536e747e5d4a9c4e1f298bd445a9d7ae8ee6a011b371f061a89f2b0e1f88acba0b24e641d5484127a83fbbc70ed08ed66bbdd0482bca0ea" string(192) "3a0b4008141da037b1f8b98d6fccd7b48ccbcaa74a77f45eb0682ab652f00daaee54ff0ac7a0e18e0ca575a8a943ef001ceba0dee83d11d3330223c8a3cb6c02d824af0acb7b20b32ebdce9aa5e6bf9e51bbf940f7120a998c91a28651f8b36f"
Output for 7.2.5
All tests pass! string(192) "c1e7b6e477aaa51845c1782dc20537163d52638e04f9dc3d119425ee18f877b91107bdd354b3dce2bb155c6b80ea4fcd03b0d86bc60d5995e7cc4d444f71fc0b46771c394a87e61c251af2866c5f6672a295b851ac3de2b05b223bbf7098cd54" string(192) "62a2cea8bc0ef1a1dda01827c9799a8e6401614897de0552c8a142f2a8ea2c212819129c1c4369dd962e379a1b2a28265beabe9497f7240d59ae31ae22cbb1079a67116fcb6f8f5234be8ba33bae86e25ccdd6b0d85cd49fe3563bf7be11b170"
Output for 7.2.4
All tests pass! string(192) "928374df898ebd2c648264c97d933d7503b4af57e437126a68eb9d59e276d486d08010aaa9e6b25e070f030bf09c32c697ffd3825cfc506e61f69cc8501e7f0644a94b5c7915a01dd34ae0a408414cc49766121703ec61f13722e344b0ad3116" string(192) "5d6631d58354b0df2ad9078222a579cc1e47f68fbe44639691d3c2b6c82e50e7b36e59168aea971be53def6c97909313d9c3e94c6fbe12681b923a34b3be06011b0e18867c17dddfe25c90d00880e851c32f64d49c4c9a983d7b55e5591b088d"
Output for 7.2.3
All tests pass! string(192) "5748135204854cf621a57ac0b0ce0039550c8022cb50bdac51a211891fd0b31830894d5ca4060911e6e83bec44dccaee1cd15f0788b08167158c8599135c560f17651fc8e344b0b2592472a908c79aa588578c0960983f36253365119ac3a8cc" string(192) "277e99e664271350aa6abb4471154431763850c5dd528c4767cd9e75d65279da39da8c427b01ad2ef860880753859f2990d49d8e1eb7c9206973ba50dc2bb105ab3a3de04ab9efc2efcad8b3ac0fb253a9d145ca8e8b43e1f001bf3d9791f0cb"
Output for 7.2.2
All tests pass! string(192) "54bd54413653bde54c03156293c28109b2ca662af1abc9173bb9f5f9f14e3fce4e52ae0debd65bce678df0b79ab5550a5b1ee73cf32f0ed0934cb91e5da11104a6e7f649110659f63f5abb6f98e38c930fe44a9c0be479b2b169522444d538f6" string(192) "6d1f481dd706f8f76b46ed704a848c8c60852f535114c5fe6def824daf68d507c8a38c63ea067409a3e21b4f650876ef54d68ee6ddffdb34341348c7de991402f145e1982a2a017b9d775d585951a97e6ce253f169af6e88a4ea08333eae87b9"
Output for 7.2.1
All tests pass! string(192) "4c96db3e7adb15cb59b11204ce1fa459426b1e45b4db57727a2340d40d2c55b0d531e2659b0d0aaad7a2dac603b9008cff5a511d93144970c1aa99c5839d7c09145d3b147456c13b7dc7661e59de324223197e5604ea370323b3c83a27e8c84a" string(192) "1e692d00e519b0e2c9c8bb06dc0f8c8098adb8e3e9ef1f4e3db867304813116b214ace8de36270d6ba0b11251c657e56ec554d9da573f84507fb61ce2de2cc0e2e10b468c863476fb99593a95df8bfdf323ef18101f1aec8ffbc07e4c56b9121"
Output for 7.2.0
All tests pass! string(192) "bd5ea11b3019f9088ca5a6c51344ef7cf1bbf9cda5debeadde18475f3913271d4777bb79f5a202fb43740282d4dcf0ebcc54007740e37c2a98542f835c4184067c4f1fd82d541659745593def0c99e020c09a90629b4c5f43ec70ccaea8f501e" string(192) "068cb83ac14ea904d46a5dc95176d4ee7cbbb487511555b376ed7460dd8915eae211eaf09d83283ed8053d7dea918379341d648a326d0f21cf596430879c470de380447af3bb2eb39e3c93e55c6e1c4ba4d74ee3785d8b9bec3c1704d99ce4b9"
Output for 5.6.38
Warning: Unsupported declare 'strict_types' in /in/e9q13 on line 2 Parse error: syntax error, unexpected ':', expecting '{' in /in/e9q13 on line 6
Process exited with code 255.