From 197dc467dec28a04c3b2f30da7cef122dfbb13e9 Mon Sep 17 00:00:00 2001 From: lloyd Date: Wed, 1 Jan 2014 21:20:55 +0000 Subject: Shuffle things around. Add NIST X.509 test to build. --- src/tests/test_mac.cpp | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/tests/test_mac.cpp (limited to 'src/tests/test_mac.cpp') diff --git a/src/tests/test_mac.cpp b/src/tests/test_mac.cpp new file mode 100644 index 000000000..31f159663 --- /dev/null +++ b/src/tests/test_mac.cpp @@ -0,0 +1,62 @@ +#include "tests.h" + +#include +#include +#include +#include +#include + +using namespace Botan; + +namespace { + +bool mac_test(const std::string& algo, + const std::string& key_hex, + const std::string& in_hex, + const std::string& out_hex) + { + Algorithm_Factory& af = global_state().algorithm_factory(); + + const auto providers = af.providers_of(algo); + size_t fails = 0; + + for(auto provider: providers) + { + auto proto = af.prototype_mac(algo, provider); + + if(!proto) + { + std::cout << "Unable to get " << algo << " from " << provider << "\n"; + ++fails; + continue; + } + + std::unique_ptr mac(proto->clone()); + + mac->set_key(hex_decode(key_hex)); + mac->update(hex_decode(in_hex)); + + auto h = mac->final(); + + if(h != hex_decode_locked(out_hex)) + { + std::cout << algo << " " << provider << " got " << hex_encode(h) << " != " << out_hex << "\n"; + ++fails; + } + } + + return (fails == 0); + } + +} + +size_t test_mac() + { + std::ifstream vec(CHECKS_DIR "/mac.vec"); + + return run_tests_bb(vec, "Mac", "Out", true, + [](std::map m) -> bool + { + return mac_test(m["Mac"], m["Key"], m["In"], m["Out"]); + }); + } -- cgit v1.2.3