Mercurial > thymian
comparison 3rdparty/vmime/tests/security/digest/sha1Test.cpp @ 0:a4671277546c tip
created the repository for the thymian project
| author | ferencd |
|---|---|
| date | Tue, 17 Aug 2021 11:19:54 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:a4671277546c |
|---|---|
| 1 // | |
| 2 // VMime library (http://www.vmime.org) | |
| 3 // Copyright (C) 2002-2013 Vincent Richard <vincent@vmime.org> | |
| 4 // | |
| 5 // This program is free software; you can redistribute it and/or | |
| 6 // modify it under the terms of the GNU General Public License as | |
| 7 // published by the Free Software Foundation; either version 3 of | |
| 8 // the License, or (at your option) any later version. | |
| 9 // | |
| 10 // This program is distributed in the hope that it will be useful, | |
| 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 13 // General Public License for more details. | |
| 14 // | |
| 15 // You should have received a copy of the GNU General Public License along | |
| 16 // with this program; if not, write to the Free Software Foundation, Inc., | |
| 17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 18 // | |
| 19 // Linking this library statically or dynamically with other modules is making | |
| 20 // a combined work based on this library. Thus, the terms and conditions of | |
| 21 // the GNU General Public License cover the whole combination. | |
| 22 // | |
| 23 | |
| 24 #include "tests/testUtils.hpp" | |
| 25 | |
| 26 #include "vmime/security/digest/messageDigestFactory.hpp" | |
| 27 | |
| 28 | |
| 29 #define INIT_DIGEST(var, algo) \ | |
| 30 vmime::shared_ptr <vmime::security::digest::messageDigest> var = \ | |
| 31 vmime::security::digest::messageDigestFactory::getInstance()->create(algo) | |
| 32 | |
| 33 | |
| 34 | |
| 35 VMIME_TEST_SUITE_BEGIN(sha1Test) | |
| 36 | |
| 37 VMIME_TEST_LIST_BEGIN | |
| 38 VMIME_TEST(testFIPS180_1) | |
| 39 VMIME_TEST(testFIPS180_2) | |
| 40 VMIME_TEST(testFIPS180_3) | |
| 41 VMIME_TEST(testReset) | |
| 42 VMIME_TEST(testUpdate) | |
| 43 VMIME_TEST_LIST_END | |
| 44 | |
| 45 | |
| 46 // Test suites from FIPS PUB 180-1 | |
| 47 // http://www.itl.nist.gov/fipspubs/fip180-1.htm | |
| 48 | |
| 49 void testFIPS180_1() | |
| 50 { | |
| 51 INIT_DIGEST(algo, "sha1"); | |
| 52 | |
| 53 algo->update("abc"); | |
| 54 algo->finalize(); | |
| 55 | |
| 56 VASSERT_EQ("*", "a9993e364706816aba3e25717850c26c9cd0d89d", algo->getHexDigest()); | |
| 57 } | |
| 58 | |
| 59 void testFIPS180_2() | |
| 60 { | |
| 61 INIT_DIGEST(algo, "sha1"); | |
| 62 | |
| 63 algo->update("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"); | |
| 64 algo->finalize(); | |
| 65 | |
| 66 VASSERT_EQ("*", "84983e441c3bd26ebaae4aa1f95129e5e54670f1", algo->getHexDigest()); | |
| 67 } | |
| 68 | |
| 69 void testFIPS180_3() | |
| 70 { | |
| 71 INIT_DIGEST(algo, "sha1"); | |
| 72 | |
| 73 vmime::byte_t* buffer = new vmime::byte_t[1000000]; | |
| 74 | |
| 75 for (int i = 0 ; i < 1000000 ; ++i) | |
| 76 buffer[i] = 'a'; | |
| 77 | |
| 78 algo->update(buffer, 1000000); | |
| 79 algo->finalize(); | |
| 80 | |
| 81 delete [] buffer; | |
| 82 | |
| 83 VASSERT_EQ("*", "34aa973cd4c4daa4f61eeb2bdbad27316534016f", algo->getHexDigest()); | |
| 84 } | |
| 85 | |
| 86 void testReset() | |
| 87 { | |
| 88 INIT_DIGEST(algo, "sha1"); | |
| 89 | |
| 90 algo->update("ab"); | |
| 91 algo->update("c"); | |
| 92 algo->finalize(); | |
| 93 | |
| 94 algo->reset(); | |
| 95 algo->finalize(); | |
| 96 | |
| 97 VASSERT_EQ("*", "da39a3ee5e6b4b0d3255bfef95601890afd80709", algo->getHexDigest()); // empty string | |
| 98 } | |
| 99 | |
| 100 void testUpdate() | |
| 101 { | |
| 102 INIT_DIGEST(algo, "sha1"); | |
| 103 | |
| 104 algo->update("a"); | |
| 105 algo->update(""); | |
| 106 algo->update("bcdbcdecdefd"); | |
| 107 algo->update("efgef"); | |
| 108 algo->update("ghfghighijhijkijkljklmklmnlmnomnopnop"); | |
| 109 algo->update(""); | |
| 110 algo->update("q"); | |
| 111 algo->update(""); | |
| 112 algo->update(""); | |
| 113 algo->finalize(); | |
| 114 | |
| 115 VASSERT_EQ("*", "84983e441c3bd26ebaae4aa1f95129e5e54670f1", algo->getHexDigest()); | |
| 116 } | |
| 117 | |
| 118 VMIME_TEST_SUITE_END | |
| 119 |
