diff options
author | lloyd <[email protected]> | 2015-03-12 11:48:27 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2015-03-12 11:48:27 +0000 |
commit | ff26efb1c4b8530024dc9b42d75e39536ece6e11 (patch) | |
tree | 8f76ffab672673222b1c2bd8121c40fa2d765e62 /src/tests/test_rfc6979.cpp | |
parent | a06d7288968e205ca5f4df7cb3fcb3914353fb5f (diff) |
Externalize the state of a RFC 6979 nonce computation.
This lets you amortize quite a few memory allocations (RNG, various
BigInts, etc) over many nonce generations.
Change generate_rfc6979_nonce to just instantiate one of these states,
call the function once, and return. This doesn't have any additional
overhead versus the previous implementation of this function.
Fix HMAC_DRBG to correctly reset its state to its starting position
when you call clear() on it.
Diffstat (limited to 'src/tests/test_rfc6979.cpp')
-rw-r--r-- | src/tests/test_rfc6979.cpp | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/src/tests/test_rfc6979.cpp b/src/tests/test_rfc6979.cpp index 8ecc04fa3..4f286b96e 100644 --- a/src/tests/test_rfc6979.cpp +++ b/src/tests/test_rfc6979.cpp @@ -22,10 +22,12 @@ size_t rfc6979_testcase(const std::string& q_str, const std::string& hash, size_t testcase) { - using namespace Botan; + size_t fails = 0; #if defined(BOTAN_HAS_RFC6979_GENERATOR) + using namespace Botan; + const BigInt q(q_str); const BigInt x(x_str); const BigInt h(h_str); @@ -37,12 +39,38 @@ size_t rfc6979_testcase(const std::string& q_str, { std::cout << "RFC 6979 test #" << testcase << " failed; generated k=" << std::hex << gen_k << "\n"; - return 1; + ++fails; + } + + RFC6979_Nonce_Generator gen(hash, q, x); + + const BigInt gen_0 = gen.nonce_for(h); + if(gen_0 != exp_k) + { + std::cout << "RFC 6979 test #" << testcase << " failed; generated k=" + << std::hex << gen_k << " (gen_0)\n"; + ++fails; + } + + const BigInt gen_1 = gen.nonce_for(h+1); + if(gen_1 == exp_k) + { + std::cout << "RFC 6979 test #" << testcase << " failed; generated k=" + << std::hex << gen_1 << " (gen_1)\n"; + ++fails; + } + + const BigInt gen_2 = gen.nonce_for(h); + if(gen_2 != exp_k) + { + std::cout << "RFC 6979 test #" << testcase << " failed; generated k=" + << std::hex << gen_2 << " (gen_2)\n"; + ++fails; } #endif - return 0; + return fails; } } |