diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/tests/data/pubkey/workfactor.vec | 37 | ||||
-rw-r--r-- | src/tests/test_workfactor.cpp | 45 |
2 files changed, 82 insertions, 0 deletions
diff --git a/src/tests/data/pubkey/workfactor.vec b/src/tests/data/pubkey/workfactor.vec new file mode 100644 index 000000000..f75f034cc --- /dev/null +++ b/src/tests/data/pubkey/workfactor.vec @@ -0,0 +1,37 @@ +[RSA_Strength] +ParamSize = 1024 +Workfactor = 80 + +ParamSize = 1536 +Workfactor = 97 + +ParamSize = 2048 +Workfactor = 111 + +ParamSize = 3072 +Workfactor = 132 + +ParamSize = 4096 +Workfactor = 150 + +ParamSize = 8192 +Workfactor = 202 + +[DL_Exponent_Size] +ParamSize = 1024 +Workfactor = 86 + +ParamSize = 1536 +Workfactor = 103 + +ParamSize = 2048 +Workfactor = 116 + +ParamSize = 3072 +Workfactor = 138 + +ParamSize = 4096 +Workfactor = 156 + +ParamSize = 8192 +Workfactor = 208 diff --git a/src/tests/test_workfactor.cpp b/src/tests/test_workfactor.cpp new file mode 100644 index 000000000..d9ad38e23 --- /dev/null +++ b/src/tests/test_workfactor.cpp @@ -0,0 +1,45 @@ +/* +* (C) 2016 Jack Lloyd +* +* Botan is released under the Simplified BSD License (see license.txt) +*/ + +#include "tests.h" + +#if defined(BOTAN_HAS_PUBLIC_KEY_CRYPTO) + #include <botan/workfactor.h> +#endif + +namespace Botan_Tests { + +class PK_Workfactor_Tests : public Text_Based_Test + { + public: + PK_Workfactor_Tests() : Text_Based_Test("pubkey/workfactor.vec", + {"ParamSize", "Workfactor"}) + {} + + Test::Result run_one_test(const std::string& type, const VarMap& vars) override + { + const size_t param_size = get_req_sz(vars, "ParamSize"); + const size_t exp_output = get_req_sz(vars, "Workfactor"); + + size_t output = 0; + + // TODO: test McEliece strength tests also + + if(type == "RSA_Strength") + output = Botan::if_work_factor(param_size); + else if(type == "DL_Exponent_Size") + output = Botan::dl_exponent_size(param_size) / 2; + + Test::Result result(type + " work factor calculation"); + result.test_eq("Calculated workfactor for " + std::to_string(param_size), + output, exp_output); + return result; + } + }; + +BOTAN_REGISTER_TEST("pk_workfactor", PK_Workfactor_Tests); + +} |