# HG changeset patch # User Claus Gittinger # Date 1553255546 -3600 # Node ID a9c72db987e7a3a6ef2003386a5e450ec35afbbe # Parent 32464e479c8fd2c319db255dbb2b24ceb402463c #QUALITY by cg class: RegressionTests::CryptTests preps for sha3 testing added: #test16_sha3_256 #test17_sha3_224 #test18_sha3_384 #test19_sha3_512 comment/format in: #test06_sha256 #test09_sha512 changed: #test03_sha1 #test07_sha224 #test08_sha384 diff -r 32464e479c8f -r a9c72db987e7 RegressionTests__CryptTests.st --- a/RegressionTests__CryptTests.st Fri Mar 22 12:51:58 2019 +0100 +++ b/RegressionTests__CryptTests.st Fri Mar 22 12:52:26 2019 +0100 @@ -152,22 +152,38 @@ test03_sha1 |h| + "/ test vectors from https://www.di-mgt.com.au/sha_testvectors.html + "/ and others + h := SHA1Stream hashValueOf:''. self assert:(h = (ByteArray fromHexString:'da39a3ee5e6b4b0d3255bfef95601890afd80709')). + h := SHA1Stream hashValueOf:'abc'. + self assert:(h = (ByteArray fromHexStringWithSeparators:'a9993e36 4706816a ba3e2571 7850c26c 9cd0d89d')). + + h := SHA1Stream hashValueOf:'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'. + self assert:(h = (ByteArray fromHexStringWithSeparators:'84983e44 1c3bd26e baae4aa1 f95129e5 e54670f1')). + + h := SHA1Stream hashValueOf:'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu'. + self assert:(h = (ByteArray fromHexStringWithSeparators:'a49b2446 a02c645b f419f995 b6709125 3a04a259')). + h := SHA1Stream hashValueOf:'The quick brown fox jumps over the lazy dog'. self assert:(h = (ByteArray fromHexString:'2fd4e1c67a2d28fced849ee1bb76e7391b93eb12')). h := SHA1Stream hashValueOf:#[16r00 16r01 16r02 16r40 16r08 16r10 16r20 16r40 16r80 - 16rFF 16rFE 16rFC 16rF8 16rF0 16rE0 16rC0 16r80]. + 16rFF 16rFE 16rFC 16rF8 16rF0 16rE0 16rC0 16r80]. self assert:(h = #[146 31 26 53 78 167 121 73 144 117 145 88 50 42 25 52 53 37 177 73]). + h := SHA1Stream hashValueOf:(String new:1000000 withAll:$a). + self assert:(h = (ByteArray fromHexStringWithSeparators:'34aa973c d4c4daa4 f61eeb2b dbad2731 6534016f')). + " self run:#test03_sha1 self new test03_sha1 " "Modified: / 25-11-2013 / 11:42:46 / cg" + "Modified: / 22-03-2019 / 12:29:01 / Claus Gittinger" ! test03b_sha1 @@ -225,9 +241,12 @@ test06_sha256 |h| + "/ test vectors from https://www.di-mgt.com.au/sha_testvectors.html + "/ and others + self - skipIf:(SHA256Stream isBehavior not or:[SHA256Stream isLoaded not]) - description:'SHA256Stream/libcrypt is not loaded'. + skipIf:(SHA256Stream isBehavior not or:[SHA256Stream isLoaded not]) + description:'SHA256Stream/libcrypt is not loaded'. h := SHA256Stream hashValueOf:''. self assert:(h = (ByteArray fromHexString:'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855')). @@ -235,18 +254,34 @@ h := SHA256Stream hashValueOf:'The quick brown fox jumps over the lazy dog'. self assert:(h = (ByteArray fromHexString:'d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592')). + h := SHA256Stream hashValueOf:'abc'. + self assert:(h = (ByteArray fromHexStringWithSeparators:'ba7816bf 8f01cfea 414140de 5dae2223 b00361a3 96177a9c b410ff61 f20015ad')). + + h := SHA256Stream hashValueOf:'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'. + self assert:(h = (ByteArray fromHexStringWithSeparators:'248d6a61 d20638b8 e5c02693 0c3e6039 a33ce459 64ff2167 f6ecedd4 19db06c1')). + + h := SHA256Stream hashValueOf:'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu'. + self assert:(h = (ByteArray fromHexStringWithSeparators:'cf5b16a7 78af8380 036ce59e 7b049237 0b249b11 e8f07a51 afac4503 7afee9d1')). + + h := SHA256Stream hashValueOf:(String new:1000000 withAll:$a). + self assert:(h = (ByteArray fromHexStringWithSeparators:'cdc76e5c 9914fb92 81a1c7e2 84d73e67 f1809a48 a497200e 046d39cc c7112cd0')). " self run:#test06_sha256 self new test06_sha256 " + + "Modified: / 22-03-2019 / 12:35:28 / Claus Gittinger" ! test07_sha224 |h| + "/ test vectors from https://www.di-mgt.com.au/sha_testvectors.html + "/ and others + self - skipIf:(SHA224Stream isBehavior not or:[SHA224Stream isLoaded not]) - description:'SHA224Stream/libcrypt is not loaded'. + skipIf:(SHA224Stream isBehavior not or:[SHA224Stream isLoaded not]) + description:'SHA224Stream/libcrypt is not loaded'. h := SHA224Stream hashValueOf:''. self assert:(h = (ByteArray fromHexString:'d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f')). @@ -254,18 +289,35 @@ h := SHA224Stream hashValueOf:'The quick brown fox jumps over the lazy dog'. self assert:(h = (ByteArray fromHexString:'730e109bd7a8a32b1cb9d9a09aa2325d2430587ddbc0c38bad911525')). + h := SHA224Stream hashValueOf:'abc'. + self assert:(h = (ByteArray fromHexStringWithSeparators:'23097d22 3405d822 8642a477 bda255b3 2aadbce4 bda0b3f7 e36c9da7')). + + h := SHA224Stream hashValueOf:'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'. + self assert:(h = (ByteArray fromHexStringWithSeparators:'75388b16 512776cc 5dba5da1 fd890150 b0c6455c b4f58b19 52522525')). + + h := SHA224Stream hashValueOf:'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu'. + self assert:(h = (ByteArray fromHexStringWithSeparators:'c97ca9a5 59850ce9 7a04a96d ef6d99a9 e0e0e2ab 14e6b8df 265fc0b3')). + + h := SHA224Stream hashValueOf:(String new:1000000 withAll:$a). + self assert:(h = (ByteArray fromHexStringWithSeparators:'20794655 980c91d8 bbb4c1ea 97618a4b f03f4258 1948b2ee 4ee7ad67')). + " self run:#test07_sha224 self new test07_sha224 " + + "Modified (format): / 22-03-2019 / 12:33:52 / Claus Gittinger" ! test08_sha384 |h| + "/ test vectors from https://www.di-mgt.com.au/sha_testvectors.html + "/ and others + self - skipIf:(SHA384Stream isBehavior not or:[SHA384Stream isLoaded not]) - description:'SHA384Stream/libcrypt is not loaded'. + skipIf:(SHA384Stream isBehavior not or:[SHA384Stream isLoaded not]) + description:'SHA384Stream/libcrypt is not loaded'. h := SHA384Stream hashValueOf:''. self assert:(h = (ByteArray fromHexString:'38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b')). @@ -273,18 +325,35 @@ h := SHA384Stream hashValueOf:'The quick brown fox jumps over the lazy dog'. self assert:(h = (ByteArray fromHexString:'ca737f1014a48f4c0b6dd43cb177b0afd9e5169367544c494011e3317dbf9a509cb1e5dc1e85a941bbee3d7f2afbc9b1')). + h := SHA384Stream hashValueOf:'abc'. + self assert:(h = (ByteArray fromHexStringWithSeparators:'cb00753f45a35e8b b5a03d699ac65007 272c32ab0eded163 1a8b605a43ff5bed 8086072ba1e7cc23 58baeca134c825a7')). + + h := SHA384Stream hashValueOf:'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'. + self assert:(h = (ByteArray fromHexStringWithSeparators:'3391fdddfc8dc739 3707a65b1b470939 7cf8b1d162af05ab fe8f450de5f36bc6 b0455a8520bc4e6f 5fe95b1fe3c8452b')). + + h := SHA384Stream hashValueOf:'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu'. + self assert:(h = (ByteArray fromHexStringWithSeparators:'09330c33f71147e8 3d192fc782cd1b47 53111b173b3b05d2 2fa08086e3b0f712 fcc7c71a557e2db9 66c3e9fa91746039')). + + h := SHA384Stream hashValueOf:(String new:1000000 withAll:$a). + self assert:(h = (ByteArray fromHexStringWithSeparators:'9d0e1809716474cb 086e834e310a4a1c ed149e9c00f24852 7972cec5704c2a5b 07b8b3dc38ecc4eb ae97ddd87f3d8985')). + " self run:#test08_sha384 self new test08_sha384 " + + "Modified (format): / 22-03-2019 / 12:33:59 / Claus Gittinger" ! test09_sha512 |h| + "/ test vectors from https://www.di-mgt.com.au/sha_testvectors.html + "/ and others + self - skipIf:(SHA512Stream isBehavior not or:[SHA512Stream isLoaded not]) - description:'SHA512Stream/libcrypt is not loaded'. + skipIf:(SHA512Stream isBehavior not or:[SHA512Stream isLoaded not]) + description:'SHA512Stream/libcrypt is not loaded'. h := SHA512Stream hashValueOf:''. self assert:(h = (ByteArray fromHexString:'cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e')). @@ -292,10 +361,24 @@ h := SHA512Stream hashValueOf:'The quick brown fox jumps over the lazy dog'. self assert:(h = (ByteArray fromHexString:'07e547d9586f6a73f73fbac0435ed76951218fb7d0c8d788a309d785436bbb642e93a252a954f23912547d1e8a3b5ed6e1bfd7097821233fa0538f3db854fee6')). + h := SHA512Stream hashValueOf:'abc'. + self assert:(h = (ByteArray fromHexStringWithSeparators:'ddaf35a193617aba cc417349ae204131 12e6fa4e89a97ea2 0a9eeee64b55d39a 2192992a274fc1a8 36ba3c23a3feebbd 454d4423643ce80e 2a9ac94fa54ca49f')). + + h := SHA512Stream hashValueOf:'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'. + self assert:(h = (ByteArray fromHexStringWithSeparators:'204a8fc6dda82f0a 0ced7beb8e08a416 57c16ef468b228a8 279be331a703c335 96fd15c13b1b07f9 aa1d3bea57789ca0 31ad85c7a71dd703 54ec631238ca3445')). + + h := SHA512Stream hashValueOf:'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu'. + self assert:(h = (ByteArray fromHexStringWithSeparators:'8e959b75dae313da 8cf4f72814fc143f 8f7779c6eb9f7fa1 7299aeadb6889018 501d289e4900f7e4 331b99dec4b5433a c7d329eeb6dd2654 5e96e55b874be909')). + + h := SHA512Stream hashValueOf:(String new:1000000 withAll:$a). + self assert:(h = (ByteArray fromHexStringWithSeparators:'e718483d0ce76964 4e2e42c7bc15b463 8e1f98b13b204428 5632a803afa973eb de0ff244877ea60a 4cb0432ce577c31b eb009c5c2c49aa2e 4eadb217ad8cc09b')). + " self run:#test09_sha512 self new test09_sha512 " + + "Modified: / 22-03-2019 / 12:36:56 / Claus Gittinger" ! test10_des @@ -860,6 +943,150 @@ "Created: / 26-07-2017 / 09:09:22 / cg" "Modified (format): / 23-08-2017 / 15:51:45 / cg" +! + +test16_sha3_256 + |h| + + "/ test vectors from https://www.di-mgt.com.au/sha_testvectors.html + "/ and others + + self + skipIf:(SHA3_256Stream isBehavior not or:[SHA3_256Stream isLoaded not]) + description:'SHA3_256Stream/libcrypt is not loaded'. + + h := SHA3_256Stream hashValueOf:''. + self assert:(h = (ByteArray fromHexStringWithSeparators:'a7ffc6f8bf1ed766 51c14756a061d662 f580ff4de43b49fa 82d80a4b80f8434a')). + +"/ h := SHA3_256Stream hashValueOf:'The quick brown fox jumps over the lazy dog'. +"/ self assert:(h = (ByteArray fromHexStringWithSeparators:'d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592')). + + h := SHA3_256Stream hashValueOf:'abc'. + self assert:(h = (ByteArray fromHexStringWithSeparators:'3a985da74fe225b2 045c172d6bd390bd 855f086e3e9d525b 46bfe24511431532')). + + h := SHA3_256Stream hashValueOf:'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'. + self assert:(h = (ByteArray fromHexStringWithSeparators:'41c0dba2a9d62408 49100376a8235e2c 82e1b9998a999e21 db32dd97496d3376')). + + h := SHA3_256Stream hashValueOf:'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu'. + self assert:(h = (ByteArray fromHexStringWithSeparators:'916f6061fe879741 ca6469b43971dfdb 28b1a32dc36cb325 4e812be27aad1d18')). + + h := SHA3_256Stream hashValueOf:(String new:1000000 withAll:$a). + self assert:(h = (ByteArray fromHexStringWithSeparators:'5c8875ae474a3634 ba4fd55ec85bffd6 61f32aca75c6d699 d0cdcb6c115891c1')). + + " + self run:#test16_sha3_256 + self new test16_sha3_256 + " + + "Created: / 22-03-2019 / 12:41:10 / Claus Gittinger" +! + +test17_sha3_224 + |h| + + "/ test vectors from https://www.di-mgt.com.au/sha_testvectors.html + "/ and others + + self + skipIf:(SHA3_224Stream isBehavior not or:[SHA3_224Stream isLoaded not]) + description:'SHA3_224Stream/libcrypt is not loaded'. + + h := SHA3_224Stream hashValueOf:''. + self assert:(h = (ByteArray fromHexStringWithSeparators:'6b4e03423667dbb7 3b6e15454f0eb1ab d4597f9a1b078e3f 5b5a6bc7')). + +"/ h := SHA3_224Stream hashValueOf:'The quick brown fox jumps over the lazy dog'. +"/ self assert:(h = (ByteArray fromHexStringWithSeparators:'d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592')). + + h := SHA3_224Stream hashValueOf:'abc'. + self assert:(h = (ByteArray fromHexStringWithSeparators:'e642824c3f8cf24a d09234ee7d3c766f c9a3a5168d0c94ad 73b46fdf')). + + h := SHA3_224Stream hashValueOf:'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'. + self assert:(h = (ByteArray fromHexStringWithSeparators:'8a24108b154ada21 c9fd5574494479ba 5c7e7ab76ef264ea d0fcce33')). + + h := SHA3_224Stream hashValueOf:'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu'. + self assert:(h = (ByteArray fromHexStringWithSeparators:'543e6868e1666c1a 643630df77367ae5 a62a85070a51c14c bf665cbc')). + + h := SHA3_224Stream hashValueOf:(String new:1000000 withAll:$a). + self assert:(h = (ByteArray fromHexStringWithSeparators:'d69335b93325192e 516a912e6d19a15c b51c6ed5c15243e7 a7fd653c')). + + " + self run:#test17_sha3_224 + self new test17_sha3_224 + " + + "Created: / 22-03-2019 / 12:42:49 / Claus Gittinger" +! + +test18_sha3_384 + |h| + + "/ test vectors from https://www.di-mgt.com.au/sha_testvectors.html + "/ and others + + self + skipIf:(SHA3_384Stream isBehavior not or:[SHA3_384Stream isLoaded not]) + description:'SHA3_384Stream/libcrypt is not loaded'. + + h := SHA3_384Stream hashValueOf:''. + self assert:(h = (ByteArray fromHexStringWithSeparators:'0c63a75b845e4f7d 01107d852e4c2485 c51a50aaaa94fc61 995e71bbee983a2a c3713831264adb47 fb6bd1e058d5f004')). + +"/ h := SHA3_384Stream hashValueOf:'The quick brown fox jumps over the lazy dog'. +"/ self assert:(h = (ByteArray fromHexStringWithSeparators:'d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592')). + + h := SHA3_384Stream hashValueOf:'abc'. + self assert:(h = (ByteArray fromHexStringWithSeparators:'ec01498288516fc9 26459f58e2c6ad8d f9b473cb0fc08c25 96da7cf0e49be4b2 98d88cea927ac7f5 39f1edf228376d25')). + + h := SHA3_384Stream hashValueOf:'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'. + self assert:(h = (ByteArray fromHexStringWithSeparators:'991c665755eb3a4b 6bbdfb75c78a492e 8c56a22c5c4d7e42 9bfdbc32b9d4ad5a a04a1f076e62fea1 9eef51acd0657c22')). + + h := SHA3_384Stream hashValueOf:'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu'. + self assert:(h = (ByteArray fromHexStringWithSeparators:'79407d3b5916b59c 3e30b09822974791 c313fb9ecc849e40 6f23592d04f625dc 8c709b98b43b3852 b337216179aa7fc7')). + + h := SHA3_384Stream hashValueOf:(String new:1000000 withAll:$a). + self assert:(h = (ByteArray fromHexStringWithSeparators:'eee9e24d78c18553 37983451df97c8ad 9eedf256c6334f8e 948d252d5e0e7684 7aa0774ddb90a842 190d2c558b4b8340')). + + " + self run:#test18_sha3_384 + self new test18_sha3_384 + " + + "Created: / 22-03-2019 / 12:44:17 / Claus Gittinger" +! + +test19_sha3_512 + |h| + + "/ test vectors from https://www.di-mgt.com.au/sha_testvectors.html + "/ and others + + self + skipIf:(SHA3_512Stream isBehavior not or:[SHA3_512Stream isLoaded not]) + description:'SHA3_512Stream/libcrypt is not loaded'. + + h := SHA3_512Stream hashValueOf:''. + self assert:(h = (ByteArray fromHexStringWithSeparators:'a69f73cca23a9ac5 c8b567dc185a756e 97c982164fe25859 e0d1dcc1475c80a6 15b2123af1f5f94c 11e3e9402c3ac558 f500199d95b6d3e3 01758586281dcd26')). + +"/ h := SHA3_512Stream hashValueOf:'The quick brown fox jumps over the lazy dog'. +"/ self assert:(h = (ByteArray fromHexStringWithSeparators:'d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592')). + + h := SHA3_512Stream hashValueOf:'abc'. + self assert:(h = (ByteArray fromHexStringWithSeparators:'b751850b1a57168a 5693cd924b6b096e 08f621827444f70d 884f5d0240d2712e 10e116e9192af3c9 1a7ec57647e39340 57340b4cf408d5a5 6592f8274eec53f0')). + + h := SHA3_512Stream hashValueOf:'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'. + self assert:(h = (ByteArray fromHexStringWithSeparators:'04a371e84ecfb5b8 b77cb48610fca818 2dd457ce6f326a0f d3d7ec2f1e91636d ee691fbe0c985302 ba1b0d8dc78c0863 46b533b49c030d99 a27daf1139d6e75e')). + + h := SHA3_512Stream hashValueOf:'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu'. + self assert:(h = (ByteArray fromHexStringWithSeparators:'afebb2ef542e6579 c50cad06d2e578f9 f8dd6881d7dc824d 26360feebf18a4fa 73e3261122948efc fd492e74e82e2189 ed0fb440d187f382 270cb455f21dd185')). + + h := SHA3_512Stream hashValueOf:(String new:1000000 withAll:$a). + self assert:(h = (ByteArray fromHexStringWithSeparators:'3c3a876da14034ab 60627c077bb98f7e 120a2a5370212dff b3385a18d4f38859 ed311d0a9d5141ce 9cc5c66ee689b266 a8aa18ace8282a0e 0db596c90b0a7b87')). + + " + self run:#test19_sha3_512 + self new test19_sha3_512 + " + + "Created: / 22-03-2019 / 12:45:45 / Claus Gittinger" ! ! !CryptTests class methodsFor:'documentation'!