diff options
author | lloyd <[email protected]> | 2008-09-14 03:52:17 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-09-14 03:52:17 +0000 |
commit | ee1c08d6fef6c624480cb405b364df578d16adc7 (patch) | |
tree | 35683ee9594354f9a0ee4e26d7f6cd84bc43abfb /checks/pk_bench.cpp | |
parent | 33a3cf904d1df95cbf0f04515b894bc7105cebb8 (diff) |
Split RSA and RW benchmarks. Benchmark RSA encryption and signatures.
Diffstat (limited to 'checks/pk_bench.cpp')
-rw-r--r-- | checks/pk_bench.cpp | 103 |
1 files changed, 87 insertions, 16 deletions
diff --git a/checks/pk_bench.cpp b/checks/pk_bench.cpp index ca90b82cf..38d2bb40a 100644 --- a/checks/pk_bench.cpp +++ b/checks/pk_bench.cpp @@ -35,7 +35,9 @@ void benchmark_enc_dec(PK_Encryptor& enc, PK_Decryptor& dec, { if(enc_timer.seconds() < seconds || ciphertext.size() == 0) { - plaintext.create(48); + plaintext.create(enc.maximum_input_size()); + + // Ensure for Raw, etc, it stays large rng.randomize(plaintext.begin(), plaintext.size()); plaintext[0] |= 0x80; @@ -47,11 +49,13 @@ void benchmark_enc_dec(PK_Encryptor& enc, PK_Decryptor& dec, if(dec_timer.seconds() < seconds) { dec_timer.start(); - SecureVector<byte> plaintext2 = dec.decrypt(ciphertext); + SecureVector<byte> plaintext_out = dec.decrypt(ciphertext); dec_timer.stop(); - if(plaintext != plaintext2) - std::cerr << "Contents mismatched on decryption in RSA benchmark!\n"; + if(plaintext_out != plaintext) + { // has never happened... + std::cerr << "Contents mismatched on decryption during benchmark!\n"; + } } } } @@ -61,7 +65,7 @@ void benchmark_sig_ver(PK_Verifier& ver, PK_Signer& sig, RandomNumberGenerator& rng, u32bit runs, double seconds) { - SecureVector<byte> message, signature; + SecureVector<byte> message, signature, sig_random; for(u32bit i = 0; i != runs; ++i) { @@ -83,18 +87,82 @@ void benchmark_sig_ver(PK_Verifier& ver, PK_Signer& sig, if(!verified) std::cerr << "Signature verification failure\n"; + + /* Also do a false verification to test/time that */ + + if(rng.next_byte() % 2) + { + sig_random.create(signature.size()); + rng.randomize(sig_random, sig_random.size()); + + verify_timer.start(); + bool verified2 = ver.verify_message(message, sig_random); + verify_timer.stop(); + + if(verified2) + std::cerr << "Signature verification failure (bad sig OK)\n"; + } } } } -template<typename PRIV_KEY_TYPE> -void benchmark_rsa_rw(RandomNumberGenerator& rng, - double seconds, - Benchmark_Report& report) +/* + Between benchmark_rsa_rw + benchmark_dsa_nr: + Type of the key + Arguments to the constructor (A list of some arbitrary type?) + Type of padding +*/ + +void benchmark_rsa(RandomNumberGenerator& rng, + double seconds, + Benchmark_Report& report) { const u32bit keylens[] = { 512, 1024, 2048, 3072, 4096, 6144, 8192, 0 }; - const std::string algo_name = PRIV_KEY_TYPE().algo_name(); + for(size_t j = 0; keylens[j]; j++) + { + u32bit keylen = keylens[j]; + + Timer keygen_timer("keygen"); + Timer verify_timer("verify"); + Timer sig_timer("signature"); + Timer enc_timer("encrypt"); + Timer dec_timer("decrypt"); + + const std::string sig_padding = "EMSA4(SHA-1)"; + const std::string enc_padding = "EME1(SHA-1)"; + + while(verify_timer.seconds() < seconds || + sig_timer.seconds() < seconds) + { + keygen_timer.start(); + RSA_PrivateKey key(rng, keylen); + keygen_timer.stop(); + + std::auto_ptr<PK_Encryptor> enc(get_pk_encryptor(key, enc_padding)); + std::auto_ptr<PK_Decryptor> dec(get_pk_decryptor(key, enc_padding)); + benchmark_enc_dec(*enc, *dec, enc_timer, dec_timer, rng, 10000, seconds); + + std::auto_ptr<PK_Signer> sig(get_pk_signer(key, sig_padding)); + std::auto_ptr<PK_Verifier> ver(get_pk_verifier(key, sig_padding)); + benchmark_sig_ver(*ver, *sig, verify_timer, sig_timer, rng, 10000, seconds); + } + + const std::string rsa_keylen = "RSA " + to_string(keylen); + + report.report(rsa_keylen, keygen_timer); + report.report(rsa_keylen + " " + sig_padding, verify_timer); + report.report(rsa_keylen + " " + sig_padding, sig_timer); + report.report(rsa_keylen + " " + enc_padding, enc_timer); + report.report(rsa_keylen + " " + enc_padding, dec_timer); + } + } + +void benchmark_rw(RandomNumberGenerator& rng, + double seconds, + Benchmark_Report& report) + { + const u32bit keylens[] = { 512, 1024, 2048, 3072, 4096, 6144, 8192, 0 }; for(size_t j = 0; keylens[j]; j++) { @@ -104,13 +172,13 @@ void benchmark_rsa_rw(RandomNumberGenerator& rng, Timer verify_timer("verify"); Timer sig_timer("signature"); - std::string padding = (algo_name == "RSA") ? "EMSA1(SHA-1)" : "EMSA2(SHA-1)"; + std::string padding = "EMSA2(SHA-1)"; while(verify_timer.seconds() < seconds || sig_timer.seconds() < seconds) { keygen_timer.start(); - PRIV_KEY_TYPE key(rng, keylen); + RW_PrivateKey key(rng, keylen); keygen_timer.stop(); std::auto_ptr<PK_Signer> sig(get_pk_signer(key, padding)); @@ -119,7 +187,7 @@ void benchmark_rsa_rw(RandomNumberGenerator& rng, benchmark_sig_ver(*ver, *sig, verify_timer, sig_timer, rng, 10000, seconds); } - const std::string nm = algo_name + "-" + to_string(keylen); + const std::string nm = "RW-" + to_string(keylen); report.report(nm, keygen_timer); report.report(nm, verify_timer); report.report(nm, sig_timer); @@ -183,6 +251,7 @@ void benchmark_dh(RandomNumberGenerator& rng, "modp/ietf/3072", "modp/ietf/4096", "modp/ietf/6144", + "modp/ietf/8192", NULL }; for(size_t j = 0; domains[j]; j++) @@ -244,6 +313,8 @@ void benchmark_elg(RandomNumberGenerator& rng, "modp/ietf/2048", "modp/ietf/3072", "modp/ietf/4096", + "modp/ietf/6144", + "modp/ietf/8192", NULL }; const std::string algo_name = "ElGamal"; @@ -270,7 +341,7 @@ void benchmark_elg(RandomNumberGenerator& rng, std::auto_ptr<PK_Decryptor> dec(get_pk_decryptor(key, padding)); std::auto_ptr<PK_Encryptor> enc(get_pk_encryptor(key, padding)); - benchmark_enc_dec(*enc, *dec, enc_timer, dec_timer, rng, 100, seconds); + benchmark_enc_dec(*enc, *dec, enc_timer, dec_timer, rng, 1000, seconds); } const std::string nm = algo_name + "-" + to_string(pbits); @@ -316,7 +387,7 @@ void bench_pk(RandomNumberGenerator& rng, Benchmark_Report report; if(algo == "All" || algo == "RSA") - benchmark_rsa_rw<RSA_PrivateKey>(rng, seconds, report); + benchmark_rsa(rng, seconds, report); if(algo == "All" || algo == "DSA") benchmark_dsa_nr<DSA_PrivateKey>(rng, seconds, report); @@ -331,5 +402,5 @@ void bench_pk(RandomNumberGenerator& rng, benchmark_dsa_nr<NR_PrivateKey>(rng, seconds, report); if(algo == "All" || algo == "RW") - benchmark_rsa_rw<RW_PrivateKey>(rng, seconds, report); + benchmark_rw(rng, seconds, report); } |