]>
Commit | Line | Data |
---|---|---|
1c2d079d | 1 | #ifndef BOOST_TEST_DYN_LINK |
7d280342 | 2 | #define BOOST_TEST_DYN_LINK |
1c2d079d FM |
3 | #endif |
4 | ||
7d280342 | 5 | #define BOOST_TEST_NO_MAIN |
6 | #ifdef HAVE_CONFIG_H | |
7 | #include "config.h" | |
8 | #endif | |
e41aadeb RG |
9 | |
10 | #ifdef HAVE_IPCIPHER | |
11 | ||
7d280342 | 12 | #include <boost/test/unit_test.hpp> |
cd63f25f | 13 | #include "ipcipher.hh" |
7d280342 | 14 | #include "misc.hh" |
15 | ||
16 | using namespace boost; | |
17 | ||
18 | BOOST_AUTO_TEST_SUITE(test_ipcrypt_hh) | |
19 | ||
20 | BOOST_AUTO_TEST_CASE(test_ipcrypt4) | |
21 | { | |
44677590 FM |
22 | ComboAddress address("127.0.0.1"); |
23 | std::string key = "0123456789ABCDEF"; | |
24 | auto encrypted = encryptCA(address, key); | |
7d280342 | 25 | |
26 | auto decrypted = decryptCA(encrypted, key); | |
44677590 | 27 | BOOST_CHECK_EQUAL(address.toString(), decrypted.toString()); |
7d280342 | 28 | } |
29 | ||
30 | BOOST_AUTO_TEST_CASE(test_ipcrypt4_vector) | |
31 | { | |
44677590 FM |
32 | // test vector from https://github.com/veorq/ipcrypt |
33 | vector<pair<string, string>> tests{{{"127.0.0.1"}, {"114.62.227.59"}}, | |
34 | {{"8.8.8.8"}, {"46.48.51.50"}}, | |
35 | {{"1.2.3.4"}, {"171.238.15.199"}}}; | |
7d280342 | 36 | |
44677590 | 37 | std::string key = "some 16-byte key"; |
7d280342 | 38 | |
44677590 | 39 | for (const auto& p : tests) { |
7d280342 | 40 | auto encrypted = encryptCA(ComboAddress(p.first), key); |
41 | BOOST_CHECK_EQUAL(encrypted.toString(), p.second); | |
42 | auto decrypted = decryptCA(encrypted, key); | |
43 | BOOST_CHECK_EQUAL(decrypted.toString(), p.first); | |
44 | } | |
45 | ||
83cfccaa | 46 | // test from Frank Denis' test.cc |
44677590 FM |
47 | ComboAddress address("192.168.69.42"); |
48 | ComboAddress out; | |
49 | ComboAddress dec; | |
7d280342 | 50 | string key2; |
44677590 FM |
51 | for (int n = 0; n < 16; ++n) { |
52 | key2.append(1, (char)n + 1); | |
53 | } | |
7d280342 | 54 | |
55 | for (unsigned int i = 0; i < 100000000UL; i++) { | |
44677590 | 56 | out = encryptCA(address, key2); |
7d280342 | 57 | // dec=decryptCA(out, key2); |
58 | // BOOST_CHECK(ip==dec); | |
44677590 | 59 | address = out; |
7d280342 | 60 | } |
61 | ||
62 | ComboAddress expected("93.155.197.186"); | |
63 | ||
44677590 | 64 | BOOST_CHECK_EQUAL(address.toString(), expected.toString()); |
7d280342 | 65 | } |
66 | ||
7d280342 | 67 | BOOST_AUTO_TEST_CASE(test_ipcrypt6) |
68 | { | |
44677590 FM |
69 | ComboAddress address("::1"); |
70 | std::string key = "0123456789ABCDEF"; | |
71 | auto encrypted = encryptCA(address, key); | |
7d280342 | 72 | |
73 | auto decrypted = decryptCA(encrypted, key); | |
44677590 | 74 | BOOST_CHECK_EQUAL(address.toString(), decrypted.toString()); |
7d280342 | 75 | } |
76 | ||
7d280342 | 77 | BOOST_AUTO_TEST_SUITE_END() |
e41aadeb RG |
78 | |
79 | #endif /* HAVE_IPCIPHER */ |