2 The software in this package is distributed under the GNU General
3 Public License version 2 (with a special exception described below).
5 A copy of GNU General Public License (GPL) is included in this distribution,
6 in the file COPYING.GPL.
8 As a special exception, if other files instantiate templates or use macros
9 or inline functions from this file, or you compile this file and link it
10 with other works to produce a work based on this file, this file
11 does not by itself cause the resulting work to be covered
12 by the GNU General Public License.
14 However the source code for this file must still be made available
15 in accordance with section (3) of the GNU General Public License.
17 This exception does not invalidate any other reasons why a work based
18 on this file might be covered by the GNU General Public License.
21 tests for the module "crypto"
23 @copyright Intra2net AG
25 #define BOOST_TEST_DYN_LINK
26 #include <boost/test/unit_test.hpp>
28 #include <tmpfstream.hpp>
39 class TestCryptoFixture
49 string tmpfile_name = "/tmp/libi2ncommon_test_crypto_XXXXXX";
50 Tempfile.open(tmpfile_name);
51 Tempfile << "Long Data and or Password";
54 Filename = Tempfile.get_tmp_filename();
69 BOOST_FIXTURE_TEST_SUITE(Crypto, TestCryptoFixture)
71 BOOST_AUTO_TEST_CASE(CheckHashMD5)
73 const string hash = hash_data("Long Data and or Password",
75 BOOST_CHECK_EQUAL(hash, string("E5952C81BBD04F9CB748433B9431F674"));
78 BOOST_AUTO_TEST_CASE(CheckHashSHA1)
80 const string hash = hash_data("Long Data and or Password",
82 BOOST_CHECK_EQUAL(hash, string("5935A22DAA087672FE2EA0E4485D58BC77E6068D"));
85 BOOST_AUTO_TEST_CASE(CheckHashSHA256)
87 const string hash = hash_data("Long Data and or Password",
89 BOOST_CHECK_EQUAL(hash, string("6D7F287A7E01ADF1A66C19D61C8D5A3BD68C1F"
90 "10565A6D37A5920B09152D62CE"));
93 BOOST_AUTO_TEST_CASE(CheckHashSHA384)
95 const string hash = hash_data("Long Data and or Password",
97 BOOST_CHECK_EQUAL(hash, string("1D879CCDFF4E50C32318A1F0FB8AF8A0B"
98 "150432CECAF41E5C7C0C75688E1F776"
99 "14CA70407A9BC97FDD1CEC4CF291B66B"));
102 BOOST_AUTO_TEST_CASE(CheckHashSHA512)
104 const string hash = hash_file(Filename,
106 BOOST_CHECK_EQUAL(hash, string("CBD561B4D1E13C08672CBCCAC855FAC3F4"
107 "7672548D0B61B0BB201017E4D93B239E"
108 "969DB3588F1466F34FB27A7D0AEFE203"
109 "594808E16659BEDD4B25F34EC46CDB"));
112 BOOST_AUTO_TEST_CASE(CheckHashFileMD5)
114 const string hash = hash_file(Filename,
116 BOOST_CHECK_EQUAL(hash, string("E5952C81BBD04F9CB748433B9431F674"));
119 BOOST_AUTO_TEST_CASE(CheckHashFileSHA1)
121 const string hash = hash_file(Filename,
123 BOOST_CHECK_EQUAL(hash, string("5935A22DAA087672FE2EA0E4485D58BC77E6068D"));
126 BOOST_AUTO_TEST_CASE(CheckHashFileSHA256)
128 const string hash = hash_file(Filename,
130 BOOST_CHECK_EQUAL(hash, string("6D7F287A7E01ADF1A66C19D61C8D5A3BD68C1F"
131 "10565A6D37A5920B09152D62CE"));
134 BOOST_AUTO_TEST_CASE(CheckHashFileSHA384)
136 const string hash = hash_file(Filename,
138 BOOST_CHECK_EQUAL(hash, string("1D879CCDFF4E50C32318A1F0FB8AF8A0B"
139 "150432CECAF41E5C7C0C75688E1F776"
140 "14CA70407A9BC97FDD1CEC4CF291B66B"));
143 BOOST_AUTO_TEST_CASE(CheckHashFileSHA512)
145 const string hash = hash_file(Filename,
147 BOOST_CHECK_EQUAL(hash, string("CBD561B4D1E13C08672CBCCAC855FAC3F4"
148 "7672548D0B61B0BB201017E4D93B239E"
149 "969DB3588F1466F34FB27A7D0AEFE203"
150 "594808E16659BEDD4B25F34EC46CDB"));
153 BOOST_AUTO_TEST_SUITE_END()