1 | // |
---|---|
2 | // SHA3EngineTest.cpp |
3 | // |
4 | // Code of the SHA3EngineTest class. |
5 | // |
6 | // test vectors from FIPS 180-1 |
7 | // |
8 | // Copyright (c) 2017, Applied Informatics Software Engineering GmbH |
9 | // and Contributors. |
10 | // |
11 | // SPDX-License-Identifier: BSL-1.0 |
12 | // |
13 | |
14 | #include "SHA3EngineTest.h" |
15 | #include "Poco/CppUnit/TestCaller.h" |
16 | #include "Poco/CppUnit/TestSuite.h" |
17 | #include "Poco/SHA3Engine.h" |
18 | |
19 | using Poco::SHA3Engine; |
20 | using Poco::DigestEngine; |
21 | |
22 | SHA3EngineTest::SHA3EngineTest(const std::string& rName): CppUnit::TestCase(rName) |
23 | { |
24 | } |
25 | |
26 | SHA3EngineTest::~SHA3EngineTest() |
27 | { |
28 | } |
29 | |
30 | void SHA3EngineTest::testSHA3_224() |
31 | { |
32 | SHA3Engine engine(SHA3Engine::SHA3_224); |
33 | |
34 | engine.update("abc"); |
35 | assertTrue (DigestEngine::digestToHex(engine.digest()) == "e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf"); |
36 | |
37 | engine.update("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"); |
38 | assertTrue (DigestEngine::digestToHex(engine.digest()) == "8a24108b154ada21c9fd5574494479ba5c7e7ab76ef264ead0fcce33"); |
39 | |
40 | engine.update("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"); |
41 | assertTrue (DigestEngine::digestToHex(engine.digest()) == "543e6868e1666c1a643630df77367ae5a62a85070a51c14cbf665cbc"); |
42 | |
43 | for (int i = 0; i < 1000000; ++i) |
44 | engine.update('a'); |
45 | assertTrue (DigestEngine::digestToHex(engine.digest()) == "d69335b93325192e516a912e6d19a15cb51c6ed5c15243e7a7fd653c"); |
46 | } |
47 | |
48 | void SHA3EngineTest::testSHA3_256() |
49 | { |
50 | SHA3Engine engine(SHA3Engine::SHA3_256); |
51 | |
52 | engine.update("abc"); |
53 | assertTrue (DigestEngine::digestToHex(engine.digest()) == "3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532"); |
54 | |
55 | engine.update("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"); |
56 | assertTrue (DigestEngine::digestToHex(engine.digest()) == "41c0dba2a9d6240849100376a8235e2c82e1b9998a999e21db32dd97496d3376"); |
57 | |
58 | engine.update("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"); |
59 | assertTrue (DigestEngine::digestToHex(engine.digest()) == "916f6061fe879741ca6469b43971dfdb28b1a32dc36cb3254e812be27aad1d18"); |
60 | |
61 | for (int i = 0; i < 1000000; ++i) |
62 | engine.update('a'); |
63 | assertTrue (DigestEngine::digestToHex(engine.digest()) == "5c8875ae474a3634ba4fd55ec85bffd661f32aca75c6d699d0cdcb6c115891c1"); |
64 | } |
65 | |
66 | void SHA3EngineTest::testSHA3_384() |
67 | { |
68 | SHA3Engine engine(SHA3Engine::SHA3_384); |
69 | |
70 | engine.update("abc"); |
71 | assertTrue (DigestEngine::digestToHex(engine.digest()) == "ec01498288516fc926459f58e2c6ad8df9b473cb0fc08c2596da7cf0e49be4b298d88cea927ac7f539f1edf228376d25"); |
72 | |
73 | engine.update("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"); |
74 | assertTrue (DigestEngine::digestToHex(engine.digest()) == "991c665755eb3a4b6bbdfb75c78a492e8c56a22c5c4d7e429bfdbc32b9d4ad5aa04a1f076e62fea19eef51acd0657c22"); |
75 | |
76 | engine.update("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"); |
77 | assertTrue (DigestEngine::digestToHex(engine.digest()) == "79407d3b5916b59c3e30b09822974791c313fb9ecc849e406f23592d04f625dc8c709b98b43b3852b337216179aa7fc7"); |
78 | |
79 | for (int i = 0; i < 1000000; ++i) |
80 | engine.update('a'); |
81 | assertTrue (DigestEngine::digestToHex(engine.digest()) == "eee9e24d78c1855337983451df97c8ad9eedf256c6334f8e948d252d5e0e76847aa0774ddb90a842190d2c558b4b8340"); |
82 | } |
83 | |
84 | void SHA3EngineTest::testSHA3_512() |
85 | { |
86 | SHA3Engine engine(SHA3Engine::SHA3_512); |
87 | |
88 | engine.update("abc"); |
89 | assertTrue (DigestEngine::digestToHex(engine.digest()) == "b751850b1a57168a5693cd924b6b096e08f621827444f70d884f5d0240d2712e10e116e9192af3c91a7ec57647e3934057340b4cf408d5a56592f8274eec53f0"); |
90 | |
91 | engine.update("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"); |
92 | assertTrue (DigestEngine::digestToHex(engine.digest()) == "04a371e84ecfb5b8b77cb48610fca8182dd457ce6f326a0fd3d7ec2f1e91636dee691fbe0c985302ba1b0d8dc78c086346b533b49c030d99a27daf1139d6e75e"); |
93 | |
94 | engine.update("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"); |
95 | assertTrue (DigestEngine::digestToHex(engine.digest()) == "afebb2ef542e6579c50cad06d2e578f9f8dd6881d7dc824d26360feebf18a4fa73e3261122948efcfd492e74e82e2189ed0fb440d187f382270cb455f21dd185"); |
96 | |
97 | for (int i = 0; i < 1000000; ++i) |
98 | engine.update('a'); |
99 | assertTrue (DigestEngine::digestToHex(engine.digest()) == "3c3a876da14034ab60627c077bb98f7e120a2a5370212dffb3385a18d4f38859ed311d0a9d5141ce9cc5c66ee689b266a8aa18ace8282a0e0db596c90b0a7b87"); |
100 | } |
101 | |
102 | void SHA3EngineTest::setUp() |
103 | { |
104 | } |
105 | |
106 | void SHA3EngineTest::tearDown() |
107 | { |
108 | } |
109 | |
110 | CppUnit::Test* SHA3EngineTest::suite() |
111 | { |
112 | CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("SHA3EngineTest"); |
113 | |
114 | CppUnit_addTest(pSuite, SHA3EngineTest, testSHA3_224); |
115 | CppUnit_addTest(pSuite, SHA3EngineTest, testSHA3_256); |
116 | CppUnit_addTest(pSuite, SHA3EngineTest, testSHA3_384); |
117 | CppUnit_addTest(pSuite, SHA3EngineTest, testSHA3_512); |
118 | |
119 | return pSuite; |
120 | } |
121 |