aboutsummaryrefslogtreecommitdiffstats
path: root/src/pubkey
diff options
context:
space:
mode:
authorlloyd <[email protected]>2013-12-25 19:57:13 +0000
committerlloyd <[email protected]>2013-12-25 19:57:13 +0000
commita4a59c29500bbae02273bfb75ddb8318a449e851 (patch)
tree7779f1c9b2708e55eb0f7ad1d5208753a1966ce1 /src/pubkey
parent4d2242a5e920ba14e37c69a8962b34d08cd485f6 (diff)
Remove global_rng calls for setting up blinding, instead require a RNG
be passed to the engine. Currently pubkey.cpp just passes along the global_rng but eventually we'll break this API and require a RNG to the constructor.
Diffstat (limited to 'src/pubkey')
-rw-r--r--src/pubkey/dh/dh.cpp6
-rw-r--r--src/pubkey/dh/dh.h3
-rw-r--r--src/pubkey/elgamal/elgamal.cpp6
-rw-r--r--src/pubkey/elgamal/elgamal.h3
-rw-r--r--src/pubkey/pubkey.cpp17
-rw-r--r--src/pubkey/rsa/rsa.cpp6
-rw-r--r--src/pubkey/rsa/rsa.h3
7 files changed, 26 insertions, 18 deletions
diff --git a/src/pubkey/dh/dh.cpp b/src/pubkey/dh/dh.cpp
index 956552c7d..80e690c24 100644
--- a/src/pubkey/dh/dh.cpp
+++ b/src/pubkey/dh/dh.cpp
@@ -7,7 +7,6 @@
#include <botan/dh.h>
#include <botan/numthry.h>
-#include <botan/libstate.h>
#include <botan/internal/workfactor.h>
namespace Botan {
@@ -76,10 +75,11 @@ std::vector<byte> DH_PrivateKey::public_value() const
return DH_PublicKey::public_value();
}
-DH_KA_Operation::DH_KA_Operation(const DH_PrivateKey& dh) :
+DH_KA_Operation::DH_KA_Operation(const DH_PrivateKey& dh,
+ RandomNumberGenerator& rng) :
p(dh.group_p()), powermod_x_p(dh.get_x(), p)
{
- BigInt k(global_state().global_rng(), std::min<size_t>(160, p.bits() - 1));
+ BigInt k(rng, p.bits() - 1);
blinder = Blinder(k, powermod_x_p(inverse_mod(k, p)), p);
}
diff --git a/src/pubkey/dh/dh.h b/src/pubkey/dh/dh.h
index bf02ffdb9..c670399d8 100644
--- a/src/pubkey/dh/dh.h
+++ b/src/pubkey/dh/dh.h
@@ -78,7 +78,8 @@ class BOTAN_DLL DH_PrivateKey : public DH_PublicKey,
class BOTAN_DLL DH_KA_Operation : public PK_Ops::Key_Agreement
{
public:
- DH_KA_Operation(const DH_PrivateKey& key);
+ DH_KA_Operation(const DH_PrivateKey& key,
+ RandomNumberGenerator& rng);
secure_vector<byte> agree(const byte w[], size_t w_len);
private:
diff --git a/src/pubkey/elgamal/elgamal.cpp b/src/pubkey/elgamal/elgamal.cpp
index 837528af8..3e22aee1a 100644
--- a/src/pubkey/elgamal/elgamal.cpp
+++ b/src/pubkey/elgamal/elgamal.cpp
@@ -7,7 +7,6 @@
#include <botan/elgamal.h>
#include <botan/numthry.h>
-#include <botan/libstate.h>
#include <botan/keypair.h>
#include <botan/internal/workfactor.h>
@@ -98,14 +97,15 @@ ElGamal_Encryption_Operation::encrypt(const byte msg[], size_t msg_len,
return output;
}
-ElGamal_Decryption_Operation::ElGamal_Decryption_Operation(const ElGamal_PrivateKey& key)
+ElGamal_Decryption_Operation::ElGamal_Decryption_Operation(const ElGamal_PrivateKey& key,
+ RandomNumberGenerator& rng)
{
const BigInt& p = key.group_p();
powermod_x_p = Fixed_Exponent_Power_Mod(key.get_x(), p);
mod_p = Modular_Reducer(p);
- BigInt k(global_state().global_rng(), std::min<size_t>(160, p.bits() - 1));
+ BigInt k(rng, p.bits() - 1);
blinder = Blinder(k, powermod_x_p(k), p);
}
diff --git a/src/pubkey/elgamal/elgamal.h b/src/pubkey/elgamal/elgamal.h
index 957aa4656..9566bcca6 100644
--- a/src/pubkey/elgamal/elgamal.h
+++ b/src/pubkey/elgamal/elgamal.h
@@ -81,7 +81,8 @@ class BOTAN_DLL ElGamal_Decryption_Operation : public PK_Ops::Decryption
public:
size_t max_input_bits() const { return mod_p.get_modulus().bits() - 1; }
- ElGamal_Decryption_Operation(const ElGamal_PrivateKey& key);
+ ElGamal_Decryption_Operation(const ElGamal_PrivateKey& key,
+ RandomNumberGenerator& rng);
secure_vector<byte> decrypt(const byte msg[], size_t msg_len);
private:
diff --git a/src/pubkey/pubkey.cpp b/src/pubkey/pubkey.cpp
index 2f4120ae1..313d54c16 100644
--- a/src/pubkey/pubkey.cpp
+++ b/src/pubkey/pubkey.cpp
@@ -25,10 +25,11 @@ PK_Encryptor_EME::PK_Encryptor_EME(const Public_Key& key,
const std::string& eme_name)
{
Algorithm_Factory::Engine_Iterator i(global_state().algorithm_factory());
+ RandomNumberGenerator& rng = global_state().global_rng();
while(const Engine* engine = i.next())
{
- op = engine->get_encryption_op(key);
+ op = engine->get_encryption_op(key, rng);
if(op)
break;
}
@@ -84,10 +85,11 @@ PK_Decryptor_EME::PK_Decryptor_EME(const Private_Key& key,
const std::string& eme_name)
{
Algorithm_Factory::Engine_Iterator i(global_state().algorithm_factory());
+ RandomNumberGenerator& rng = global_state().global_rng();
while(const Engine* engine = i.next())
{
- op = engine->get_decryption_op(key);
+ op = engine->get_decryption_op(key, rng);
if(op)
break;
}
@@ -126,6 +128,7 @@ PK_Signer::PK_Signer(const Private_Key& key,
Fault_Protection prot)
{
Algorithm_Factory::Engine_Iterator i(global_state().algorithm_factory());
+ RandomNumberGenerator& rng = global_state().global_rng();
op = nullptr;
verify_op = nullptr;
@@ -133,10 +136,10 @@ PK_Signer::PK_Signer(const Private_Key& key,
while(const Engine* engine = i.next())
{
if(!op)
- op = engine->get_signature_op(key);
+ op = engine->get_signature_op(key, rng);
if(!verify_op && prot == ENABLE_FAULT_PROTECTION)
- verify_op = engine->get_verify_op(key);
+ verify_op = engine->get_verify_op(key, rng);
if(op && (verify_op || prot == DISABLE_FAULT_PROTECTION))
break;
@@ -244,10 +247,11 @@ PK_Verifier::PK_Verifier(const Public_Key& key,
Signature_Format format)
{
Algorithm_Factory::Engine_Iterator i(global_state().algorithm_factory());
+ RandomNumberGenerator& rng = global_state().global_rng();
while(const Engine* engine = i.next())
{
- op = engine->get_verify_op(key);
+ op = engine->get_verify_op(key, rng);
if(op)
break;
}
@@ -352,10 +356,11 @@ PK_Key_Agreement::PK_Key_Agreement(const PK_Key_Agreement_Key& key,
const std::string& kdf_name)
{
Algorithm_Factory::Engine_Iterator i(global_state().algorithm_factory());
+ RandomNumberGenerator& rng = global_state().global_rng();
while(const Engine* engine = i.next())
{
- op = engine->get_key_agreement_op(key);
+ op = engine->get_key_agreement_op(key, rng);
if(op)
break;
}
diff --git a/src/pubkey/rsa/rsa.cpp b/src/pubkey/rsa/rsa.cpp
index 5b6820e49..199ce6ad8 100644
--- a/src/pubkey/rsa/rsa.cpp
+++ b/src/pubkey/rsa/rsa.cpp
@@ -6,7 +6,6 @@
*/
#include <botan/rsa.h>
-#include <botan/libstate.h>
#include <botan/parsing.h>
#include <botan/numthry.h>
#include <botan/keypair.h>
@@ -60,7 +59,8 @@ bool RSA_PrivateKey::check_key(RandomNumberGenerator& rng, bool strong) const
return KeyPair::signature_consistency_check(rng, *this, "EMSA4(SHA-1)");
}
-RSA_Private_Operation::RSA_Private_Operation(const RSA_PrivateKey& rsa) :
+RSA_Private_Operation::RSA_Private_Operation(const RSA_PrivateKey& rsa,
+ RandomNumberGenerator& rng) :
n(rsa.get_n()),
q(rsa.get_q()),
c(rsa.get_c()),
@@ -69,7 +69,7 @@ RSA_Private_Operation::RSA_Private_Operation(const RSA_PrivateKey& rsa) :
powermod_d2_q(rsa.get_d2(), rsa.get_q()),
mod_p(rsa.get_p())
{
- BigInt k(global_state().global_rng(), std::min<size_t>(160, n.bits() - 1));
+ BigInt k(rng, n.bits() - 1);
blinder = Blinder(powermod_e_n(k), inverse_mod(k, n), n);
}
diff --git a/src/pubkey/rsa/rsa.h b/src/pubkey/rsa/rsa.h
index 0942d92ad..4d9189d20 100644
--- a/src/pubkey/rsa/rsa.h
+++ b/src/pubkey/rsa/rsa.h
@@ -90,7 +90,8 @@ class BOTAN_DLL RSA_Private_Operation : public PK_Ops::Signature,
public PK_Ops::Decryption
{
public:
- RSA_Private_Operation(const RSA_PrivateKey& rsa);
+ RSA_Private_Operation(const RSA_PrivateKey& rsa,
+ RandomNumberGenerator& rng);
size_t max_input_bits() const { return (n.bits() - 1); }