25
25
26
26
#include < boost/test/unit_test.hpp>
27
27
28
- BOOST_FIXTURE_TEST_SUITE (crypto_tests, BasicTestingSetup)
28
+ namespace crypto_tests {
29
+ struct CryptoTest : BasicTestingSetup {
29
30
30
31
template <typename Hasher, typename In, typename Out>
31
- static void TestVector(const Hasher &h, const In &in, const Out &out) {
32
+ void TestVector (const Hasher &h, const In &in, const Out &out) {
32
33
Out hash;
33
34
BOOST_CHECK (out.size () == h.OUTPUT_SIZE );
34
35
hash.resize (out.size ());
@@ -56,22 +57,22 @@ static void TestVector(const Hasher &h, const In &in, const Out &out) {
56
57
}
57
58
}
58
59
59
- static void TestSHA1 (const std::string &in, const std::string &hexout) { TestVector (CSHA1 (), in, ParseHex (hexout));}
60
- static void TestSHA256 (const std::string &in, const std::string &hexout) { TestVector (CSHA256 (), in, ParseHex (hexout));}
61
- static void TestSHA512 (const std::string &in, const std::string &hexout) { TestVector (CSHA512 (), in, ParseHex (hexout));}
62
- static void TestRIPEMD160 (const std::string &in, const std::string &hexout) { TestVector (CRIPEMD160 (), in, ParseHex (hexout));}
60
+ void TestSHA1 (const std::string &in, const std::string &hexout) { TestVector (CSHA1 (), in, ParseHex (hexout));}
61
+ void TestSHA256 (const std::string &in, const std::string &hexout) { TestVector (CSHA256 (), in, ParseHex (hexout));}
62
+ void TestSHA512 (const std::string &in, const std::string &hexout) { TestVector (CSHA512 (), in, ParseHex (hexout));}
63
+ void TestRIPEMD160 (const std::string &in, const std::string &hexout) { TestVector (CRIPEMD160 (), in, ParseHex (hexout));}
63
64
64
- static void TestHMACSHA256 (const std::string &hexkey, const std::string &hexin, const std::string &hexout) {
65
+ void TestHMACSHA256 (const std::string &hexkey, const std::string &hexin, const std::string &hexout) {
65
66
std::vector<unsigned char > key = ParseHex (hexkey);
66
67
TestVector (CHMAC_SHA256 (key.data (), key.size ()), ParseHex (hexin), ParseHex (hexout));
67
68
}
68
69
69
- static void TestHMACSHA512 (const std::string &hexkey, const std::string &hexin, const std::string &hexout) {
70
+ void TestHMACSHA512 (const std::string &hexkey, const std::string &hexin, const std::string &hexout) {
70
71
std::vector<unsigned char > key = ParseHex (hexkey);
71
72
TestVector (CHMAC_SHA512 (key.data (), key.size ()), ParseHex (hexin), ParseHex (hexout));
72
73
}
73
74
74
- static void TestAES256 (const std::string &hexkey, const std::string &hexin, const std::string &hexout)
75
+ void TestAES256 (const std::string &hexkey, const std::string &hexin, const std::string &hexout)
75
76
{
76
77
std::vector<unsigned char > key = ParseHex (hexkey);
77
78
std::vector<unsigned char > in = ParseHex (hexin);
@@ -90,7 +91,7 @@ static void TestAES256(const std::string &hexkey, const std::string &hexin, cons
90
91
BOOST_CHECK (buf == in);
91
92
}
92
93
93
- static void TestAES256CBC (const std::string &hexkey, const std::string &hexiv, bool pad, const std::string &hexin, const std::string &hexout)
94
+ void TestAES256CBC (const std::string &hexkey, const std::string &hexiv, bool pad, const std::string &hexin, const std::string &hexout)
94
95
{
95
96
std::vector<unsigned char > key = ParseHex (hexkey);
96
97
std::vector<unsigned char > iv = ParseHex (hexiv);
@@ -131,7 +132,7 @@ static void TestAES256CBC(const std::string &hexkey, const std::string &hexiv, b
131
132
}
132
133
}
133
134
134
- static void TestChaCha20 (const std::string &hex_message, const std::string &hexkey, ChaCha20::Nonce96 nonce, uint32_t seek, const std::string& hexout)
135
+ void TestChaCha20 (const std::string &hex_message, const std::string &hexkey, ChaCha20::Nonce96 nonce, uint32_t seek, const std::string& hexout)
135
136
{
136
137
auto key = ParseHex<std::byte>(hexkey);
137
138
assert (key.size () == 32 );
@@ -182,7 +183,7 @@ static void TestChaCha20(const std::string &hex_message, const std::string &hexk
182
183
}
183
184
}
184
185
185
- static void TestFSChaCha20 (const std::string& hex_plaintext, const std::string& hexkey, uint32_t rekey_interval, const std::string& ciphertext_after_rotation)
186
+ void TestFSChaCha20 (const std::string& hex_plaintext, const std::string& hexkey, uint32_t rekey_interval, const std::string& ciphertext_after_rotation)
186
187
{
187
188
auto key = ParseHex<std::byte>(hexkey);
188
189
BOOST_CHECK_EQUAL (FSChaCha20::KEYLEN, key.size ());
@@ -222,7 +223,7 @@ static void TestFSChaCha20(const std::string& hex_plaintext, const std::string&
222
223
BOOST_CHECK_EQUAL (HexStr (fsc20_output), ciphertext_after_rotation);
223
224
}
224
225
225
- static void TestPoly1305 (const std::string &hexmessage, const std::string &hexkey, const std::string& hextag)
226
+ void TestPoly1305 (const std::string &hexmessage, const std::string &hexkey, const std::string& hextag)
226
227
{
227
228
auto key = ParseHex<std::byte>(hexkey);
228
229
auto m = ParseHex<std::byte>(hexmessage);
@@ -247,7 +248,7 @@ static void TestPoly1305(const std::string &hexmessage, const std::string &hexke
247
248
}
248
249
}
249
250
250
- static void TestChaCha20Poly1305 (const std::string& plain_hex, const std::string& aad_hex, const std::string& key_hex, ChaCha20::Nonce96 nonce, const std::string& cipher_hex)
251
+ void TestChaCha20Poly1305 (const std::string& plain_hex, const std::string& aad_hex, const std::string& key_hex, ChaCha20::Nonce96 nonce, const std::string& cipher_hex)
251
252
{
252
253
auto plain = ParseHex<std::byte>(plain_hex);
253
254
auto aad = ParseHex<std::byte>(aad_hex);
@@ -288,7 +289,7 @@ static void TestChaCha20Poly1305(const std::string& plain_hex, const std::string
288
289
}
289
290
}
290
291
291
- static void TestFSChaCha20Poly1305 (const std::string& plain_hex, const std::string& aad_hex, const std::string& key_hex, uint64_t msg_idx, const std::string& cipher_hex)
292
+ void TestFSChaCha20Poly1305 (const std::string& plain_hex, const std::string& aad_hex, const std::string& key_hex, uint64_t msg_idx, const std::string& cipher_hex)
292
293
{
293
294
auto plain = ParseHex<std::byte>(plain_hex);
294
295
auto aad = ParseHex<std::byte>(aad_hex);
@@ -334,7 +335,7 @@ static void TestFSChaCha20Poly1305(const std::string& plain_hex, const std::stri
334
335
}
335
336
}
336
337
337
- static void TestHKDF_SHA256_32 (const std::string &ikm_hex, const std::string &salt_hex, const std::string &info_hex, const std::string &okm_check_hex) {
338
+ void TestHKDF_SHA256_32 (const std::string &ikm_hex, const std::string &salt_hex, const std::string &info_hex, const std::string &okm_check_hex) {
338
339
std::vector<unsigned char > initial_key_material = ParseHex (ikm_hex);
339
340
std::vector<unsigned char > salt = ParseHex (salt_hex);
340
341
std::vector<unsigned char > info = ParseHex (info_hex);
@@ -350,6 +351,10 @@ static void TestHKDF_SHA256_32(const std::string &ikm_hex, const std::string &sa
350
351
BOOST_CHECK (HexStr (out) == okm_check_hex);
351
352
}
352
353
354
+ void TestSHA3_256 (const std::string& input, const std::string& output);
355
+ }; // struct CryptoTests
356
+ } // namespace crypto_tests
357
+
353
358
static std::string LongTestString ()
354
359
{
355
360
std::string ret;
@@ -365,6 +370,8 @@ static std::string LongTestString()
365
370
366
371
const std::string test1 = LongTestString();
367
372
373
+ BOOST_FIXTURE_TEST_SUITE (crypto_tests, CryptoTest)
374
+
368
375
BOOST_AUTO_TEST_CASE(ripemd160_testvectors) {
369
376
TestRIPEMD160 (" " , " 9c1185a5c5e9fc54612808977ee8f548b2258d31" );
370
377
TestRIPEMD160 (" abc" , " 8eb208f7e05d987a9b044a8e98c6b087f15a0bfc" );
@@ -1076,7 +1083,7 @@ BOOST_AUTO_TEST_CASE(sha256d64)
1076
1083
}
1077
1084
}
1078
1085
1079
- static void TestSHA3_256 (const std::string& input, const std::string& output)
1086
+ void CryptoTest:: TestSHA3_256 (const std::string& input, const std::string& output)
1080
1087
{
1081
1088
const auto in_bytes = ParseHex (input);
1082
1089
const auto out_bytes = ParseHex (output);
0 commit comments