diff options
-rw-r--r-- | checks/pk.cpp | 20 | ||||
-rw-r--r-- | doc/examples/dh.cpp | 7 | ||||
-rw-r--r-- | doc/examples/dsa_kgen.cpp | 7 | ||||
-rw-r--r-- | doc/examples/factor.cpp | 5 | ||||
-rw-r--r-- | doc/examples/pkcs10.cpp | 6 | ||||
-rw-r--r-- | doc/examples/rsa_kgen.cpp | 5 | ||||
-rw-r--r-- | doc/examples/self_sig.cpp | 7 | ||||
-rw-r--r-- | include/dl_algo.h | 4 | ||||
-rw-r--r-- | include/dsa.h | 2 | ||||
-rw-r--r-- | include/elgamal.h | 2 | ||||
-rw-r--r-- | include/if_algo.h | 4 | ||||
-rw-r--r-- | include/nr.h | 2 | ||||
-rw-r--r-- | include/pk_keys.h | 4 | ||||
-rw-r--r-- | include/rsa.h | 2 | ||||
-rw-r--r-- | include/rw.h | 2 | ||||
-rw-r--r-- | src/dl_algo.cpp | 11 | ||||
-rw-r--r-- | src/dsa.cpp | 4 | ||||
-rw-r--r-- | src/elgamal.cpp | 4 | ||||
-rw-r--r-- | src/filter.cpp | 1 | ||||
-rw-r--r-- | src/if_algo.cpp | 9 | ||||
-rw-r--r-- | src/nr.cpp | 4 | ||||
-rw-r--r-- | src/numthry.cpp | 1 | ||||
-rw-r--r-- | src/pk_keys.cpp | 10 | ||||
-rw-r--r-- | src/rsa.cpp | 4 | ||||
-rw-r--r-- | src/rw.cpp | 4 | ||||
-rw-r--r-- | src/ui.cpp | 1 |
26 files changed, 73 insertions, 59 deletions
diff --git a/checks/pk.cpp b/checks/pk.cpp index 72e135715..0deab355c 100644 --- a/checks/pk.cpp +++ b/checks/pk.cpp @@ -660,31 +660,31 @@ void do_pk_keygen_tests() std::cout << "Testing PK key generation: " << std::flush; /* Putting each key in a block reduces memory pressure, speeds it up */ -#define IF_SIG_KEY(TYPE, BITS) \ - { \ - TYPE key(BITS, global_state().prng_reference()); \ - key.check_key(true); \ - std::cout << '.' << std::flush; \ +#define IF_SIG_KEY(TYPE, BITS) \ + { \ + TYPE key(BITS, global_state().prng_reference()); \ + key.check_key(global_state().prng_reference(), true); \ + std::cout << '.' << std::flush; \ } #define DL_SIG_KEY(TYPE, GROUP) \ { \ TYPE key(DL_Group(GROUP), global_state().prng_reference()); \ - key.check_key(true); \ - std::cout << '.' << std::flush; \ + key.check_key(global_state().prng_reference(), true); \ + std::cout << '.' << std::flush; \ } #define DL_ENC_KEY(TYPE, GROUP) \ { \ TYPE key(DL_Group(GROUP), global_state().prng_reference()); \ - key.check_key(true); \ - std::cout << '.' << std::flush; \ + key.check_key(global_state().prng_reference(), true); \ + std::cout << '.' << std::flush; \ } #define DL_KEY(TYPE, GROUP) \ { \ TYPE key(DL_Group(GROUP), global_state().prng_reference()); \ - key.check_key(true); \ + key.check_key(global_state().prng_reference(), true); \ std::cout << '.' << std::flush; \ } diff --git a/doc/examples/dh.cpp b/doc/examples/dh.cpp index 17dd29f56..c8e13dbb4 100644 --- a/doc/examples/dh.cpp +++ b/doc/examples/dh.cpp @@ -7,6 +7,7 @@ */ #include <botan/botan.h> #include <botan/dh.h> +#include <botan/libstate.h> using namespace Botan; #include <iostream> @@ -15,11 +16,13 @@ int main() { try { // Alice creates a DH key and sends (the public part) to Bob - DH_PrivateKey private_a(DL_Group("modp/ietf/1024")); + DH_PrivateKey private_a(DL_Group("modp/ietf/1024"), + global_state().prng_reference()); DH_PublicKey public_a = private_a; // Bob gets this // Bob creates a key with a matching group - DH_PrivateKey private_b(public_a.get_domain()); + DH_PrivateKey private_b(public_a.get_domain(), + global_state().prng_reference()); // Bob sends the key back to Alice DH_PublicKey public_b = private_b; // Alice gets this diff --git a/doc/examples/dsa_kgen.cpp b/doc/examples/dsa_kgen.cpp index 3dc55a443..c078d7fa3 100644 --- a/doc/examples/dsa_kgen.cpp +++ b/doc/examples/dsa_kgen.cpp @@ -21,6 +21,7 @@ This file is in the public domain #include <string> #include <botan/botan.h> #include <botan/dsa.h> +#include <botan/libstate.h> using namespace Botan; int main(int argc, char* argv[]) @@ -39,8 +40,10 @@ int main(int argc, char* argv[]) return 1; } - try { - DSA_PrivateKey key(DL_Group("dsa/jce/1024")); + try + { + DSA_PrivateKey key(DL_Group("dsa/jce/1024"), + global_state().prng_reference()); pub << X509::PEM_encode(key); if(argc == 1) diff --git a/doc/examples/factor.cpp b/doc/examples/factor.cpp index 6972ec108..2c9d94fa9 100644 --- a/doc/examples/factor.cpp +++ b/doc/examples/factor.cpp @@ -5,6 +5,7 @@ #include <botan/botan.h> #include <botan/reducer.h> #include <botan/numthry.h> +#include <botan/libstate.h> using namespace Botan; #include <algorithm> @@ -17,7 +18,7 @@ using namespace Botan; BigInt rho(const BigInt& n) { - BigInt x = random_integer(0, n-1); + BigInt x = random_integer(global_state().prng_reference(), 0, n-1); BigInt y = x; BigInt d = 0; @@ -90,7 +91,7 @@ std::vector<BigInt> factorize(const BigInt& n_in) while(n != 1) { - if(is_prime(n)) + if(is_prime(n, global_state().prng_reference())) { factors.push_back(n); break; diff --git a/doc/examples/pkcs10.cpp b/doc/examples/pkcs10.cpp index a4f6efb04..7e374ad72 100644 --- a/doc/examples/pkcs10.cpp +++ b/doc/examples/pkcs10.cpp @@ -11,6 +11,7 @@ This file is in the public domain #include <botan/x509self.h> #include <botan/rsa.h> #include <botan/dsa.h> +#include <botan/libstate.h> using namespace Botan; #include <iostream> @@ -25,8 +26,9 @@ int main(int argc, char* argv[]) return 1; } - try { - RSA_PrivateKey priv_key(1024); + try + { + RSA_PrivateKey priv_key(1024, global_state().prng_reference()); // If you want a DSA key instead of RSA, comment out the above line and // uncomment this one: //DSA_PrivateKey priv_key(DL_Group("dsa/jce/1024")); diff --git a/doc/examples/rsa_kgen.cpp b/doc/examples/rsa_kgen.cpp index e57f60c06..de2ed0db7 100644 --- a/doc/examples/rsa_kgen.cpp +++ b/doc/examples/rsa_kgen.cpp @@ -14,6 +14,7 @@ This file is in the public domain #include <string> #include <botan/botan.h> #include <botan/rsa.h> +#include <botan/libstate.h> using namespace Botan; int main(int argc, char* argv[]) @@ -26,7 +27,7 @@ int main(int argc, char* argv[]) } u32bit bits = std::atoi(argv[1]); - if(bits < 512 || bits > 4096) + if(bits < 1024 || bits > 4096) { std::cout << "Invalid argument for bitsize" << std::endl; return 1; @@ -42,7 +43,7 @@ int main(int argc, char* argv[]) try { - RSA_PrivateKey key(bits); + RSA_PrivateKey key(bits, global_state().prng_reference()); pub << X509::PEM_encode(key); if(argc == 2) diff --git a/doc/examples/self_sig.cpp b/doc/examples/self_sig.cpp index d00bcb3b4..c2118be40 100644 --- a/doc/examples/self_sig.cpp +++ b/doc/examples/self_sig.cpp @@ -13,6 +13,7 @@ This file is in the public domain #include <botan/x509self.h> #include <botan/rsa.h> #include <botan/dsa.h> +#include <botan/libstate.h> using namespace Botan; #include <iostream> @@ -39,9 +40,9 @@ int main(int argc, char* argv[]) return 1; } - try { - RSA_PrivateKey key(1024); - //DSA_PrivateKey key(DL_Group("dsa/jce/1024")); + try + { + RSA_PrivateKey key(1024, global_state().prng_reference()); std::ofstream priv_key("private.pem"); priv_key << PKCS8::PEM_encode(key, argv[1]); diff --git a/include/dl_algo.h b/include/dl_algo.h index f279d4633..2bcd67cb9 100644 --- a/include/dl_algo.h +++ b/include/dl_algo.h @@ -18,7 +18,7 @@ namespace Botan { class BOTAN_DLL DL_Scheme_PublicKey : public virtual Public_Key { public: - bool check_key(bool) const; + bool check_key(RandomNumberGenerator& rng, bool) const; const DL_Group& get_domain() const { return group; } const BigInt& get_y() const { return y; } @@ -43,7 +43,7 @@ class BOTAN_DLL DL_Scheme_PrivateKey : public virtual DL_Scheme_PublicKey, public virtual Private_Key { public: - bool check_key(bool) const; + bool check_key(RandomNumberGenerator& rng, bool) const; const BigInt& get_x() const { return x; } diff --git a/include/dsa.h b/include/dsa.h index 21941cd29..83c92572e 100644 --- a/include/dsa.h +++ b/include/dsa.h @@ -45,7 +45,7 @@ class BOTAN_DLL DSA_PrivateKey : public DSA_PublicKey, public: SecureVector<byte> sign(const byte[], u32bit) const; - bool check_key(bool) const; + bool check_key(RandomNumberGenerator& rng, bool) const; DSA_PrivateKey() {} DSA_PrivateKey(const DL_Group&, RandomNumberGenerator& rng); diff --git a/include/elgamal.h b/include/elgamal.h index 9a8135d38..bf9199fac 100644 --- a/include/elgamal.h +++ b/include/elgamal.h @@ -43,7 +43,7 @@ class BOTAN_DLL ElGamal_PrivateKey : public ElGamal_PublicKey, public: SecureVector<byte> decrypt(const byte[], u32bit) const; - bool check_key(bool) const; + bool check_key(RandomNumberGenerator& rng, bool) const; ElGamal_PrivateKey() {} ElGamal_PrivateKey(const DL_Group&, RandomNumberGenerator&); diff --git a/include/if_algo.h b/include/if_algo.h index aa336a067..5f5fa4ce2 100644 --- a/include/if_algo.h +++ b/include/if_algo.h @@ -18,7 +18,7 @@ namespace Botan { class BOTAN_DLL IF_Scheme_PublicKey : public virtual Public_Key { public: - bool check_key(bool) const; + bool check_key(RandomNumberGenerator& rng, bool) const; const BigInt& get_n() const { return n; } const BigInt& get_e() const { return e; } @@ -40,7 +40,7 @@ class BOTAN_DLL IF_Scheme_PrivateKey : public virtual IF_Scheme_PublicKey, public virtual Private_Key { public: - bool check_key(bool) const; + bool check_key(RandomNumberGenerator& rng, bool) const; const BigInt& get_p() const { return p; } const BigInt& get_q() const { return q; } diff --git a/include/nr.h b/include/nr.h index 0225af057..47c91dc6e 100644 --- a/include/nr.h +++ b/include/nr.h @@ -45,7 +45,7 @@ class BOTAN_DLL NR_PrivateKey : public NR_PublicKey, public: SecureVector<byte> sign(const byte[], u32bit) const; - bool check_key(bool) const; + bool check_key(RandomNumberGenerator& rng, bool) const; NR_PrivateKey() {} NR_PrivateKey(const DL_Group&, RandomNumberGenerator& rng); diff --git a/include/pk_keys.h b/include/pk_keys.h index 36905e868..a44aa7c7c 100644 --- a/include/pk_keys.h +++ b/include/pk_keys.h @@ -20,7 +20,9 @@ class BOTAN_DLL Public_Key virtual std::string algo_name() const = 0; virtual OID get_oid() const; - virtual bool check_key(bool) const { return true; } + virtual bool check_key(RandomNumberGenerator&, bool) const + { return true; } + virtual u32bit message_parts() const { return 1; } virtual u32bit message_part_size() const { return 0; } virtual u32bit max_input_bits() const = 0; diff --git a/include/rsa.h b/include/rsa.h index 54ac50fad..16408c471 100644 --- a/include/rsa.h +++ b/include/rsa.h @@ -41,7 +41,7 @@ class BOTAN_DLL RSA_PrivateKey : public RSA_PublicKey, SecureVector<byte> decrypt(const byte[], u32bit) const; SecureVector<byte> sign(const byte[], u32bit) const; - bool check_key(bool) const; + bool check_key(RandomNumberGenerator& rng, bool) const; RSA_PrivateKey() {} RSA_PrivateKey(const BigInt&, const BigInt&, const BigInt&, diff --git a/include/rw.h b/include/rw.h index 6ccc2b10d..0d22711df 100644 --- a/include/rw.h +++ b/include/rw.h @@ -37,7 +37,7 @@ class BOTAN_DLL RW_PrivateKey : public RW_PublicKey, public: SecureVector<byte> sign(const byte[], u32bit) const; - bool check_key(bool) const; + bool check_key(RandomNumberGenerator& rng, bool) const; RW_PrivateKey() {} RW_PrivateKey(const BigInt&, const BigInt&, const BigInt&, diff --git a/src/dl_algo.cpp b/src/dl_algo.cpp index afefe2df3..e1de143a0 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 { @@ -128,11 +127,12 @@ PKCS8_Decoder* DL_Scheme_PrivateKey::pkcs8_decoder() /************************************************* * Check Public DL Parameters * *************************************************/ -bool DL_Scheme_PublicKey::check_key(bool strong) const +bool DL_Scheme_PublicKey::check_key(RandomNumberGenerator& rng, + bool strong) const { if(y < 2 || y >= group_p()) return false; - if(!group.verify_group(global_state().prng_reference(), strong)) + if(!group.verify_group(rng, strong)) return false; return true; } @@ -140,14 +140,15 @@ bool DL_Scheme_PublicKey::check_key(bool strong) const /************************************************* * Check DL Scheme Private Parameters * *************************************************/ -bool DL_Scheme_PrivateKey::check_key(bool strong) const +bool DL_Scheme_PrivateKey::check_key(RandomNumberGenerator& rng, + bool strong) const { const BigInt& p = group_p(); const BigInt& g = group_g(); if(y < 2 || y >= p || x < 2 || x >= p) return false; - if(!group.verify_group(global_state().prng_reference(), strong)) + if(!group.verify_group(rng, strong)) return false; if(!strong) diff --git a/src/dsa.cpp b/src/dsa.cpp index 13ab67374..e22d9bd88 100644 --- a/src/dsa.cpp +++ b/src/dsa.cpp @@ -112,9 +112,9 @@ SecureVector<byte> DSA_PrivateKey::sign(const byte in[], u32bit length) const /************************************************* * Check Private DSA Parameters * *************************************************/ -bool DSA_PrivateKey::check_key(bool strong) const +bool DSA_PrivateKey::check_key(RandomNumberGenerator& rng, bool strong) const { - if(!DL_Scheme_PrivateKey::check_key(strong) || x >= group_q()) + if(!DL_Scheme_PrivateKey::check_key(rng, strong) || x >= group_q()) return false; if(!strong) diff --git a/src/elgamal.cpp b/src/elgamal.cpp index bcb8a6cc0..95062cc53 100644 --- a/src/elgamal.cpp +++ b/src/elgamal.cpp @@ -104,9 +104,9 @@ SecureVector<byte> ElGamal_PrivateKey::decrypt(const byte in[], /************************************************* * Check Private ElGamal Parameters * *************************************************/ -bool ElGamal_PrivateKey::check_key(bool strong) const +bool ElGamal_PrivateKey::check_key(RandomNumberGenerator& rng, bool strong) const { - if(!DL_Scheme_PrivateKey::check_key(strong)) + if(!DL_Scheme_PrivateKey::check_key(rng, strong)) return false; if(!strong) diff --git a/src/filter.cpp b/src/filter.cpp index a5bc2dea1..253f20c32 100644 --- a/src/filter.cpp +++ b/src/filter.cpp @@ -5,7 +5,6 @@ #include <botan/filter.h> #include <botan/secqueue.h> -#include <botan/libstate.h> namespace Botan { diff --git a/src/if_algo.cpp b/src/if_algo.cpp index b8d8071f4..dfb41f177 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 { @@ -183,7 +182,7 @@ void IF_Scheme_PrivateKey::PKCS8_load_hook(bool generated) /************************************************* * Check IF Scheme Public Parameters * *************************************************/ -bool IF_Scheme_PublicKey::check_key(bool) const +bool IF_Scheme_PublicKey::check_key(RandomNumberGenerator&, bool) const { if(n < 35 || n.is_even() || e < 2) return false; @@ -193,7 +192,8 @@ bool IF_Scheme_PublicKey::check_key(bool) const /************************************************* * Check IF Scheme Private Parameters * *************************************************/ -bool IF_Scheme_PrivateKey::check_key(bool strong) const +bool IF_Scheme_PrivateKey::check_key(RandomNumberGenerator& rng, + bool strong) const { if(n < 35 || n.is_even() || e < 2 || d < 2 || p < 3 || q < 3 || p*q != n) return false; @@ -203,8 +203,7 @@ bool IF_Scheme_PrivateKey::check_key(bool strong) const if(d1 != d % (p - 1) || d2 != d % (q - 1) || c != inverse_mod(q, p)) return false; - if(!check_prime(p, global_state().prng_reference()) || - !check_prime(q, global_state().prng_reference())) + if(!check_prime(p, rng) || !check_prime(q, rng)) return false; return true; } diff --git a/src/nr.cpp b/src/nr.cpp index 0f911daac..53beb4056 100644 --- a/src/nr.cpp +++ b/src/nr.cpp @@ -111,9 +111,9 @@ SecureVector<byte> NR_PrivateKey::sign(const byte in[], u32bit length) const /************************************************* * Check Private Nyberg-Rueppel Parameters * *************************************************/ -bool NR_PrivateKey::check_key(bool strong) const +bool NR_PrivateKey::check_key(RandomNumberGenerator& rng, bool strong) const { - if(!DL_Scheme_PrivateKey::check_key(strong) || x >= group_q()) + if(!DL_Scheme_PrivateKey::check_key(rng, strong) || x >= group_q()) return false; if(!strong) diff --git a/src/numthry.cpp b/src/numthry.cpp index f36e2f3fe..49d078f51 100644 --- a/src/numthry.cpp +++ b/src/numthry.cpp @@ -4,7 +4,6 @@ *************************************************/ #include <botan/numthry.h> -#include <botan/libstate.h> #include <algorithm> namespace Botan { diff --git a/src/pk_keys.cpp b/src/pk_keys.cpp index 719c5509d..8ada71133 100644 --- a/src/pk_keys.cpp +++ b/src/pk_keys.cpp @@ -6,6 +6,7 @@ #include <botan/pk_keys.h> #include <botan/config.h> #include <botan/oids.h> +#include <botan/libstate.h> namespace Botan { @@ -43,7 +44,8 @@ OID Public_Key::get_oid() const *************************************************/ void Public_Key::load_check() const { - if(!check_key(key_check_level("public"))) + if(!check_key(global_state().prng_reference(), + key_check_level("public"))) throw Invalid_Argument(algo_name() + ": Invalid public key"); } @@ -52,7 +54,8 @@ void Public_Key::load_check() const *************************************************/ void Private_Key::load_check() const { - if(!check_key(key_check_level("private"))) + if(!check_key(global_state().prng_reference(), + key_check_level("private"))) throw Invalid_Argument(algo_name() + ": Invalid private key"); } @@ -61,7 +64,8 @@ void Private_Key::load_check() const *************************************************/ void Private_Key::gen_check() const { - if(!check_key(key_check_level("private_gen"))) + if(!check_key(global_state().prng_reference(), + key_check_level("private_gen"))) throw Self_Test_Failure(algo_name() + " private key generation failed"); } diff --git a/src/rsa.cpp b/src/rsa.cpp index e438c8b92..75789fc10 100644 --- a/src/rsa.cpp +++ b/src/rsa.cpp @@ -125,9 +125,9 @@ SecureVector<byte> RSA_PrivateKey::sign(const byte in[], u32bit len) const /************************************************* * Check Private RSA Parameters * *************************************************/ -bool RSA_PrivateKey::check_key(bool strong) const +bool RSA_PrivateKey::check_key(RandomNumberGenerator& rng, bool strong) const { - if(!IF_Scheme_PrivateKey::check_key(strong)) + if(!IF_Scheme_PrivateKey::check_key(rng, strong)) return false; if(!strong) diff --git a/src/rw.cpp b/src/rw.cpp index 425ab83b3..35e3bbf8d 100644 --- a/src/rw.cpp +++ b/src/rw.cpp @@ -115,9 +115,9 @@ SecureVector<byte> RW_PrivateKey::sign(const byte in[], u32bit len) const /************************************************* * Check Private Rabin-Williams Parameters * *************************************************/ -bool RW_PrivateKey::check_key(bool strong) const +bool RW_PrivateKey::check_key(RandomNumberGenerator& rng, bool strong) const { - if(!IF_Scheme_PrivateKey::check_key(strong)) + if(!IF_Scheme_PrivateKey::check_key(rng, strong)) return false; if(!strong) diff --git a/src/ui.cpp b/src/ui.cpp index 197259e3a..fb81ae23c 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -4,7 +4,6 @@ *************************************************/ #include <botan/ui.h> -#include <botan/libstate.h> namespace Botan { |