aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/test_hash.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2014-01-10 23:07:16 +0000
committerlloyd <[email protected]>2014-01-10 23:07:16 +0000
commitad6555f522ae16f6284e8dafa02f630b88bcf289 (patch)
treebd63c51dbeab75eb0f90c72589bc922141237056 /src/tests/test_hash.cpp
parent6894dca64c04936d07048c0e8cbf7e25858548c3 (diff)
Split up docs into the reference manual, the website, and everything else.
Add `website` target to makefile. Some progress towards fixing minimized builds. TLS now hard requires ECDSA and GCM since otherwise a minimized build has only insecure options. Remove boost_thread dependency in command line tool
Diffstat (limited to 'src/tests/test_hash.cpp')
-rw-r--r--src/tests/test_hash.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/tests/test_hash.cpp b/src/tests/test_hash.cpp
new file mode 100644
index 000000000..eaa3ff3b5
--- /dev/null
+++ b/src/tests/test_hash.cpp
@@ -0,0 +1,65 @@
+#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()
+ {
+ auto test = [](const std::string& input)
+ {
+ std::ifstream vec(input);
+
+ 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"]);
+ });
+ };
+
+ return run_tests_in_dir(TEST_DATA_DIR "hash", test);
+ }