diff options
author | Jack Lloyd <[email protected]> | 2016-11-03 16:41:57 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2016-11-03 16:41:57 -0400 |
commit | 0b820c330a62aaa3a715b7b7d00276f886cd4a0f (patch) | |
tree | 0fb61052bca179ac0a11d5a746756640124234e0 /src/tests/test_bigint.cpp | |
parent | ffbc4f3d88b77ab389e460df1adde320c81b3be2 (diff) |
Add test for DSA parameter generation
Limited to 1024 bit params by default to keep runtimes reasonable,
but test vectors for all sizes from FIPS 186-3 do pass.
Diffstat (limited to 'src/tests/test_bigint.cpp')
-rw-r--r-- | src/tests/test_bigint.cpp | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/src/tests/test_bigint.cpp b/src/tests/test_bigint.cpp index cee7b5b8b..3d9fd7139 100644 --- a/src/tests/test_bigint.cpp +++ b/src/tests/test_bigint.cpp @@ -6,7 +6,7 @@ #include "tests.h" -#if defined(BOTAN_HAS_BIGINT) +#if defined(BOTAN_HAS_NUMBERTHEORY) #include <botan/bigint.h> #include <botan/numthry.h> #include <botan/reducer.h> @@ -17,7 +17,7 @@ namespace Botan_Tests { namespace { -#if defined(BOTAN_HAS_BIGINT) +#if defined(BOTAN_HAS_NUMBERTHEORY) using Botan::BigInt; @@ -508,6 +508,48 @@ class BigInt_InvMod_Test : public Text_Based_Test BOTAN_REGISTER_TEST("bn_invmod", BigInt_InvMod_Test); +class DSA_ParamGen_Test : public Text_Based_Test + { + public: + DSA_ParamGen_Test() : Text_Based_Test("bn/dsa_gen.vec", {"P","Q","Seed"}) {} + + Test::Result run_one_test(const std::string& header, const VarMap& vars) override + { + const std::vector<byte> seed = get_req_bin(vars, "Seed"); + const Botan::BigInt P = get_req_bn(vars, "P"); + const Botan::BigInt Q = get_req_bn(vars, "Q"); + + const std::vector<std::string> header_parts = Botan::split_on(header, ','); + + if(header_parts.size() != 2) + throw Test_Error("Unexpected header '" + header + "' in DSA param gen test"); + + const size_t p_bits = Botan::to_u32bit(header_parts[1]); + const size_t q_bits = Botan::to_u32bit(header_parts[0]); + + Test::Result result("DSA Parameter Generation"); + + // These tests are very slow so skip in normal runs + if(Test::soak_level() <= 5 && p_bits > 1024) + return result; + + Botan::BigInt gen_P, gen_Q; + if(Botan::generate_dsa_primes(Test::rng(), gen_P, gen_Q, p_bits, q_bits, seed)) + { + result.test_eq("P", gen_P, P); + result.test_eq("Q", gen_Q, Q); + } + else + { + result.test_failure("Seed did not generate a DSA parameter"); + } + + return result; + } + }; + +BOTAN_REGISTER_TEST("dsa_param", DSA_ParamGen_Test); + #endif } |