aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-06-27 14:29:33 +0000
committerlloyd <[email protected]>2008-06-27 14:29:33 +0000
commit34d5da54da524018580935da11525bd72b5a560e (patch)
tree398e07f035b4e72bf7a315f0d9f1e6e55b46795f /src
parentd1bc1ae91003bc10b46b0d1e38f0ac64080b4c81 (diff)
Remove load checking, as it requires an RNG (at least at the moment).
Probably some variation of it will be added back in later, at least to do basic checks like that primes are really odd (and we can do basic primality checks, etc, even with an RNG). Alternative: call check_key() manually on public keys you load with an RNG object.
Diffstat (limited to 'src')
-rw-r--r--src/dh.cpp6
-rw-r--r--src/dl_algo.cpp12
-rw-r--r--src/dsa.cpp6
-rw-r--r--src/elgamal.cpp8
-rw-r--r--src/if_algo.cpp14
-rw-r--r--src/nr.cpp6
-rw-r--r--src/pk_core.cpp22
-rw-r--r--src/rsa.cpp13
-rw-r--r--src/rw.cpp14
-rw-r--r--src/x509_key.cpp4
10 files changed, 47 insertions, 58 deletions
diff --git a/src/dh.cpp b/src/dh.cpp
index 159eb0629..8d2059936 100644
--- a/src/dh.cpp
+++ b/src/dh.cpp
@@ -5,7 +5,6 @@
#include <botan/dh.h>
#include <botan/numthry.h>
-#include <botan/libstate.h>
#include <botan/util.h>
namespace Botan {
@@ -17,15 +16,14 @@ DH_PublicKey::DH_PublicKey(const DL_Group& grp, const BigInt& y1)
{
group = grp;
y = y1;
- X509_load_hook(global_state().prng_reference());
+ X509_load_hook();
}
/*************************************************
* Algorithm Specific X.509 Initialization Code *
*************************************************/
-void DH_PublicKey::X509_load_hook(RandomNumberGenerator& rng)
+void DH_PublicKey::X509_load_hook()
{
- load_check(rng);
}
/*************************************************
diff --git a/src/dl_algo.cpp b/src/dl_algo.cpp
index 7fc364389..2b59a334e 100644
--- a/src/dl_algo.cpp
+++ b/src/dl_algo.cpp
@@ -7,7 +7,6 @@
#include <botan/numthry.h>
#include <botan/der_enc.h>
#include <botan/ber_dec.h>
-#include <botan/libstate.h>
namespace Botan {
@@ -43,7 +42,7 @@ X509_Encoder* DL_Scheme_PublicKey::x509_encoder() const
/*************************************************
* Return the X.509 public key decoder *
*************************************************/
-X509_Decoder* DL_Scheme_PublicKey::x509_decoder(RandomNumberGenerator& rng)
+X509_Decoder* DL_Scheme_PublicKey::x509_decoder()
{
class DL_Scheme_Decoder : public X509_Decoder
{
@@ -57,18 +56,15 @@ X509_Decoder* DL_Scheme_PublicKey::x509_decoder(RandomNumberGenerator& rng)
void key_bits(const MemoryRegion<byte>& bits)
{
BER_Decoder(bits).decode(key->y);
- key->X509_load_hook(rng);
+ key->X509_load_hook();
}
- DL_Scheme_Decoder(DL_Scheme_PublicKey* k,
- RandomNumberGenerator& r) :
- key(k), rng(r) {}
+ DL_Scheme_Decoder(DL_Scheme_PublicKey* k) : key(k) {}
private:
DL_Scheme_PublicKey* key;
- RandomNumberGenerator& rng;
};
- return new DL_Scheme_Decoder(this, rng);
+ return new DL_Scheme_Decoder(this);
}
/*************************************************
diff --git a/src/dsa.cpp b/src/dsa.cpp
index 8ca2f7db5..a7eb8e789 100644
--- a/src/dsa.cpp
+++ b/src/dsa.cpp
@@ -6,7 +6,6 @@
#include <botan/dsa.h>
#include <botan/numthry.h>
#include <botan/keypair.h>
-#include <botan/libstate.h>
namespace Botan {
@@ -17,16 +16,15 @@ DSA_PublicKey::DSA_PublicKey(const DL_Group& grp, const BigInt& y1)
{
group = grp;
y = y1;
- X509_load_hook(global_state().prng_reference());
+ X509_load_hook();
}
/*************************************************
* Algorithm Specific X.509 Initialization Code *
*************************************************/
-void DSA_PublicKey::X509_load_hook(RandomNumberGenerator& rng)
+void DSA_PublicKey::X509_load_hook()
{
core = DSA_Core(group, y);
- load_check(rng);
}
/*************************************************
diff --git a/src/elgamal.cpp b/src/elgamal.cpp
index d97a365e7..ea0d581b0 100644
--- a/src/elgamal.cpp
+++ b/src/elgamal.cpp
@@ -7,7 +7,6 @@
#include <botan/numthry.h>
#include <botan/keypair.h>
#include <botan/util.h>
-#include <botan/libstate.h>
namespace Botan {
@@ -18,16 +17,15 @@ ElGamal_PublicKey::ElGamal_PublicKey(const DL_Group& grp, const BigInt& y1)
{
group = grp;
y = y1;
- X509_load_hook(global_state().prng_reference());
+ X509_load_hook();
}
/*************************************************
* Algorithm Specific X.509 Initialization Code *
*************************************************/
-void ElGamal_PublicKey::X509_load_hook(RandomNumberGenerator& rng)
+void ElGamal_PublicKey::X509_load_hook()
{
- core = ELG_Core(rng, group, y);
- load_check(rng);
+ core = ELG_Core(group, y);
}
/*************************************************
diff --git a/src/if_algo.cpp b/src/if_algo.cpp
index 072822f2a..929f488fd 100644
--- a/src/if_algo.cpp
+++ b/src/if_algo.cpp
@@ -7,7 +7,6 @@
#include <botan/numthry.h>
#include <botan/der_enc.h>
#include <botan/ber_dec.h>
-#include <botan/libstate.h>
namespace Botan {
@@ -46,7 +45,7 @@ X509_Encoder* IF_Scheme_PublicKey::x509_encoder() const
/*************************************************
* Return the X.509 public key decoder *
*************************************************/
-X509_Decoder* IF_Scheme_PublicKey::x509_decoder(RandomNumberGenerator& rng)
+X509_Decoder* IF_Scheme_PublicKey::x509_decoder()
{
class IF_Scheme_Decoder : public X509_Decoder
{
@@ -62,17 +61,15 @@ X509_Decoder* IF_Scheme_PublicKey::x509_decoder(RandomNumberGenerator& rng)
.verify_end()
.end_cons();
- key->X509_load_hook(rng);
+ key->X509_load_hook();
}
- IF_Scheme_Decoder(IF_Scheme_PublicKey* k, RandomNumberGenerator& r) :
- key(k), rng(r) {}
+ IF_Scheme_Decoder(IF_Scheme_PublicKey* k) : key(k) {}
private:
IF_Scheme_PublicKey* key;
- RandomNumberGenerator& rng;
};
- return new IF_Scheme_Decoder(this, rng);
+ return new IF_Scheme_Decoder(this);
}
/*************************************************
@@ -160,10 +157,9 @@ PKCS8_Decoder* IF_Scheme_PrivateKey::pkcs8_decoder(RandomNumberGenerator& rng)
/*************************************************
* Algorithm Specific X.509 Initialization Code *
*************************************************/
-void IF_Scheme_PublicKey::X509_load_hook(RandomNumberGenerator& rng)
+void IF_Scheme_PublicKey::X509_load_hook()
{
core = IF_Core(e, n);
- load_check(rng);
}
/*************************************************
diff --git a/src/nr.cpp b/src/nr.cpp
index de46abd80..02919d52e 100644
--- a/src/nr.cpp
+++ b/src/nr.cpp
@@ -6,7 +6,6 @@
#include <botan/nr.h>
#include <botan/numthry.h>
#include <botan/keypair.h>
-#include <botan/libstate.h>
namespace Botan {
@@ -17,16 +16,15 @@ NR_PublicKey::NR_PublicKey(const DL_Group& grp, const BigInt& y1)
{
group = grp;
y = y1;
- X509_load_hook(global_state().prng_reference());
+ X509_load_hook();
}
/*************************************************
* Algorithm Specific X.509 Initialization Code *
*************************************************/
-void NR_PublicKey::X509_load_hook(RandomNumberGenerator& rng)
+void NR_PublicKey::X509_load_hook()
{
core = NR_Core(group, y);
- load_check(rng);
}
/*************************************************
diff --git a/src/pk_core.cpp b/src/pk_core.cpp
index 200e5c964..939ad1c1f 100644
--- a/src/pk_core.cpp
+++ b/src/pk_core.cpp
@@ -179,21 +179,27 @@ SecureVector<byte> NR_Core::sign(const byte in[], u32bit length,
/*************************************************
* ELG_Core Constructor *
*************************************************/
+ELG_Core::ELG_Core(const DL_Group& group, const BigInt& y)
+ {
+ op = Engine_Core::elg_op(group, y, 0);
+ p_bytes = 0;
+ }
+
+/*************************************************
+* ELG_Core Constructor *
+*************************************************/
ELG_Core::ELG_Core(RandomNumberGenerator& rng,
const DL_Group& group, const BigInt& y, const BigInt& x)
{
op = Engine_Core::elg_op(group, y, x);
- p_bytes = 0;
- if(x != 0)
- {
- const BigInt& p = group.get_p();
- p_bytes = p.bytes();
+ const BigInt& p = group.get_p();
+ p_bytes = p.bytes();
+ if(BLINDING_BITS)
+ {
BigInt k(rng, std::min(p.bits()-1, BLINDING_BITS));
-
- if(k != 0)
- blinder = Blinder(k, power_mod(k, x, p), p);
+ blinder = Blinder(k, power_mod(k, x, p), p);
}
}
diff --git a/src/rsa.cpp b/src/rsa.cpp
index 07b2e4da9..65eb0af1f 100644
--- a/src/rsa.cpp
+++ b/src/rsa.cpp
@@ -1,6 +1,6 @@
/*************************************************
* RSA Source File *
-* (C) 1999-2007 Jack Lloyd *
+* (C) 1999-2008 Jack Lloyd *
*************************************************/
#include <botan/rsa.h>
@@ -18,7 +18,7 @@ RSA_PublicKey::RSA_PublicKey(const BigInt& mod, const BigInt& exp)
{
n = mod;
e = exp;
- X509_load_hook(global_state().prng_reference());
+ X509_load_hook();
}
/*************************************************
@@ -53,8 +53,8 @@ SecureVector<byte> RSA_PublicKey::verify(const byte in[], u32bit len) const
/*************************************************
* Create a RSA private key *
*************************************************/
-RSA_PrivateKey::RSA_PrivateKey(u32bit bits, RandomNumberGenerator& rng,
- u32bit exp)
+RSA_PrivateKey::RSA_PrivateKey(RandomNumberGenerator& rng,
+ u32bit bits, u32bit exp)
{
if(bits < 1024)
throw Invalid_Argument(algo_name() + ": Can't make a key that is only " +
@@ -76,7 +76,8 @@ RSA_PrivateKey::RSA_PrivateKey(u32bit bits, RandomNumberGenerator& rng,
/*************************************************
* RSA_PrivateKey Constructor *
*************************************************/
-RSA_PrivateKey::RSA_PrivateKey(const BigInt& prime1, const BigInt& prime2,
+RSA_PrivateKey::RSA_PrivateKey(RandomNumberGenerator& rng,
+ const BigInt& prime1, const BigInt& prime2,
const BigInt& exp, const BigInt& d_exp,
const BigInt& mod)
{
@@ -89,7 +90,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(global_state().prng_reference());
+ PKCS8_load_hook(rng);
}
/*************************************************
diff --git a/src/rw.cpp b/src/rw.cpp
index cf0ca72ba..4cbed6097 100644
--- a/src/rw.cpp
+++ b/src/rw.cpp
@@ -1,13 +1,12 @@
/*************************************************
* Rabin-Williams Source File *
-* (C) 1999-2007 Jack Lloyd *
+* (C) 1999-2008 Jack Lloyd *
*************************************************/
#include <botan/rw.h>
#include <botan/numthry.h>
#include <botan/keypair.h>
#include <botan/parsing.h>
-#include <botan/libstate.h>
#include <algorithm>
namespace Botan {
@@ -19,7 +18,7 @@ RW_PublicKey::RW_PublicKey(const BigInt& mod, const BigInt& exp)
{
n = mod;
e = exp;
- X509_load_hook(global_state().prng_reference());
+ X509_load_hook();
}
/*************************************************
@@ -53,8 +52,8 @@ 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,
- u32bit exp)
+RW_PrivateKey::RW_PrivateKey(RandomNumberGenerator& rng,
+ u32bit bits, u32bit exp)
{
if(bits < 1024)
throw Invalid_Argument(algo_name() + ": Can't make a key that is only " +
@@ -76,7 +75,8 @@ RW_PrivateKey::RW_PrivateKey(u32bit bits, RandomNumberGenerator& rng,
/*************************************************
* RW_PrivateKey Constructor *
*************************************************/
-RW_PrivateKey::RW_PrivateKey(const BigInt& prime1, const BigInt& prime2,
+RW_PrivateKey::RW_PrivateKey(RandomNumberGenerator& rng,
+ const BigInt& prime1, const BigInt& prime2,
const BigInt& exp, const BigInt& d_exp,
const BigInt& mod)
{
@@ -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(global_state().prng_reference());
+ PKCS8_load_hook(rng);
}
/*************************************************
diff --git a/src/x509_key.cpp b/src/x509_key.cpp
index f327aac16..26ce16a72 100644
--- a/src/x509_key.cpp
+++ b/src/x509_key.cpp
@@ -11,7 +11,6 @@
#include <botan/pk_algs.h>
#include <botan/oids.h>
#include <botan/pem.h>
-#include <botan/libstate.h>
#include <memory>
namespace Botan {
@@ -98,8 +97,7 @@ Public_Key* load_key(DataSource& source)
throw Decoding_Error("Unknown PK algorithm/OID: " + alg_name + ", " +
alg_id.oid.as_string());
- std::auto_ptr<X509_Decoder> decoder(
- key_obj->x509_decoder(global_state().prng_reference()));
+ std::auto_ptr<X509_Decoder> decoder(key_obj->x509_decoder());
if(!decoder.get())
throw Decoding_Error("Key does not support X.509 decoding");