diff options
author | lloyd <[email protected]> | 2014-01-05 06:23:21 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2014-01-05 06:23:21 +0000 |
commit | c431fb65b883a0a5fa060ea7caace0aca3628ec6 (patch) | |
tree | 09898d2307801bffa7e1aeee9251d57ed4837870 /src/tests/test_dlies.cpp | |
parent | 052345203b67eb5cacacd5659ec9837eeb59af35 (diff) |
Split up public key tests and data, use new test framework
Diffstat (limited to 'src/tests/test_dlies.cpp')
-rw-r--r-- | src/tests/test_dlies.cpp | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/src/tests/test_dlies.cpp b/src/tests/test_dlies.cpp new file mode 100644 index 000000000..cd931fd35 --- /dev/null +++ b/src/tests/test_dlies.cpp @@ -0,0 +1,77 @@ +#include "tests.h" +#include "test_pubkey.h" + +#include <botan/auto_rng.h> +#include <botan/pubkey.h> +#include <botan/lookup.h> +#include <botan/dlies.h> +#include <botan/dh.h> +#include <botan/hex.h> +#include <iostream> +#include <fstream> + +using namespace Botan; + +namespace { + +size_t dlies_kat(const std::string& p, + const std::string& g, + const std::string& x1, + const std::string& x2, + const std::string& msg, + const std::string& ciphertext) + { + AutoSeeded_RNG rng; + + BigInt p_bn(p); + BigInt g_bn(g); + BigInt x1_bn(x1); + BigInt x2_bn(x2); + + DL_Group domain(p_bn, g_bn); + + DH_PrivateKey from(rng, domain, x1_bn); + DH_PrivateKey to(rng, domain, x2_bn); + + const std::string opt_str = "KDF2(SHA-1)/HMAC(SHA-1)/16"; + + std::vector<std::string> options = split_on(opt_str, '/'); + + if(options.size() != 3) + throw std::runtime_error("DLIES needs three options: " + opt_str); + + const size_t mac_key_len = to_u32bit(options[2]); + + DLIES_Encryptor e(from, + get_kdf(options[0]), + get_mac(options[1]), + mac_key_len); + + DLIES_Decryptor d(to, + get_kdf(options[0]), + get_mac(options[1]), + mac_key_len); + + e.set_other_key(to.public_value()); + + const std::string empty = ""; + return validate_encryption(e, d, "DLIES", msg, empty, ciphertext); + } + +} + +size_t test_dlies() + { + std::ifstream dlies(TEST_DATA_DIR "/dlies.vec"); + + size_t fails = 0; + + fails += run_tests_bb(dlies, "DLIES Encryption", "Ciphertext", true, + [](std::map<std::string, std::string> m) -> size_t + { + return dlies_kat(m["P"], m["G"], m["X1"], m["X2"], m["Msg"], m["Ciphertext"]); + }); + + return fails; + } + |