diff options
author | lloyd <[email protected]> | 2014-01-07 11:03:55 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2014-01-07 11:03:55 +0000 |
commit | c109c7f84fcef6ba895c6293508b2deae0e803c1 (patch) | |
tree | 35ba7b55914023a77ecfbcf5dee2befcc4e275d1 /src/tests/kat_hash.cpp | |
parent | a7e3abf95fd1bc3df45be6fc9cb82e28e0a727ea (diff) |
Rename test sources
Diffstat (limited to 'src/tests/kat_hash.cpp')
-rw-r--r-- | src/tests/kat_hash.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/tests/kat_hash.cpp b/src/tests/kat_hash.cpp new file mode 100644 index 000000000..55510b9f4 --- /dev/null +++ b/src/tests/kat_hash.cpp @@ -0,0 +1,60 @@ +#include "tests.h" + +#include <botan/libstate.h> +#include <botan/hash.h> +#include <botan/hex.h> +#include <iostream> +#include <fstream> + +using namespace Botan; + +namespace { + +size_t hash_test(const std::string& algo, + 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_hash_function(algo, provider); + + if(!proto) + { + std::cout << "Unable to get " << algo << " from " << provider << "\n"; + ++fails; + continue; + } + + std::unique_ptr<HashFunction> hash(proto->clone()); + + hash->update(hex_decode(in_hex)); + + auto h = hash->final(); + + if(h != hex_decode_locked(out_hex)) + { + std::cout << algo << " " << provider << " got " << hex_encode(h) << " != " << out_hex << "\n"; + ++fails; + } + } + + return fails; + } + +} + +size_t test_hash() + { + std::ifstream vec(TEST_DATA_DIR "/hash.vec"); + + return run_tests_bb(vec, "Hash", "Out", true, + [](std::map<std::string, std::string> m) -> size_t + { + return hash_test(m["Hash"], m["In"], m["Out"]); + }); + } |