aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2013-03-16 17:44:36 +0000
committerlloyd <[email protected]>2013-03-16 17:44:36 +0000
commit3b6eac4497ecf68053d28dd7f84056ee469129d7 (patch)
treec4d93674550e6642e197cae80c58788e928fc92c
parent35c5cbed2ebe0eb72e2ff665b78a9027d17c19ec (diff)
Add algorithm_kat_detailed which returns a string with info about the failure
-rw-r--r--checks/validate.cpp12
-rw-r--r--doc/relnotes/1_11_3.rst4
-rw-r--r--src/selftest/selftest.cpp51
-rw-r--r--src/selftest/selftest.h13
4 files changed, 60 insertions, 20 deletions
diff --git a/checks/validate.cpp b/checks/validate.cpp
index 48bc6bd87..388d4940e 100644
--- a/checks/validate.cpp
+++ b/checks/validate.cpp
@@ -439,18 +439,18 @@ bool failed_test(const std::string& algo,
if(params.size() > 3)
vars["iv"] = params[3];
- std::map<std::string, bool> results =
- algorithm_kat(algo, vars, global_state().algorithm_factory());
+ Algorithm_Factory& af = global_state().algorithm_factory();
+
+ const auto results = algorithm_kat_detailed(algo, vars, af);
if(results.size())
{
- for(std::map<std::string, bool>::const_iterator i = results.begin();
- i != results.end(); ++i)
+ for(auto i : results)
{
- if(i->second == false)
+ if(i.second != "passed")
{
std::cout << algo << " test with provider "
- << i->first << " failed\n";
+ << i.first << " failed - " << i.second << "\n";
return true;
}
}
diff --git a/doc/relnotes/1_11_3.rst b/doc/relnotes/1_11_3.rst
index 244e3cfae..0b12a8439 100644
--- a/doc/relnotes/1_11_3.rst
+++ b/doc/relnotes/1_11_3.rst
@@ -2,3 +2,7 @@ Version 1.11.3, Not Yet Released
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
* New functions for symmetric encryption are included in cryptobox.h
+
+* A new function :cpp:func:`algorithm_kat_detailed` returns a string
+ providing information about failures, instead of just a pass/fail
+ indicator as in :cpp:func:`algorithm_kat`.
diff --git a/src/selftest/selftest.cpp b/src/selftest/selftest.cpp
index 8f4dc70d8..4be0fa4cf 100644
--- a/src/selftest/selftest.cpp
+++ b/src/selftest/selftest.cpp
@@ -10,6 +10,8 @@
#include <botan/internal/core_engine.h>
#include <botan/internal/stl_util.h>
+#include <iostream>
+
namespace Botan {
namespace {
@@ -17,16 +19,21 @@ namespace {
/*
* Perform a Known Answer Test
*/
-bool test_filter_kat(Filter* filter,
- const std::string& input,
- const std::string& expected_output)
+std::string test_filter_kat(Filter* filter,
+ const std::string& input,
+ const std::string& expected)
{
Pipe pipe(new Hex_Decoder, filter, new Hex_Encoder);
pipe.process_msg(input);
- const std::string output = pipe.read_all_as_string();
+ const std::string got = pipe.read_all_as_string();
+
+ const bool same = (got == expected);
- return (output == expected_output);
+ if(same)
+ return "passed";
+ else
+ return (std::string("got ") + got + " expected " + expected);
}
}
@@ -34,15 +41,15 @@ bool test_filter_kat(Filter* filter,
/*
* Run a set of KATs
*/
-std::map<std::string, bool>
-algorithm_kat(const SCAN_Name& algo_name,
- const std::map<std::string, std::string>& vars,
- Algorithm_Factory& af)
+std::map<std::string, std::string>
+algorithm_kat_detailed(const SCAN_Name& algo_name,
+ const std::map<std::string, std::string>& vars,
+ Algorithm_Factory& af)
{
const std::string& algo = algo_name.algo_name_and_args();
std::vector<std::string> providers = af.providers_of(algo);
- std::map<std::string, bool> all_results;
+ std::map<std::string, std::string> all_results;
if(providers.empty()) // no providers, nothing to do
return all_results;
@@ -110,16 +117,32 @@ algorithm_kat(const SCAN_Name& algo_name,
else if(!dec->valid_iv_length(0))
throw Invalid_IV_Length(algo, iv.length());
- bool enc_ok = test_filter_kat(enc, input, output);
- bool dec_ok = test_filter_kat(dec, output, input);
-
- all_results[provider] = enc_ok && dec_ok;
+ all_results[provider + " (encrypt)"] = test_filter_kat(enc, input, output);
+ all_results[provider + " (decrypt)"] = test_filter_kat(dec, output, input);
}
}
return all_results;
}
+std::map<std::string, bool>
+algorithm_kat(const SCAN_Name& algo_name,
+ const std::map<std::string, std::string>& vars,
+ Algorithm_Factory& af)
+ {
+ const auto result = algorithm_kat_detailed(algo_name, vars, af);
+
+ std::map<std::string, bool> pass_or_fail;
+
+ for(auto i : result)
+ {
+ //std::cout << i.first << " " << i.second << "\n";
+ pass_or_fail[i.first] = (i.second == "passed");
+ }
+
+ return pass_or_fail;
+ }
+
namespace {
void verify_results(const std::string& algo,
diff --git a/src/selftest/selftest.h b/src/selftest/selftest.h
index 091206579..2ceadd0d4 100644
--- a/src/selftest/selftest.h
+++ b/src/selftest/selftest.h
@@ -42,6 +42,19 @@ algorithm_kat(const SCAN_Name& algo_name,
const std::map<std::string, std::string>& vars,
Algorithm_Factory& af);
+/**
+* Run a set of algorithm KATs (known answer tests)
+* @param algo_name the algorithm we are testing
+* @param vars a set of input variables for this test, all
+ hex encoded. Keys used: "input", "output", "key", and "iv"
+* @param af an algorithm factory
+* @returns map from provider name to test result for that provider
+*/
+BOTAN_DLL std::map<std::string, std::string>
+algorithm_kat_detailed(const SCAN_Name& algo_name,
+ const std::map<std::string, std::string>& vars,
+ Algorithm_Factory& af);
+
}
#endif