aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/if_algo.h4
-rw-r--r--src/if_algo.cpp32
-rw-r--r--src/rsa.cpp10
-rw-r--r--src/rw.cpp10
4 files changed, 30 insertions, 26 deletions
diff --git a/include/if_algo.h b/include/if_algo.h
index 5f5fa4ce2..2df8723a4 100644
--- a/include/if_algo.h
+++ b/include/if_algo.h
@@ -28,7 +28,7 @@ class BOTAN_DLL IF_Scheme_PublicKey : public virtual Public_Key
X509_Encoder* x509_encoder() const;
X509_Decoder* x509_decoder();
protected:
- virtual void X509_load_hook();
+ virtual void X509_load_hook(RandomNumberGenerator&);
BigInt n, e;
IF_Core core;
};
@@ -49,7 +49,7 @@ class BOTAN_DLL IF_Scheme_PrivateKey : public virtual IF_Scheme_PublicKey,
PKCS8_Encoder* pkcs8_encoder() const;
PKCS8_Decoder* pkcs8_decoder();
protected:
- virtual void PKCS8_load_hook(bool = false);
+ virtual void PKCS8_load_hook(RandomNumberGenerator&, bool = false);
BigInt d, p, q, d1, d2, c;
};
diff --git a/src/if_algo.cpp b/src/if_algo.cpp
index 209c51c46..2bd508c86 100644
--- a/src/if_algo.cpp
+++ b/src/if_algo.cpp
@@ -62,15 +62,17 @@ X509_Decoder* IF_Scheme_PublicKey::x509_decoder()
.verify_end()
.end_cons();
- key->X509_load_hook();
+ key->X509_load_hook(rng);
}
- IF_Scheme_Decoder(IF_Scheme_PublicKey* k) : key(k) {}
+ IF_Scheme_Decoder(IF_Scheme_PublicKey* k, RandomNumberGenerator& r) :
+ key(k), rng(r) {}
private:
IF_Scheme_PublicKey* key;
+ RandomNumberGenerator& rng;
};
- return new IF_Scheme_Decoder(this);
+ return new IF_Scheme_Decoder(this, global_state().prng_reference());
}
/*************************************************
@@ -142,43 +144,45 @@ PKCS8_Decoder* IF_Scheme_PrivateKey::pkcs8_decoder()
if(version != 0)
throw Decoding_Error("Unknown PKCS #1 key format version");
- key->PKCS8_load_hook();
+ key->PKCS8_load_hook(rng);
}
- IF_Scheme_Decoder(IF_Scheme_PrivateKey* k) : key(k) {}
+ IF_Scheme_Decoder(IF_Scheme_PrivateKey* k, RandomNumberGenerator& r) :
+ key(k), rng(r) {}
private:
IF_Scheme_PrivateKey* key;
+ RandomNumberGenerator& rng;
};
- return new IF_Scheme_Decoder(this);
+ return new IF_Scheme_Decoder(this, global_state().prng_reference());
}
/*************************************************
* Algorithm Specific X.509 Initialization Code *
*************************************************/
-void IF_Scheme_PublicKey::X509_load_hook()
+void IF_Scheme_PublicKey::X509_load_hook(RandomNumberGenerator& rng)
{
- core = IF_Core(global_state().prng_reference(), e, n);
- load_check(global_state().prng_reference());
+ core = IF_Core(rng, e, n);
+ load_check(rng);
}
/*************************************************
* Algorithm Specific PKCS #8 Initialization Code *
*************************************************/
-void IF_Scheme_PrivateKey::PKCS8_load_hook(bool generated)
+void IF_Scheme_PrivateKey::PKCS8_load_hook(RandomNumberGenerator& rng,
+ bool generated)
{
if(n == 0) n = p * q;
if(d1 == 0) d1 = d % (p - 1);
if(d2 == 0) d2 = d % (q - 1);
if(c == 0) c = inverse_mod(q, p);
- core = IF_Core(global_state().prng_reference(),
- e, n, d, p, q, d1, d2, c);
+ core = IF_Core(rng, e, n, d, p, q, d1, d2, c);
if(generated)
- gen_check(global_state().prng_reference());
+ gen_check(rng);
else
- load_check(global_state().prng_reference());
+ load_check(rng);
}
/*************************************************
diff --git a/src/rsa.cpp b/src/rsa.cpp
index d9bf9e22b..07b2e4da9 100644
--- a/src/rsa.cpp
+++ b/src/rsa.cpp
@@ -7,6 +7,7 @@
#include <botan/numthry.h>
#include <botan/keypair.h>
#include <botan/parsing.h>
+#include <botan/libstate.h>
namespace Botan {
@@ -17,7 +18,7 @@ RSA_PublicKey::RSA_PublicKey(const BigInt& mod, const BigInt& exp)
{
n = mod;
e = exp;
- X509_load_hook();
+ X509_load_hook(global_state().prng_reference());
}
/*************************************************
@@ -52,8 +53,7 @@ SecureVector<byte> RSA_PublicKey::verify(const byte in[], u32bit len) const
/*************************************************
* Create a RSA private key *
*************************************************/
-RSA_PrivateKey::RSA_PrivateKey(u32bit bits,
- RandomNumberGenerator& rng,
+RSA_PrivateKey::RSA_PrivateKey(u32bit bits, RandomNumberGenerator& rng,
u32bit exp)
{
if(bits < 1024)
@@ -67,7 +67,7 @@ RSA_PrivateKey::RSA_PrivateKey(u32bit bits,
q = random_prime(rng, bits - p.bits(), e);
d = inverse_mod(e, lcm(p - 1, q - 1));
- PKCS8_load_hook(true);
+ PKCS8_load_hook(rng, true);
if(n.bits() != bits)
throw Self_Test_Failure(algo_name() + " private key generation failed");
@@ -89,7 +89,7 @@ RSA_PrivateKey::RSA_PrivateKey(const BigInt& prime1, const BigInt& prime2,
if(d == 0)
d = inverse_mod(e, lcm(p - 1, q - 1));
- PKCS8_load_hook();
+ PKCS8_load_hook(global_state().prng_reference());
}
/*************************************************
diff --git a/src/rw.cpp b/src/rw.cpp
index 2574df442..cf0ca72ba 100644
--- a/src/rw.cpp
+++ b/src/rw.cpp
@@ -7,6 +7,7 @@
#include <botan/numthry.h>
#include <botan/keypair.h>
#include <botan/parsing.h>
+#include <botan/libstate.h>
#include <algorithm>
namespace Botan {
@@ -18,7 +19,7 @@ RW_PublicKey::RW_PublicKey(const BigInt& mod, const BigInt& exp)
{
n = mod;
e = exp;
- X509_load_hook();
+ X509_load_hook(global_state().prng_reference());
}
/*************************************************
@@ -52,8 +53,7 @@ SecureVector<byte> RW_PublicKey::verify(const byte in[], u32bit len) const
/*************************************************
* Create a Rabin-Williams private key *
*************************************************/
-RW_PrivateKey::RW_PrivateKey(u32bit bits,
- RandomNumberGenerator& rng,
+RW_PrivateKey::RW_PrivateKey(u32bit bits, RandomNumberGenerator& rng,
u32bit exp)
{
if(bits < 1024)
@@ -67,7 +67,7 @@ RW_PrivateKey::RW_PrivateKey(u32bit bits,
q = random_prime(rng, bits - p.bits(), e / 2, ((p % 8 == 3) ? 7 : 3), 8);
d = inverse_mod(e, lcm(p - 1, q - 1) >> 1);
- PKCS8_load_hook(true);
+ PKCS8_load_hook(rng, true);
if(n.bits() != bits)
throw Self_Test_Failure(algo_name() + " private key generation failed");
@@ -89,7 +89,7 @@ RW_PrivateKey::RW_PrivateKey(const BigInt& prime1, const BigInt& prime2,
if(d == 0)
d = inverse_mod(e, lcm(p - 1, q - 1) >> 1);
- PKCS8_load_hook();
+ PKCS8_load_hook(global_state().prng_reference());
}
/*************************************************