aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/pubkey/dh
diff options
context:
space:
mode:
authorlloyd <[email protected]>2015-02-04 04:03:38 +0000
committerlloyd <[email protected]>2015-02-04 04:03:38 +0000
commit0dd060fed07b0060f94e3bae62e125a85c1bb877 (patch)
treeed4bc7a961e2b30f17ed5e80769c84b0c313c8b7 /src/lib/pubkey/dh
parentf9a7c85b74be0f4a7273e8e0591703af83036e81 (diff)
Remove algo factory, engines, global RNG, global state, etc.
Convert all uses of Algorithm_Factory and the engines to using Algo_Registry The shared pool of entropy sources remains but is moved to EntropySource. With that and few remaining initializations (default OIDs and aliases) moved elsewhere, the global state is empty and init and shutdown are no-ops. Remove almost all of the headers and code for handling the global state, except LibraryInitializer which remains as a compatability stub. Update seeding for blinding so only one hacky almost-global RNG instance needs to be setup instead of across all pubkey uses (it uses either the system RNG or an AutoSeeded_RNG if the system RNG is not available).
Diffstat (limited to 'src/lib/pubkey/dh')
-rw-r--r--src/lib/pubkey/dh/dh.cpp31
-rw-r--r--src/lib/pubkey/dh/info.txt1
2 files changed, 11 insertions, 21 deletions
diff --git a/src/lib/pubkey/dh/dh.cpp b/src/lib/pubkey/dh/dh.cpp
index 8f44895ae..be411c5d8 100644
--- a/src/lib/pubkey/dh/dh.cpp
+++ b/src/lib/pubkey/dh/dh.cpp
@@ -11,12 +11,6 @@
#include <botan/pow_mod.h>
#include <botan/blinding.h>
-#if defined(BOTAN_HAS_SYSTEM_RNG)
- #include <botan/system_rng.h>
-#else
- #include <botan/auto_rng.h>
-#endif
-
namespace Botan {
/*
@@ -96,34 +90,31 @@ class DH_KA_Operation : public PK_Ops::Key_Agreement
secure_vector<byte> agree(const byte w[], size_t w_len);
private:
- const BigInt& p;
+ const BigInt& m_p;
- Fixed_Exponent_Power_Mod powermod_x_p;
- Blinder blinder;
+ Fixed_Exponent_Power_Mod m_powermod_x_p;
+ Blinder m_blinder;
};
DH_KA_Operation::DH_KA_Operation(const DH_PrivateKey& dh, const std::string&) :
- p(dh.group_p()), powermod_x_p(dh.get_x(), p)
+ m_p(dh.group_p()),
+ m_powermod_x_p(dh.get_x(), m_p),
+ m_blinder(m_p,
+ [](const BigInt& k) { return k; },
+ [this](const BigInt& k) { return m_powermod_x_p(inverse_mod(k, m_p)); })
{
-#if defined(BOTAN_HAS_SYSTEM_RNG)
- auto& rng = system_rng();
-#else
- AutoSeeded_RNG rng;
-#endif
- BigInt k(rng, p.bits() - 1);
- blinder = Blinder(k, powermod_x_p(inverse_mod(k, p)), p);
}
secure_vector<byte> DH_KA_Operation::agree(const byte w[], size_t w_len)
{
BigInt input = BigInt::decode(w, w_len);
- if(input <= 1 || input >= p - 1)
+ if(input <= 1 || input >= m_p - 1)
throw Invalid_Argument("DH agreement - invalid key provided");
- BigInt r = blinder.unblind(powermod_x_p(blinder.blind(input)));
+ BigInt r = m_blinder.unblind(m_powermod_x_p(m_blinder.blind(input)));
- return BigInt::encode_1363(r, p.bytes());
+ return BigInt::encode_1363(r, m_p.bytes());
}
}
diff --git a/src/lib/pubkey/dh/info.txt b/src/lib/pubkey/dh/info.txt
index bb2707951..13ee41d5b 100644
--- a/src/lib/pubkey/dh/info.txt
+++ b/src/lib/pubkey/dh/info.txt
@@ -11,6 +11,5 @@ dh.cpp
<requires>
dl_algo
dl_group
-libstate
numbertheory
</requires>