From 0b820c330a62aaa3a715b7b7d00276f886cd4a0f Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Thu, 3 Nov 2016 16:41:57 -0400 Subject: 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. --- src/tests/test_bigint.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) (limited to 'src/tests/test_bigint.cpp') 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 #include #include @@ -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 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 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 } -- cgit v1.2.3