aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/pubkey/rfc6979/rfc6979.h
diff options
context:
space:
mode:
authorlloyd <[email protected]>2015-03-12 11:48:27 +0000
committerlloyd <[email protected]>2015-03-12 11:48:27 +0000
commitff26efb1c4b8530024dc9b42d75e39536ece6e11 (patch)
tree8f76ffab672673222b1c2bd8121c40fa2d765e62 /src/lib/pubkey/rfc6979/rfc6979.h
parenta06d7288968e205ca5f4df7cb3fcb3914353fb5f (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/lib/pubkey/rfc6979/rfc6979.h')
-rw-r--r--src/lib/pubkey/rfc6979/rfc6979.h24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/lib/pubkey/rfc6979/rfc6979.h b/src/lib/pubkey/rfc6979/rfc6979.h
index 8e2940578..5b3dee8ef 100644
--- a/src/lib/pubkey/rfc6979/rfc6979.h
+++ b/src/lib/pubkey/rfc6979/rfc6979.h
@@ -1,6 +1,6 @@
/*
* RFC 6979 Deterministic Nonce Generator
-* (C) 2014 Jack Lloyd
+* (C) 2014,2015 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
@@ -10,9 +10,31 @@
#include <botan/bigint.h>
#include <string>
+#include <memory>
namespace Botan {
+class RandomNumberGenerator;
+
+class BOTAN_DLL RFC6979_Nonce_Generator
+ {
+ public:
+ /**
+ * Note: keeps persistent reference to order
+ */
+ RFC6979_Nonce_Generator(const std::string& hash,
+ const BigInt& order,
+ const BigInt& x);
+
+ const BigInt& nonce_for(const BigInt& m);
+ private:
+ const BigInt& m_order;
+ BigInt m_k;
+ size_t m_qlen, m_rlen;
+ std::unique_ptr<RandomNumberGenerator> m_hmac_drbg;
+ secure_vector<byte> m_rng_in, m_rng_out;
+ };
+
/**
* @param x the secret (EC)DSA key
* @param q the group order