diff options
author | lloyd <[email protected]> | 2008-05-24 18:25:00 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-05-24 18:25:00 +0000 |
commit | b7563677f13adb8dfa5813ef91ed79364b2d984d (patch) | |
tree | cf7fabb3eb43bc49333be726c15ecac1a7f9a1a7 /checks | |
parent | a6a9110d02925e111cff2dc1143a09a3b7680f0b (diff) |
Previously random_integer and friends used the global PRNG object to get
random bits. Now they take a reference to a RandomNumberGenerator object.
This was applied several times out, so now the constructors to private
key objects also take a RandomNumberGenerator& argument. This is also true
for a number of randomized algorithms (Miller-Rabin, for instance).
You can get a reference to the global PRNG with
global_state().prng_reference()
This is a provisional thing: and warning: it is not thread safe! If this
is a problem instead keep per-thread PRNGs and pass them were needed.
Diffstat (limited to 'checks')
-rw-r--r-- | checks/bigint.cpp | 3 | ||||
-rw-r--r-- | checks/dolook2.cpp | 2 | ||||
-rw-r--r-- | checks/pk.cpp | 19 | ||||
-rw-r--r-- | checks/pk_bench.cpp | 12 | ||||
-rw-r--r-- | checks/x509.cpp | 10 |
5 files changed, 28 insertions, 18 deletions
diff --git a/checks/bigint.cpp b/checks/bigint.cpp index 6a4d5ac94..5853e8a73 100644 --- a/checks/bigint.cpp +++ b/checks/bigint.cpp @@ -332,7 +332,8 @@ u32bit check_primetest(const std::vector<std::string>& args) BigInt n(args[0]); bool should_be_prime = (args[1] == "1"); - bool is_prime = Botan::verify_prime(n); + bool is_prime = Botan::verify_prime(n, + global_state().prng_reference()); if(is_prime != should_be_prime) { diff --git a/checks/dolook2.cpp b/checks/dolook2.cpp index b49d48a5e..1b7123b30 100644 --- a/checks/dolook2.cpp +++ b/checks/dolook2.cpp @@ -113,7 +113,7 @@ void RNG_Filter::write(const byte[], u32bit length) Filter* lookup_rng(const std::string& algname) { if(algname == "X9.31-RNG") - return new RNG_Filter(new ANSI_X931_RNG); + return new RNG_Filter(new ANSI_X931_RNG("AES-256", new Randpool)); if(algname == "Randpool") return new RNG_Filter(new Randpool); return 0; diff --git a/checks/pk.cpp b/checks/pk.cpp index 5d9417fc6..72e135715 100644 --- a/checks/pk.cpp +++ b/checks/pk.cpp @@ -21,6 +21,7 @@ #include <botan/numthry.h> #include <botan/x931_rng.h> +#include <botan/randpool.h> #include <botan/libstate.h> using namespace Botan; @@ -194,7 +195,7 @@ u32bit do_pk_validation_tests(const std::string& filename) std::cout << std::endl; - global_state().set_prng(new ANSI_X931_RNG); + global_state().set_prng(new ANSI_X931_RNG("AES-128", new Randpool)); for(u32bit j = 0; j != 2; j++) global_state().seed_prng(true, 384); @@ -249,7 +250,7 @@ void validate_encryption(PK_Encryptor* e, PK_Decryptor* d, failure = true; } - global_state().set_prng(new ANSI_X931_RNG); + global_state().set_prng(new ANSI_X931_RNG("AES-128", new Randpool)); for(u32bit j = 0; j != 2; j++) global_state().seed_prng(true, 384); @@ -290,7 +291,7 @@ void validate_signature(PK_Verifier* v, PK_Signer* s, const std::string& algo, failure = true; } - global_state().set_prng(new ANSI_X931_RNG); + global_state().set_prng(new ANSI_X931_RNG("AES-128", new Randpool)); for(u32bit j = 0; j != 2; j++) global_state().seed_prng(true, 384); @@ -661,34 +662,34 @@ void do_pk_keygen_tests() /* Putting each key in a block reduces memory pressure, speeds it up */ #define IF_SIG_KEY(TYPE, BITS) \ { \ - TYPE key(BITS); \ + TYPE key(BITS, global_state().prng_reference()); \ key.check_key(true); \ std::cout << '.' << std::flush; \ } #define DL_SIG_KEY(TYPE, GROUP) \ { \ - TYPE key(DL_Group(GROUP)); \ + TYPE key(DL_Group(GROUP), global_state().prng_reference()); \ key.check_key(true); \ std::cout << '.' << std::flush; \ } #define DL_ENC_KEY(TYPE, GROUP) \ { \ - TYPE key(DL_Group(GROUP)); \ + TYPE key(DL_Group(GROUP), global_state().prng_reference()); \ key.check_key(true); \ std::cout << '.' << std::flush; \ } #define DL_KEY(TYPE, GROUP) \ { \ - TYPE key(DL_Group(GROUP)); \ + TYPE key(DL_Group(GROUP), global_state().prng_reference()); \ key.check_key(true); \ std::cout << '.' << std::flush; \ } - IF_SIG_KEY(RSA_PrivateKey, 512); - IF_SIG_KEY(RW_PrivateKey, 512); + IF_SIG_KEY(RSA_PrivateKey, 1024); + IF_SIG_KEY(RW_PrivateKey, 1024); DL_SIG_KEY(DSA_PrivateKey, "dsa/jce/512"); DL_SIG_KEY(DSA_PrivateKey, "dsa/jce/768"); diff --git a/checks/pk_bench.cpp b/checks/pk_bench.cpp index 51a454f4a..58d0a2f39 100644 --- a/checks/pk_bench.cpp +++ b/checks/pk_bench.cpp @@ -87,7 +87,8 @@ 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); + DSA_PrivateKey key("dsa/jce/" + len_str, + global_state().prng_reference()); bench_ver(get_pk_signer(key, "EMSA1(SHA-1)"), get_pk_verifier(key, "EMSA1(SHA-1)"), @@ -106,7 +107,8 @@ void bench_pk(const std::string& algo, bool html, double seconds) { const std::string len_str = to_string(keylen[j]); - DH_PrivateKey key("modp/ietf/" + len_str); + DH_PrivateKey key("modp/ietf/" + len_str, + global_state().prng_reference()); bench_kas(get_pk_kas(key, "Raw"), "DH-" + len_str, seconds, html); } @@ -120,7 +122,8 @@ 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); + ElGamal_PrivateKey key("modp/ietf/" + len_str, + global_state().prng_reference()); bench_enc(get_pk_encryptor(key, "Raw"), "ELG-" + len_str, seconds, html); @@ -139,7 +142,8 @@ 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); + NR_PrivateKey key("dsa/jce/" + len_str, + global_state().prng_reference()); bench_ver(get_pk_signer(key, "EMSA1(SHA-1)"), get_pk_verifier(key, "EMSA1(SHA-1)"), diff --git a/checks/x509.cpp b/checks/x509.cpp index 6e6dad60c..459f3b62f 100644 --- a/checks/x509.cpp +++ b/checks/x509.cpp @@ -6,6 +6,8 @@ #include <botan/pkcs10.h> #include <botan/rsa.h> #include <botan/dsa.h> + +#include <botan/libstate.h> using namespace Botan; #include <iostream> @@ -71,7 +73,7 @@ void do_x509_tests() /* Create the CA's key and self-signed cert */ std::cout << '.' << std::flush; - RSA_PrivateKey ca_key(1024); + RSA_PrivateKey ca_key(1024, global_state().prng_reference()); std::cout << '.' << std::flush; X509_Certificate ca_cert = X509::create_self_signed_cert(ca_opts(), ca_key); @@ -79,13 +81,15 @@ 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")); + DSA_PrivateKey user1_key(DL_Group("dsa/jce/1024"), + global_state().prng_reference()); + std::cout << '.' << std::flush; PKCS10_Request user1_req = X509::create_cert_req(req_opts1(), user1_key); /* Create user #2's key and cert request */ std::cout << '.' << std::flush; - RSA_PrivateKey user2_key(768); + RSA_PrivateKey user2_key(1024, global_state().prng_reference()); std::cout << '.' << std::flush; PKCS10_Request user2_req = X509::create_cert_req(req_opts2(), user2_key); |