aboutsummaryrefslogtreecommitdiffstats
path: root/checks/hash.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2013-12-31 21:38:18 +0000
committerlloyd <[email protected]>2013-12-31 21:38:18 +0000
commitc5dc7598403b5f7e739b2c27707663b16c4199f8 (patch)
tree632042be775d298f648247b824b97d493dca889d /checks/hash.cpp
parent7947d9787fe1cf448a418e2252edededdf887032 (diff)
Split up tests by type
Diffstat (limited to 'checks/hash.cpp')
-rw-r--r--checks/hash.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/checks/hash.cpp b/checks/hash.cpp
new file mode 100644
index 000000000..29cd4d42c
--- /dev/null
+++ b/checks/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 {
+
+bool 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 == 0);
+ }
+
+}
+
+size_t test_hash()
+ {
+ std::ifstream vec("checks/hash.vec");
+
+ return run_tests_bb(vec, "Hash", "Out", true,
+ [](std::map<std::string, std::string> m) -> bool
+ {
+ return hash_test(m["Hash"], m["In"], m["Out"]);
+ });
+ }