1. So. Many. HASHES!
- Posted by ghaberek (admin) Feb 13, 2022
- 933 views
I have successfully grafted a pared-down version of hashing algorithms from libtomcrypt into the backend. I should be pushing the changes soon.
Previously I was looking at a project called picohash for this, but that was a too-pared-down version of libtomcrypt that included only MD5, SHA-1, SHA224, and SHA256.
Here's the full list of supported algorithms:
- MD2
- MD4
- MD5
- SHA-1
- SHA-2: SHA224, SHA256, SHA384, SHA512, SHA512/224, SHA512/256
- SHA-3: SHA3-224, SHA3-256, SHA3-384, SHA3-512
This change also includes removing the hash() built-in function and moving its functionality to a checksum() in std/hash.e.
Here are some sample tests:
greg@ubuntu:~/Projects/OpenEuphoria/euphoria/source$ build/eui -c build/eu.cfg ../tests/t_hash.e passed: MD2("") -> 8350e5a3e24c153df2275c9f80692773 passed: MD2("The quick brown fox jumps over the lazy dog") -> 03d85a0d629d2c442e987525319fc471 passed: MD2("The quick brown fox jumps over the lazy cog") -> 6b890c9292668cdbbfda00a4ebf31f05 passed: MD4("") -> 31d6cfe0d16ae931b73c59d7e0c089c0 passed: MD4("The quick brown fox jumps over the lazy dog") -> 1bee69a46ba811185c194762abaeae90 passed: MD4("The quick brown fox jumps over the lazy cog") -> b86e130ce7028da59e672d56ad0113df passed: MD5("") -> d41d8cd98f00b204e9800998ecf8427e passed: MD5("The quick brown fox jumps over the lazy dog") -> 9e107d9d372bb6826bd81d3542a419d6 passed: MD5("The quick brown fox jumps over the lazy cog") -> 1055d3e698d289f2af8663725127bd4b passed: SHA1("") -> da39a3ee5e6b4b0d3255bfef95601890afd80709 passed: SHA1("The quick brown fox jumps over the lazy dog") -> 2fd4e1c67a2d28fced849ee1bb76e7391b93eb12 passed: SHA1("The quick brown fox jumps over the lazy cog") -> de9f2c7fd25e1b3afad3e85a0bd17d9b100db4b3 passed: SHA224("") -> d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f passed: SHA224("The quick brown fox jumps over the lazy dog") -> 730e109bd7a8a32b1cb9d9a09aa2325d2430587ddbc0c38bad911525 passed: SHA224("The quick brown fox jumps over the lazy cog") -> fee755f44a55f20fb3362cdc3c493615b3cb574ed95ce610ee5b1e9b passed: SHA256("") -> e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 passed: SHA256("The quick brown fox jumps over the lazy dog") -> d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592 passed: SHA256("The quick brown fox jumps over the lazy cog") -> e4c4d8f3bf76b692de791a173e05321150f7a345b46484fe427f6acc7ecc81be passed: SHA384("") -> 38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b passed: SHA384("The quick brown fox jumps over the lazy dog") -> ca737f1014a48f4c0b6dd43cb177b0afd9e5169367544c494011e3317dbf9a509cb1e5dc1e85a941bbee3d7f2afbc9b1 passed: SHA384("The quick brown fox jumps over the lazy cog") -> 098cea620b0978caa5f0befba6ddcf22764bea977e1c70b3483edfdf1de25f4b40d6cea3cadf00f809d422feb1f0161b passed: SHA512("") -> cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e passed: SHA512("The quick brown fox jumps over the lazy dog") -> 07e547d9586f6a73f73fbac0435ed76951218fb7d0c8d788a309d785436bbb642e93a252a954f23912547d1e8a3b5ed6e1bfd7097821233fa0538f3db854fee6 passed: SHA512("The quick brown fox jumps over the lazy cog") -> 3eeee1d0e11733ef152a6c29503b3ae20c4f1f3cda4cb26f1bc1a41f91c7fe4ab3bd86494049e201c4bd5155f31ecb7a3c8606843c4cc8dfcab7da11c8ae5045 passed: SHA512_224("") -> 6ed0dd02806fa89e25de060c19d3ac86cabb87d6a0ddd05c333b84f4 passed: SHA512_224("The quick brown fox jumps over the lazy dog") -> 944cd2847fb54558d4775db0485a50003111c8e5daa63fe722c6aa37 passed: SHA512_224("The quick brown fox jumps over the lazy cog") -> 2b9d6565a7e40f780ba8ab7c8dcf41e3ed3b77997f4c55aa987eede5 passed: SHA512_256("") -> c672b8d1ef56ed28ab87c3622c5114069bdd3ad7b8f9737498d0c01ecef0967a passed: SHA512_256("The quick brown fox jumps over the lazy dog") -> dd9d67b371519c339ed8dbd25af90e976a1eeefd4ad3d889005e532fc5bef04d passed: SHA512_256("The quick brown fox jumps over the lazy cog") -> cc8d255a7f2f38fd50388fd1f65ea7910835c5c1e73da46fba01ea50d5dd76fb passed: SHA3_224("") -> 6b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7 passed: SHA3_224("The quick brown fox jumps over the lazy dog") -> d15dadceaa4d5d7bb3b48f446421d542e08ad8887305e28d58335795 passed: SHA3_224("The quick brown fox jumps over the lazy cog") -> b770eb6ac3ac52bd2f9e8dc186d6b604e7c3b7ffc8bd9220b0078ced passed: SHA3_256("") -> a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a passed: SHA3_256("The quick brown fox jumps over the lazy dog") -> 69070dda01975c8c120c3aada1b282394e7f032fa9cf32f4cb2259a0897dfc04 passed: SHA3_256("The quick brown fox jumps over the lazy cog") -> cc80b0b13ba89613d93f02ee7ccbe72ee26c6edfe577f22e63a1380221caedbc passed: SHA3_384("") -> 0c63a75b845e4f7d01107d852e4c2485c51a50aaaa94fc61995e71bbee983a2ac3713831264adb47fb6bd1e058d5f004 passed: SHA3_384("The quick brown fox jumps over the lazy dog") -> 7063465e08a93bce31cd89d2e3ca8f602498696e253592ed26f07bf7e703cf328581e1471a7ba7ab119b1a9ebdf8be41 passed: SHA3_384("The quick brown fox jumps over the lazy cog") -> e414797403c7d01ab64b41e90df4165d59b7f147e4292ba2da336acba242fd651949eb1cfff7e9012e134b40981842e1 passed: SHA3_512("") -> a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26 passed: SHA3_512("The quick brown fox jumps over the lazy dog") -> 01dedd5de4ef14642445ba5f5b97c15e47b9ad931326e4b0727cd94cefc44fff23f07bf543139939b49128caf436dc1bdee54fcb24023a08d9403f9b4bf0d450 passed: SHA3_512("The quick brown fox jumps over the lazy cog") -> 28e361fe8c56e617caa56c28c7c36e5c13be552b77081be82b642f08bb7ef085b9a81910fe98269386b9aacfd2349076c9506126e198f6f6ad44c12017ca77b1 42 tests run, 42 passed, 0 failed, 100% success
-Greg
2. Re: So. Many. HASHES!
- Posted by ghaberek (admin) Feb 13, 2022
- 926 views
- Last edited Feb 14, 2022
Fun fact: on my system the interpreter runs those hash tests in 1.6s and the translator does them in 0.004s.
Edit: I now have it testing hashes on over 450 files from the source directory as well. 2766 tests in total (strings and files) in 2.82s interpreted, 0.98s translated.
-Greg