diff options
Diffstat (limited to 'checks')
-rw-r--r-- | checks/bench.cpp | 22 | ||||
-rw-r--r-- | checks/bench.h | 15 | ||||
-rw-r--r-- | checks/check.cpp | 26 | ||||
-rw-r--r-- | checks/pk.cpp | 78 | ||||
-rw-r--r-- | checks/pk_bench.cpp | 87 | ||||
-rw-r--r-- | checks/validate.h | 8 | ||||
-rw-r--r-- | checks/x509.cpp | 15 |
7 files changed, 137 insertions, 114 deletions
diff --git a/checks/bench.cpp b/checks/bench.cpp index 807e6db82..d3a9e06c4 100644 --- a/checks/bench.cpp +++ b/checks/bench.cpp @@ -25,6 +25,7 @@ Botan::Filter* lookup(const std::string&, namespace { double bench_filter(std::string name, Botan::Filter* filter, + Botan::RandomNumberGenerator& rng, bool html, double seconds) { Botan::Pipe pipe(filter, new BitBucket); @@ -33,7 +34,7 @@ double bench_filter(std::string name, Botan::Filter* filter, static const u32bit BUFFERSIZE = 32*1024; byte buf[BUFFERSIZE]; - global_rng().randomize(buf, BUFFERSIZE); + rng.randomize(buf, BUFFERSIZE); u32bit iterations = 0; u64bit start = get_clock(), clocks_used = 0; @@ -73,12 +74,13 @@ double bench_filter(std::string name, Botan::Filter* filter, } double bench(const std::string& name, const std::string& filtername, bool html, - double seconds, u32bit keylen, u32bit ivlen) + double seconds, u32bit keylen, u32bit ivlen, + Botan::RandomNumberGenerator& rng) { std::vector<std::string> params; Botan::SecureVector<byte> key(keylen); - global_rng().randomize(key, key.size()); + rng.randomize(key, key.size()); params.push_back(hex_encode(key, key.size())); //params.push_back(std::string(int(2*keylen), 'A')); @@ -87,13 +89,15 @@ double bench(const std::string& name, const std::string& filtername, bool html, Botan::Filter* filter = lookup(filtername, params); if(filter) - return bench_filter(name, filter, html, seconds); + return bench_filter(name, filter, rng, html, seconds); return 0; } } -void benchmark(const std::string& what, bool html, double seconds) +void benchmark(const std::string& what, + Botan::RandomNumberGenerator& rng, + bool html, double seconds) { try { if(html) @@ -120,7 +124,7 @@ void benchmark(const std::string& what, bool html, double seconds) { double speed = bench(algos[j].name, algos[j].filtername, html, seconds, algos[j].keylen, - algos[j].ivlen); + algos[j].ivlen, rng); if(speed > .00001) /* log(0) == -inf -> messed up average */ sum += std::log(speed); how_many++; @@ -158,7 +162,9 @@ void benchmark(const std::string& what, bool html, double seconds) } } -u32bit bench_algo(const std::string& name, double seconds) +u32bit bench_algo(const std::string& name, + Botan::RandomNumberGenerator& rng, + double seconds) { try { std::vector<algorithm> algos = get_algos(); @@ -168,7 +174,7 @@ u32bit bench_algo(const std::string& name, double seconds) if(algos[j].name == name) { bench(algos[j].name, algos[j].filtername, false, seconds, - algos[j].keylen, algos[j].ivlen); + algos[j].keylen, algos[j].ivlen, rng); return 1; } } diff --git a/checks/bench.h b/checks/bench.h index 40d3cab8a..e101acdc2 100644 --- a/checks/bench.h +++ b/checks/bench.h @@ -2,8 +2,17 @@ #ifndef BOTAN_BENCHMARCH_H__ #define BOTAN_BENCHMARCH_H__ -void benchmark(const std::string&, bool html, double seconds); -void bench_pk(const std::string&, bool html, double seconds); -u32bit bench_algo(const std::string&, double); +#include <botan/rng.h> +#include <string> + +void benchmark(const std::string&, Botan::RandomNumberGenerator&, + bool html, double seconds); + +void bench_pk(Botan::RandomNumberGenerator&, + const std::string&, bool html, double seconds); + +u32bit bench_algo(const std::string&, + Botan::RandomNumberGenerator&, + double); #endif diff --git a/checks/check.cpp b/checks/check.cpp index 0a7ce373e..9ef5ee1f9 100644 --- a/checks/check.cpp +++ b/checks/check.cpp @@ -19,6 +19,7 @@ using namespace Botan; #include "getopt.h" #include "bench.h" #include "validate.h" +#include "common.h" const std::string VALIDATION_FILE = "checks/validate.dat"; const std::string BIGINT_VALIDATION_FILE = "checks/mp_valid.dat"; @@ -38,6 +39,8 @@ int main(int argc, char* argv[]) Botan::InitializerOptions init_options(opts.value_if_set("init")); Botan::LibraryInitializer init(init_options); + RandomNumberGenerator& rng = global_rng(); + if(opts.is_set("help") || argc <= 1) { std::cerr << "Test driver for " @@ -79,32 +82,32 @@ int main(int argc, char* argv[]) for(u32bit j = 0; j != algs.size(); j++) { const std::string alg = algs[j]; - u32bit found = bench_algo(alg, seconds); + u32bit found = bench_algo(alg, rng, seconds); if(!found) // maybe it's a PK algorithm - bench_pk(alg, html, seconds); + bench_pk(global_rng(), alg, html, seconds); } } if(opts.is_set("benchmark")) - benchmark("All", html, seconds); + benchmark("All", rng, html, seconds); else if(opts.is_set("bench-type")) { const std::string type = opts.value("bench-type"); if(type == "all") - benchmark("All", html, seconds); + benchmark("All", rng, html, seconds); else if(type == "block") - benchmark("Block Cipher", html, seconds); + benchmark("Block Cipher", rng, html, seconds); else if(type == "stream") - benchmark("Stream Cipher", html, seconds); + benchmark("Stream Cipher", rng, html, seconds); else if(type == "hash") - benchmark("Hash", html, seconds); + benchmark("Hash", rng, html, seconds); else if(type == "mac") - benchmark("MAC", html, seconds); + benchmark("MAC", rng, html, seconds); else if(type == "rng") - benchmark("RNG", html, seconds); + benchmark("RNG", rng, html, seconds); else if(type == "pk") - bench_pk("All", html, seconds); + bench_pk(rng, "All", html, seconds); } } catch(Botan::Exception& e) @@ -193,7 +196,8 @@ int validate() errors += do_validation_tests(VALIDATION_FILE); errors += do_validation_tests(EXPECTED_FAIL_FILE, false); errors += do_bigint_tests(BIGINT_VALIDATION_FILE); - errors += do_pk_validation_tests(PK_VALIDATION_FILE); + errors += do_pk_validation_tests(PK_VALIDATION_FILE, + global_rng()); } catch(Botan::Exception& e) { diff --git a/checks/pk.cpp b/checks/pk.cpp index 989daf54f..263f8e090 100644 --- a/checks/pk.cpp +++ b/checks/pk.cpp @@ -137,7 +137,8 @@ void validate_kas(PK_Key_Agreement* kas, const std::string& algo, } u32bit validate_rsa_enc_pkcs8(const std::string& algo, - const std::vector<std::string>& str) + const std::vector<std::string>& str, + RandomNumberGenerator& rng) { if(str.size() != 4 && str.size() != 5) throw Exception("Invalid input from pk_valid.dat"); @@ -150,9 +151,7 @@ u32bit validate_rsa_enc_pkcs8(const std::string& algo, DataSource_Memory keysource(reinterpret_cast<const byte*>(str[0].c_str()), str[0].length()); - Private_Key* privkey = PKCS8::load_key(keysource, - global_rng(), - pass); + Private_Key* privkey = PKCS8::load_key(keysource, rng, pass); RSA_PrivateKey* rsapriv = dynamic_cast<RSA_PrivateKey*>(privkey); if(!rsapriv) @@ -172,13 +171,12 @@ u32bit validate_rsa_enc_pkcs8(const std::string& algo, } u32bit validate_rsa_enc(const std::string& algo, - const std::vector<std::string>& str) + const std::vector<std::string>& str, + RandomNumberGenerator& rng) { if(str.size() != 6) throw Exception("Invalid input from pk_valid.dat"); - RandomNumberGenerator& rng = global_rng(); - RSA_PrivateKey privkey(rng, to_bigint(str[1]), to_bigint(str[2]), to_bigint(str[0])); @@ -196,13 +194,12 @@ u32bit validate_rsa_enc(const std::string& algo, } u32bit validate_elg_enc(const std::string& algo, - const std::vector<std::string>& str) + const std::vector<std::string>& str, + RandomNumberGenerator& rng) { if(str.size() != 6 && str.size() != 7) throw Exception("Invalid input from pk_valid.dat"); - RandomNumberGenerator& rng = global_rng(); - DL_Group domain(to_bigint(str[0]), to_bigint(str[1])); ElGamal_PrivateKey privkey(rng, domain, to_bigint(str[2])); ElGamal_PublicKey pubkey = privkey; @@ -225,13 +222,12 @@ u32bit validate_elg_enc(const std::string& algo, } u32bit validate_rsa_sig(const std::string& algo, - const std::vector<std::string>& str) + const std::vector<std::string>& str, + RandomNumberGenerator& rng) { if(str.size() != 6) throw Exception("Invalid input from pk_valid.dat"); - RandomNumberGenerator& rng = global_rng(); - RSA_PrivateKey privkey(rng, to_bigint(str[1]), to_bigint(str[2]), to_bigint(str[0])); @@ -324,13 +320,12 @@ u32bit validate_rw_ver(const std::string& algo, } u32bit validate_rw_sig(const std::string& algo, - const std::vector<std::string>& str) + const std::vector<std::string>& str, + RandomNumberGenerator& rng) { if(str.size() != 6) throw Exception("Invalid input from pk_valid.dat"); - RandomNumberGenerator& rng = global_rng(); - RW_PrivateKey privkey(rng, to_bigint(str[1]), to_bigint(str[2]), to_bigint(str[0])); RW_PublicKey pubkey = privkey; @@ -346,7 +341,8 @@ u32bit validate_rw_sig(const std::string& algo, } u32bit validate_dsa_sig(const std::string& algo, - const std::vector<std::string>& str) + const std::vector<std::string>& str, + RandomNumberGenerator& rng) { if(str.size() != 4 && str.size() != 5) throw Exception("Invalid input from pk_valid.dat"); @@ -359,9 +355,7 @@ u32bit validate_dsa_sig(const std::string& algo, DataSource_Memory keysource(reinterpret_cast<const byte*>(str[0].c_str()), str[0].length()); - Private_Key* privkey = PKCS8::load_key(keysource, - global_rng(), - pass); + Private_Key* privkey = PKCS8::load_key(keysource, rng, pass); DSA_PrivateKey* dsapriv = dynamic_cast<DSA_PrivateKey*>(privkey); if(!dsapriv) @@ -413,13 +407,12 @@ u32bit validate_dsa_ver(const std::string& algo, } u32bit validate_nr_sig(const std::string& algo, - const std::vector<std::string>& str) + const std::vector<std::string>& str, + RandomNumberGenerator& rng) { if(str.size() != 8) throw Exception("Invalid input from pk_valid.dat"); - RandomNumberGenerator& rng = global_rng(); - DL_Group domain(to_bigint(str[0]), to_bigint(str[1]), to_bigint(str[2])); NR_PrivateKey privkey(rng, domain, to_bigint(str[4])); NR_PublicKey pubkey = privkey; @@ -435,13 +428,12 @@ u32bit validate_nr_sig(const std::string& algo, } u32bit validate_dh(const std::string& algo, - const std::vector<std::string>& str) + const std::vector<std::string>& str, + RandomNumberGenerator& rng) { if(str.size() != 5 && str.size() != 6) throw Exception("Invalid input from pk_valid.dat"); - RandomNumberGenerator& rng = global_rng(); - DL_Group domain(to_bigint(str[0]), to_bigint(str[1])); DH_PrivateKey mykey(rng, domain, to_bigint(str[2])); @@ -462,13 +454,12 @@ u32bit validate_dh(const std::string& algo, } u32bit validate_dlies(const std::string& algo, - const std::vector<std::string>& str) + const std::vector<std::string>& str, + RandomNumberGenerator& rng) { if(str.size() != 6) throw Exception("Invalid input from pk_valid.dat"); - RandomNumberGenerator& rng = global_rng(); - DL_Group domain(to_bigint(str[0]), to_bigint(str[1])); DH_PrivateKey from(rng, domain, to_bigint(str[2])); @@ -495,7 +486,7 @@ u32bit validate_dlies(const std::string& algo, return (failure ? 1 : 0); } -void do_pk_keygen_tests() +void do_pk_keygen_tests(RandomNumberGenerator& rng) { std::cout << "Testing PK key generation: " << std::flush; @@ -528,8 +519,6 @@ void do_pk_keygen_tests() std::cout << '.' << std::flush; \ } - RandomNumberGenerator& rng = global_rng(); - IF_SIG_KEY(RSA_PrivateKey, 1024); IF_SIG_KEY(RW_PrivateKey, 1024); @@ -554,7 +543,8 @@ void do_pk_keygen_tests() } -u32bit do_pk_validation_tests(const std::string& filename) +u32bit do_pk_validation_tests(const std::string& filename, + RandomNumberGenerator& rng) { std::ifstream test_data(filename.c_str()); @@ -623,33 +613,33 @@ u32bit do_pk_validation_tests(const std::string& filename) u32bit new_errors = 0; if(algorithm.find("DSA/") != std::string::npos) - new_errors = validate_dsa_sig(algorithm, substr); + new_errors = validate_dsa_sig(algorithm, substr, rng); else if(algorithm.find("DSA_VA/") != std::string::npos) new_errors = validate_dsa_ver(algorithm, substr); else if(algorithm.find("RSAES_PKCS8/") != std::string::npos) - new_errors = validate_rsa_enc_pkcs8(algorithm, substr); + new_errors = validate_rsa_enc_pkcs8(algorithm, substr, rng); else if(algorithm.find("RSAVA_X509/") != std::string::npos) new_errors = validate_rsa_ver_x509(algorithm, substr); else if(algorithm.find("RSAES/") != std::string::npos) - new_errors = validate_rsa_enc(algorithm, substr); + new_errors = validate_rsa_enc(algorithm, substr, rng); else if(algorithm.find("RSASSA/") != std::string::npos) - new_errors = validate_rsa_sig(algorithm, substr); + new_errors = validate_rsa_sig(algorithm, substr, rng); else if(algorithm.find("RSAVA/") != std::string::npos) new_errors = validate_rsa_ver(algorithm, substr); else if(algorithm.find("RWVA/") != std::string::npos) new_errors = validate_rw_ver(algorithm, substr); else if(algorithm.find("RW/") != std::string::npos) - new_errors = validate_rw_sig(algorithm, substr); + new_errors = validate_rw_sig(algorithm, substr, rng); else if(algorithm.find("NR/") != std::string::npos) - new_errors = validate_nr_sig(algorithm, substr); + new_errors = validate_nr_sig(algorithm, substr, rng); else if(algorithm.find("ElGamal/") != std::string::npos) - new_errors = validate_elg_enc(algorithm, substr); + new_errors = validate_elg_enc(algorithm, substr, rng); else if(algorithm.find("DH/") != std::string::npos) - new_errors = validate_dh(algorithm, substr); + new_errors = validate_dh(algorithm, substr, rng); else if(algorithm.find("DLIES/") != std::string::npos) - new_errors = validate_dlies(algorithm, substr); + new_errors = validate_dlies(algorithm, substr, rng); else std::cout << "WARNING: Unknown PK algorithm " << algorithm << std::endl; @@ -664,8 +654,8 @@ u32bit do_pk_validation_tests(const std::string& filename) std::cout << std::endl; - do_pk_keygen_tests(); - do_x509_tests(); + do_pk_keygen_tests(rng); + do_x509_tests(rng); return errors; } diff --git a/checks/pk_bench.cpp b/checks/pk_bench.cpp index 31f1d3073..8bb4e791c 100644 --- a/checks/pk_bench.cpp +++ b/checks/pk_bench.cpp @@ -21,13 +21,20 @@ using namespace Botan; #define PRINT_MS_PER_OP 0 /* If 0, print ops / second */ -void bench_enc(PK_Encryptor*, const std::string&, double, bool); -void bench_dec(PK_Encryptor*, PK_Decryptor*, const std::string&, double, bool); -void bench_sig(PK_Signer*, const std::string&, double, bool); -void bench_ver(PK_Signer*, PK_Verifier*, const std::string&, double, bool); -void bench_kas(PK_Key_Agreement*, const std::string&, double, bool); - -void bench_pk(const std::string& algo, bool html, double seconds) +void bench_enc(PK_Encryptor*, RandomNumberGenerator&, + const std::string&, double, bool); +void bench_dec(PK_Encryptor*, PK_Decryptor*, RandomNumberGenerator&, + const std::string&, double, bool); +void bench_sig(PK_Signer*, RandomNumberGenerator&, + const std::string&, double, bool); +void bench_ver(PK_Signer*, PK_Verifier*, + RandomNumberGenerator&, + const std::string&, double, bool); +void bench_kas(PK_Key_Agreement*, RandomNumberGenerator&, + const std::string&, double, bool); + +void bench_pk(RandomNumberGenerator& rng, + const std::string& algo, bool html, double seconds) { /* There is some strangeness going on here. It looks like algorithms @@ -54,7 +61,6 @@ 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_rng(); if(algo == "All" || algo == "RSA") { @@ -73,11 +79,11 @@ void bench_pk(const std::string& algo, bool html, double seconds) throw Invalid_Argument("Failure reading RSA key from " + file); bench_enc(get_pk_encryptor(*key, "Raw"), - "RSA-" + len_str, seconds, html); + rng, "RSA-" + len_str, seconds, html); bench_dec(get_pk_encryptor(*key, "Raw"), get_pk_decryptor(*key, "Raw"), - "RSA-" + len_str, seconds, html); + rng, "RSA-" + len_str, seconds, html); } } @@ -93,10 +99,10 @@ void bench_pk(const std::string& algo, bool html, double seconds) bench_ver(get_pk_signer(key, "EMSA1(SHA-1)"), get_pk_verifier(key, "EMSA1(SHA-1)"), - "DSA-" + len_str, seconds, html); + rng, "DSA-" + len_str, seconds, html); bench_sig(get_pk_signer(key, "EMSA1(SHA-1)"), - "DSA-" + len_str, seconds, html); + rng, "DSA-" + len_str, seconds, html); } } @@ -111,7 +117,8 @@ void bench_pk(const std::string& algo, bool html, double seconds) DH_PrivateKey key(rng, "modp/ietf/" + len_str); - bench_kas(get_pk_kas(key, "Raw"), "DH-" + len_str, seconds, html); + bench_kas(get_pk_kas(key, "Raw"), rng, + "DH-" + len_str, seconds, html); } } @@ -126,11 +133,11 @@ void bench_pk(const std::string& algo, bool html, double seconds) ElGamal_PrivateKey key(rng, "modp/ietf/" + len_str); bench_enc(get_pk_encryptor(key, "Raw"), - "ELG-" + len_str, seconds, html); + rng, "ELG-" + len_str, seconds, html); bench_dec(get_pk_encryptor(key, "Raw"), get_pk_decryptor(key, "Raw"), - "ELG-" + len_str, seconds, html); + rng, "ELG-" + len_str, seconds, html); } } @@ -146,10 +153,10 @@ void bench_pk(const std::string& algo, bool html, double seconds) bench_ver(get_pk_signer(key, "EMSA1(SHA-1)"), get_pk_verifier(key, "EMSA1(SHA-1)"), - "NR-" + len_str, seconds, html); + rng, "NR-" + len_str, seconds, html); bench_sig(get_pk_signer(key, "EMSA1(SHA-1)"), - "NR-" + len_str, seconds, html); + rng, "NR-" + len_str, seconds, html); } } @@ -167,9 +174,9 @@ void bench_pk(const std::string& algo, bool html, double seconds) bench_ver(get_pk_signer(*key, "EMSA2(SHA-1)"), get_pk_verifier(*key, "EMSA2(SHA-1)"), - "RW-" + len_str, seconds, html); + rng, "RW-" + len_str, seconds, html); bench_sig(get_pk_signer(*key, "EMSA2(SHA-1)"), - "RW-" + len_str, seconds, html); + rng, "RW-" + len_str, seconds, html); delete key; } @@ -212,7 +219,9 @@ void print_result(bool html, u32bit runs, u64bit clocks_used, } -void bench_enc(PK_Encryptor* enc, const std::string& algo_name, +void bench_enc(PK_Encryptor* enc, + RandomNumberGenerator& rng, + const std::string& algo_name, double seconds, bool html) { static const u32bit MSG_SIZE = 16; @@ -226,10 +235,10 @@ void bench_enc(PK_Encryptor* enc, const std::string& algo_name, while(clocks_used < seconds * ticks) { runs++; - global_rng().randomize(msg, MSG_SIZE); + rng.randomize(msg, MSG_SIZE); u64bit start = get_clock(); - enc->encrypt(msg, MSG_SIZE, global_rng()); + enc->encrypt(msg, MSG_SIZE, rng); clocks_used += get_clock() - start; } @@ -239,29 +248,28 @@ void bench_enc(PK_Encryptor* enc, const std::string& algo_name, } void bench_dec(PK_Encryptor* enc, PK_Decryptor* dec, + RandomNumberGenerator& rng, const std::string& algo_name, double seconds, bool html) { static const u32bit MSG_SIZE = 16; byte msg[MSG_SIZE]; - global_rng().randomize(msg, MSG_SIZE); + rng.randomize(msg, MSG_SIZE); SecureVector<byte> output; u32bit runs = 0; u64bit clocks_used = 0; - SecureVector<byte> encrypted_msg = enc->encrypt(msg, MSG_SIZE, - global_rng()); + SecureVector<byte> encrypted_msg = enc->encrypt(msg, MSG_SIZE, rng); const u64bit ticks = get_ticks(); while(clocks_used < seconds * ticks) { runs++; - global_rng().randomize(msg, MSG_SIZE); + rng.randomize(msg, MSG_SIZE); msg[0] |= 0x80; // make sure it works with "Raw" padding - encrypted_msg = enc->encrypt(msg, MSG_SIZE, - global_rng()); + encrypted_msg = enc->encrypt(msg, MSG_SIZE, rng); u64bit start = get_clock(); output = dec->decrypt(encrypted_msg); @@ -282,7 +290,9 @@ void bench_dec(PK_Encryptor* enc, PK_Decryptor* dec, print_result(html, runs, clocks_used, algo_name, "private operation"); } -void bench_sig(PK_Signer* sig, const std::string& algo_name, +void bench_sig(PK_Signer* sig, + RandomNumberGenerator& rng, + const std::string& algo_name, double seconds, bool html) { static const u32bit MSG_SIZE = 16; @@ -295,10 +305,10 @@ void bench_sig(PK_Signer* sig, const std::string& algo_name, while(clocks_used < seconds * ticks) { runs++; - global_rng().randomize(msg, MSG_SIZE); + rng.randomize(msg, MSG_SIZE); u64bit start = get_clock(); sig->update(msg, MSG_SIZE); - sig->signature(global_rng()); + sig->signature(rng); clocks_used += get_clock() - start; } @@ -308,15 +318,16 @@ void bench_sig(PK_Signer* sig, const std::string& algo_name, } void bench_ver(PK_Signer* sig, PK_Verifier* ver, + RandomNumberGenerator& rng, const std::string& algo_name, double seconds, bool html) { static const u32bit MSG_SIZE = 16; byte msg[MSG_SIZE]; - global_rng().randomize(msg, MSG_SIZE); + rng.randomize(msg, MSG_SIZE); sig->update(msg, MSG_SIZE); - SecureVector<byte> signature = sig->signature(global_rng()); + SecureVector<byte> signature = sig->signature(rng); u32bit runs = 0; u64bit clocks_used = 0; @@ -326,9 +337,9 @@ void bench_ver(PK_Signer* sig, PK_Verifier* ver, // feel free to tweak, but make sure this always runs when runs == 0 if(runs % 100 == 0) { - global_rng().randomize(msg, MSG_SIZE); + rng.randomize(msg, MSG_SIZE); sig->update(msg, MSG_SIZE); - signature = sig->signature(global_rng()); + signature = sig->signature(rng); } runs++; @@ -347,7 +358,9 @@ void bench_ver(PK_Signer* sig, PK_Verifier* ver, print_result(html, runs, clocks_used, algo_name, "public operation"); } -void bench_kas(PK_Key_Agreement* kas, const std::string& algo_name, +void bench_kas(PK_Key_Agreement* kas, + RandomNumberGenerator& rng, + const std::string& algo_name, double seconds, bool html) { /* 128 bits: should always be considered valid (what about ECC?) */ @@ -361,7 +374,7 @@ void bench_kas(PK_Key_Agreement* kas, const std::string& algo_name, while(clocks_used < seconds * ticks) { runs++; - global_rng().randomize(key, REMOTE_KEY_SIZE); + rng.randomize(key, REMOTE_KEY_SIZE); u64bit start = get_clock(); kas->derive_key(0, key, REMOTE_KEY_SIZE); diff --git a/checks/validate.h b/checks/validate.h index c411ff702..a562cd4b4 100644 --- a/checks/validate.h +++ b/checks/validate.h @@ -2,9 +2,13 @@ #ifndef BOTAN_TEST_VALIDATE_H__ #define BOTAN_TEST_VALIDATE_H__ +#include <botan/rng.h> +#include <string> + u32bit do_validation_tests(const std::string&, bool = true); u32bit do_bigint_tests(const std::string&); -u32bit do_pk_validation_tests(const std::string&); -void do_x509_tests(); +u32bit do_pk_validation_tests(const std::string&, + Botan::RandomNumberGenerator&); +void do_x509_tests(Botan::RandomNumberGenerator&); #endif diff --git a/checks/x509.cpp b/checks/x509.cpp index 3c802356b..f2517d02a 100644 --- a/checks/x509.cpp +++ b/checks/x509.cpp @@ -44,10 +44,9 @@ u64bit key_id(const Public_Key* key) return id; } -u32bit check_against_copy(const Private_Key& orig) +u32bit check_against_copy(const Private_Key& orig, + RandomNumberGenerator& rng) { - RandomNumberGenerator& rng = global_rng(); - Private_Key* copy_priv = PKCS8::copy_key(orig, rng); Public_Key* copy_pub = X509::copy_key(orig); @@ -75,10 +74,8 @@ u32bit check_against_copy(const Private_Key& orig) } -void do_x509_tests() +void do_x509_tests(RandomNumberGenerator& rng) { - RandomNumberGenerator& rng = global_rng(); - std::cout << "Testing X.509 CA/CRL/cert/cert request: " << std::flush; /* Create the CA's key and self-signed cert */ @@ -153,9 +150,9 @@ void do_x509_tests() if(store.validate_cert(user2_cert) != CERT_IS_REVOKED) std::cout << "\nFAILED: User cert #2 was not revoked" << std::endl; - check_against_copy(ca_key); - check_against_copy(user1_key); - check_against_copy(user2_key); + check_against_copy(ca_key, rng); + check_against_copy(user1_key, rng); + check_against_copy(user2_key, rng); std::cout << std::endl; } |