diff options
-rw-r--r-- | checks/pk.cpp | 12 | ||||
-rw-r--r-- | checks/pk_bench.cpp | 17 | ||||
-rw-r--r-- | checks/x509.cpp | 2 | ||||
-rw-r--r-- | include/dsa.h | 4 | ||||
-rw-r--r-- | include/elgamal.h | 4 | ||||
-rw-r--r-- | include/nr.h | 5 | ||||
-rw-r--r-- | src/dsa.cpp | 31 | ||||
-rw-r--r-- | src/elgamal.cpp | 28 | ||||
-rw-r--r-- | src/nr.cpp | 28 |
9 files changed, 58 insertions, 73 deletions
diff --git a/checks/pk.cpp b/checks/pk.cpp index 93007c8d8..2dad1b966 100644 --- a/checks/pk.cpp +++ b/checks/pk.cpp @@ -198,8 +198,10 @@ u32bit validate_elg_enc(const std::string& algo, if(str.size() != 6 && str.size() != 7) throw Exception("Invalid input from pk_valid.dat"); + RandomNumberGenerator& rng = global_state().prng_reference(); + DL_Group domain(to_bigint(str[0]), to_bigint(str[1])); - ElGamal_PrivateKey privkey(domain, to_bigint(str[2]), to_bigint(str[3])); + ElGamal_PrivateKey privkey(rng, domain, to_bigint(str[2])); ElGamal_PublicKey pubkey = privkey; std::string eme = algo.substr(8, std::string::npos); @@ -407,8 +409,10 @@ u32bit validate_nr_sig(const std::string& algo, if(str.size() != 8) throw Exception("Invalid input from pk_valid.dat"); + RandomNumberGenerator& rng = global_state().prng_reference(); + DL_Group domain(to_bigint(str[0]), to_bigint(str[1]), to_bigint(str[2])); - NR_PrivateKey privkey(domain, to_bigint(str[4]), to_bigint(str[3])); + NR_PrivateKey privkey(rng, domain, to_bigint(str[4])); NR_PublicKey pubkey = privkey; std::string emsa = algo.substr(3, std::string::npos); @@ -496,14 +500,14 @@ void do_pk_keygen_tests() #define DL_SIG_KEY(TYPE, GROUP) \ { \ - TYPE key(DL_Group(GROUP), rng); \ + TYPE key(rng, DL_Group(GROUP)); \ key.check_key(rng, true); \ std::cout << '.' << std::flush; \ } #define DL_ENC_KEY(TYPE, GROUP) \ { \ - TYPE key(DL_Group(GROUP), rng); \ + TYPE key(rng, DL_Group(GROUP)); \ key.check_key(rng, true); \ std::cout << '.' << std::flush; \ } diff --git a/checks/pk_bench.cpp b/checks/pk_bench.cpp index 8daa1fe91..a0ac7d0ab 100644 --- a/checks/pk_bench.cpp +++ b/checks/pk_bench.cpp @@ -55,6 +55,8 @@ void bench_pk(const std::string& algo, bool html, double seconds) ad-hoc format (the RW algorithm has no assigned OID that I know of, so there is no way to encode a RW key into a PKCS #8 structure). */ + RandomNumberGenerator& rng = global_state().prng_reference(); + if(algo == "All" || algo == "RSA") { const u32bit keylen[] = { 512, 1024, 1536, 2048, 3072, 4096, 0 }; @@ -65,7 +67,7 @@ void bench_pk(const std::string& algo, bool html, double seconds) const std::string file = "checks/keys/rsa" + len_str + ".pem"; std::auto_ptr<RSA_PrivateKey> key( - dynamic_cast<RSA_PrivateKey*>(PKCS8::load_key(file, global_state().prng_reference())) + dynamic_cast<RSA_PrivateKey*>(PKCS8::load_key(file, rng)) ); if(key.get() == 0) @@ -88,8 +90,7 @@ void bench_pk(const std::string& algo, bool html, double seconds) { const std::string len_str = to_string(keylen[j]); - DSA_PrivateKey key("dsa/jce/" + len_str, - global_state().prng_reference()); + DSA_PrivateKey key(rng, "dsa/jce/" + len_str); bench_ver(get_pk_signer(key, "EMSA1(SHA-1)"), get_pk_verifier(key, "EMSA1(SHA-1)"), @@ -108,7 +109,7 @@ void bench_pk(const std::string& algo, bool html, double seconds) { const std::string len_str = to_string(keylen[j]); - DH_PrivateKey key(global_state().prng_reference(), + DH_PrivateKey key(rng, "modp/ietf/" + len_str); bench_kas(get_pk_kas(key, "Raw"), "DH-" + len_str, seconds, html); @@ -123,8 +124,7 @@ void bench_pk(const std::string& algo, bool html, double seconds) { const std::string len_str = to_string(keylen[j]); - ElGamal_PrivateKey key("modp/ietf/" + len_str, - global_state().prng_reference()); + ElGamal_PrivateKey key(rng, "modp/ietf/" + len_str); bench_enc(get_pk_encryptor(key, "Raw"), "ELG-" + len_str, seconds, html); @@ -143,8 +143,7 @@ void bench_pk(const std::string& algo, bool html, double seconds) { const std::string len_str = to_string(keylen[j]); - NR_PrivateKey key("dsa/jce/" + len_str, - global_state().prng_reference()); + NR_PrivateKey key(rng, "dsa/jce/" + len_str); bench_ver(get_pk_signer(key, "EMSA1(SHA-1)"), get_pk_verifier(key, "EMSA1(SHA-1)"), @@ -165,7 +164,7 @@ void bench_pk(const std::string& algo, bool html, double seconds) const std::string file = "checks/keys/rw" + len_str + ".pem"; RW_PrivateKey* key = - dynamic_cast<RW_PrivateKey*>(PKCS8::load_key(file, global_state().prng_reference())); + dynamic_cast<RW_PrivateKey*>(PKCS8::load_key(file, rng)); bench_ver(get_pk_signer(*key, "EMSA2(SHA-1)"), get_pk_verifier(*key, "EMSA2(SHA-1)"), diff --git a/checks/x509.cpp b/checks/x509.cpp index 48cbd8384..92d9d43ed 100644 --- a/checks/x509.cpp +++ b/checks/x509.cpp @@ -94,7 +94,7 @@ void do_x509_tests() /* Create user #1's key and cert request */ std::cout << '.' << std::flush; - DSA_PrivateKey user1_key(DL_Group("dsa/jce/1024"), rng); + DSA_PrivateKey user1_key(rng, DL_Group("dsa/jce/1024")); std::cout << '.' << std::flush; PKCS10_Request user1_req = X509::create_cert_req(req_opts1(), diff --git a/include/dsa.h b/include/dsa.h index eb14dbef9..429d55b7c 100644 --- a/include/dsa.h +++ b/include/dsa.h @@ -49,8 +49,8 @@ class BOTAN_DLL DSA_PrivateKey : public DSA_PublicKey, bool check_key(RandomNumberGenerator& rng, bool) const; DSA_PrivateKey() {} - DSA_PrivateKey(const DL_Group&, RandomNumberGenerator& rng); - DSA_PrivateKey(const DL_Group&, const BigInt&, const BigInt& = 0); + DSA_PrivateKey(RandomNumberGenerator&, const DL_Group&, + const BigInt& = 0); private: void PKCS8_load_hook(RandomNumberGenerator& rng, bool = false); }; diff --git a/include/elgamal.h b/include/elgamal.h index 7cce0a73e..c85f6986e 100644 --- a/include/elgamal.h +++ b/include/elgamal.h @@ -46,8 +46,8 @@ class BOTAN_DLL ElGamal_PrivateKey : public ElGamal_PublicKey, bool check_key(RandomNumberGenerator& rng, bool) const; ElGamal_PrivateKey() {} - ElGamal_PrivateKey(const DL_Group&, RandomNumberGenerator&); - ElGamal_PrivateKey(const DL_Group&, const BigInt&, const BigInt& = 0); + ElGamal_PrivateKey(RandomNumberGenerator&, const DL_Group&, + const BigInt& = 0); private: void PKCS8_load_hook(RandomNumberGenerator&, bool = false); }; diff --git a/include/nr.h b/include/nr.h index 51b9a95d1..2dcbccd20 100644 --- a/include/nr.h +++ b/include/nr.h @@ -49,8 +49,9 @@ class BOTAN_DLL NR_PrivateKey : public NR_PublicKey, bool check_key(RandomNumberGenerator& rng, bool) const; NR_PrivateKey() {} - NR_PrivateKey(const DL_Group&, RandomNumberGenerator& rng); - NR_PrivateKey(const DL_Group&, const BigInt&, const BigInt& = 0); + + NR_PrivateKey(RandomNumberGenerator&, const DL_Group&, + const BigInt& = 0); private: void PKCS8_load_hook(RandomNumberGenerator&, bool = false); }; diff --git a/src/dsa.cpp b/src/dsa.cpp index e53ba0766..8ca2f7db5 100644 --- a/src/dsa.cpp +++ b/src/dsa.cpp @@ -57,26 +57,20 @@ u32bit DSA_PublicKey::message_part_size() const /************************************************* * Create a DSA private key * *************************************************/ -DSA_PrivateKey::DSA_PrivateKey(const DL_Group& grp, - RandomNumberGenerator& rng) +DSA_PrivateKey::DSA_PrivateKey(RandomNumberGenerator& rng, + const DL_Group& grp, + const BigInt& x_arg) { group = grp; - x = random_integer(rng, 2, group_q() - 1); + x = x_arg; - PKCS8_load_hook(rng, true); - } - -/************************************************* -* DSA_PrivateKey Constructor * -*************************************************/ -DSA_PrivateKey::DSA_PrivateKey(const DL_Group& grp, const BigInt& x1, - const BigInt& y1) - { - group = grp; - y = y1; - x = x1; - - PKCS8_load_hook(global_state().prng_reference()); + if(x == 0) + { + x = random_integer(rng, 2, group_q() - 1); + PKCS8_load_hook(rng, true); + } + else + PKCS8_load_hook(rng, false); } /************************************************* @@ -85,8 +79,7 @@ DSA_PrivateKey::DSA_PrivateKey(const DL_Group& grp, const BigInt& x1, void DSA_PrivateKey::PKCS8_load_hook(RandomNumberGenerator& rng, bool generated) { - if(y == 0) - y = power_mod(group_g(), x, group_p()); + y = power_mod(group_g(), x, group_p()); core = DSA_Core(group, y, x); if(generated) diff --git a/src/elgamal.cpp b/src/elgamal.cpp index fc5100d99..d97a365e7 100644 --- a/src/elgamal.cpp +++ b/src/elgamal.cpp @@ -52,26 +52,20 @@ u32bit ElGamal_PublicKey::max_input_bits() const /************************************************* * ElGamal_PrivateKey Constructor * *************************************************/ -ElGamal_PrivateKey::ElGamal_PrivateKey(const DL_Group& grp, - RandomNumberGenerator& rng) +ElGamal_PrivateKey::ElGamal_PrivateKey(RandomNumberGenerator& rng, + const DL_Group& grp, + const BigInt& x_arg) { group = grp; - x.randomize(rng, 2 * dl_work_factor(group_p().bits())); + x = x_arg; - PKCS8_load_hook(rng, true); - } - -/************************************************* -* ElGamal_PrivateKey Constructor * -*************************************************/ -ElGamal_PrivateKey::ElGamal_PrivateKey(const DL_Group& grp, const BigInt& x1, - const BigInt& y1) - { - group = grp; - y = y1; - x = x1; - - PKCS8_load_hook(global_state().prng_reference()); + if(x == 0) + { + x.randomize(rng, 2 * dl_work_factor(group_p().bits())); + PKCS8_load_hook(rng, true); + } + else + PKCS8_load_hook(rng, false); } /************************************************* diff --git a/src/nr.cpp b/src/nr.cpp index d8e200d9f..de46abd80 100644 --- a/src/nr.cpp +++ b/src/nr.cpp @@ -56,26 +56,20 @@ u32bit NR_PublicKey::message_part_size() const /************************************************* * Create a NR private key * *************************************************/ -NR_PrivateKey::NR_PrivateKey(const DL_Group& grp, - RandomNumberGenerator& rng) +NR_PrivateKey::NR_PrivateKey(RandomNumberGenerator& rng, + const DL_Group& grp, + const BigInt& x_arg) { group = grp; - x = random_integer(rng, 2, group_q() - 1); + x = x_arg; - PKCS8_load_hook(rng, true); - } - -/************************************************* -* NR_PrivateKey Constructor * -*************************************************/ -NR_PrivateKey::NR_PrivateKey(const DL_Group& grp, const BigInt& x1, - const BigInt& y1) - { - group = grp; - y = y1; - x = x1; - - PKCS8_load_hook(global_state().prng_reference()); + if(x == 0) + { + x = random_integer(rng, 2, group_q() - 1); + PKCS8_load_hook(rng, true); + } + else + PKCS8_load_hook(rng, false); } /************************************************* |