aboutsummaryrefslogtreecommitdiffstats
path: root/checks/pk_bench.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'checks/pk_bench.cpp')
-rw-r--r--checks/pk_bench.cpp149
1 files changed, 111 insertions, 38 deletions
diff --git a/checks/pk_bench.cpp b/checks/pk_bench.cpp
index 84eba79e2..a180778a6 100644
--- a/checks/pk_bench.cpp
+++ b/checks/pk_bench.cpp
@@ -6,7 +6,6 @@
#include <botan/pkcs8.h>
#include <botan/mem_ops.h>
-#include <botan/look_pk.h>
#include <botan/libstate.h>
#include <botan/parsing.h>
@@ -49,6 +48,10 @@
#include <botan/ecdh.h>
#endif
+#if defined(BOTAN_HAS_GOST_34_10_2001)
+ #include <botan/gost_3410.h>
+#endif
+
using namespace Botan;
#include "common.h"
@@ -211,13 +214,16 @@ void benchmark_rsa(RandomNumberGenerator& rng,
while(verify_timer.seconds() < seconds ||
sig_timer.seconds() < seconds)
{
- std::unique_ptr<PK_Encryptor> enc(get_pk_encryptor(key, enc_padding));
- std::unique_ptr<PK_Decryptor> dec(get_pk_decryptor(key, enc_padding));
- benchmark_enc_dec(*enc, *dec, enc_timer, dec_timer, rng, 10000, seconds);
+ PK_Encryptor_EME enc(key, enc_padding);
+ PK_Decryptor_EME dec(key, enc_padding);
+
+ benchmark_enc_dec(enc, dec, enc_timer, dec_timer,
+ rng, 10000, seconds);
+
+ PK_Signer sig(key, sig_padding);
+ PK_Verifier ver(key, sig_padding);
- std::unique_ptr<PK_Signer> sig(get_pk_signer(key, sig_padding));
- std::unique_ptr<PK_Verifier> ver(get_pk_verifier(key, sig_padding));
- benchmark_sig_ver(*ver, *sig, verify_timer,
+ benchmark_sig_ver(ver, sig, verify_timer,
sig_timer, rng, 10000, seconds);
}
@@ -266,10 +272,11 @@ void benchmark_rw(RandomNumberGenerator& rng,
RW_PrivateKey key(rng, keylen);
keygen_timer.stop();
- std::unique_ptr<PK_Signer> sig(get_pk_signer(key, padding));
- std::unique_ptr<PK_Verifier> ver(get_pk_verifier(key, padding));
+ PK_Signer sig(key, padding);
+ PK_Verifier ver(key, padding);
- benchmark_sig_ver(*ver, *sig, verify_timer, sig_timer, rng, 10000, seconds);
+ benchmark_sig_ver(ver, sig, verify_timer, sig_timer,
+ rng, 10000, seconds);
}
const std::string nm = "RW-" + std::to_string(keylen);
@@ -321,10 +328,10 @@ void benchmark_ecdsa(RandomNumberGenerator& rng,
ECDSA_PrivateKey key(rng, params);
keygen_timer.stop();
- std::unique_ptr<PK_Signer> sig(get_pk_signer(key, padding));
- std::unique_ptr<PK_Verifier> ver(get_pk_verifier(key, padding));
+ PK_Signer sig(key, padding);
+ PK_Verifier ver(key, padding);
- benchmark_sig_ver(*ver, *sig, verify_timer,
+ benchmark_sig_ver(ver, sig, verify_timer,
sig_timer, rng, 1000, seconds);
}
@@ -338,11 +345,70 @@ void benchmark_ecdsa(RandomNumberGenerator& rng,
#endif
+#if defined(BOTAN_HAS_GOST_34_10_2001)
+
+void benchmark_gost_3410(RandomNumberGenerator& rng,
+ double seconds,
+ Benchmark_Report& report)
+ {
+ const char* domains[] = { "1.3.132.0.6", // secp112r1
+ "1.3.132.0.28", // secp128r1
+ "1.3.132.0.30", // secp160r2
+ "1.3.132.0.33", // secp224r1
+ "1.2.643.2.2.35.1", // gost 256p
+ "1.3.132.0.34", // secp384r1
+ "1.3.132.0.35", // secp512r1
+ NULL };
+
+ for(size_t j = 0; domains[j]; j++)
+ {
+ OID oid(domains[j]);
+ EC_Domain_Params params(oid);
+
+ u32bit pbits = params.get_curve().get_p().bits();
+
+ u32bit hashbits = pbits;
+
+ if(hashbits < 160)
+ hashbits = 160;
+ if(hashbits == 521)
+ hashbits = 512;
+
+ const std::string padding = "EMSA1(SHA-" + to_string(hashbits) + ")";
+
+ Timer keygen_timer("keygen");
+ Timer verify_timer(padding + " verify");
+ Timer sig_timer(padding + " signature");
+
+ while(verify_timer.seconds() < seconds ||
+ sig_timer.seconds() < seconds)
+ {
+ keygen_timer.start();
+ GOST_3410_PrivateKey key(rng, params);
+ keygen_timer.stop();
+
+ PK_Signer sig(key, padding);
+ PK_Verifier ver(key, padding);
+
+ benchmark_sig_ver(ver, sig, verify_timer,
+ sig_timer, rng, 1000, seconds);
+ }
+
+ const std::string nm = "GOST-34.10-" + to_string(pbits);
+
+ report.report(nm, keygen_timer);
+ report.report(nm, verify_timer);
+ report.report(nm, sig_timer);
+ }
+ }
+
+#endif
+
#if defined(BOTAN_HAS_ECDH)
-void benchmark_eckaeg(RandomNumberGenerator& rng,
- double seconds,
- Benchmark_Report& report)
+void benchmark_ecdh(RandomNumberGenerator& rng,
+ double seconds,
+ Benchmark_Report& report)
{
const char* domains[] = { "1.3.132.0.6", // secp112r1
"1.3.132.0.28", // secp128r1
@@ -365,17 +431,17 @@ void benchmark_eckaeg(RandomNumberGenerator& rng,
while(kex_timer.seconds() < seconds)
{
keygen_timer.start();
- ECDH_PrivateKey eckaeg1(rng, params);
+ ECDH_PrivateKey ecdh1(rng, params);
keygen_timer.stop();
keygen_timer.start();
- ECDH_PrivateKey eckaeg2(rng, params);
+ ECDH_PrivateKey ecdh2(rng, params);
keygen_timer.stop();
- ECDH_PublicKey pub1(eckaeg1);
- ECDH_PublicKey pub2(eckaeg2);
+ PK_Key_Agreement ka1(ecdh1, "KDF2(SHA-1)");
+ PK_Key_Agreement ka2(ecdh2, "KDF2(SHA-1)");
- SecureVector<byte> secret1, secret2;
+ SymmetricKey secret1, secret2;
for(u32bit i = 0; i != 1000; ++i)
{
@@ -383,15 +449,15 @@ void benchmark_eckaeg(RandomNumberGenerator& rng,
break;
kex_timer.start();
- secret1 = eckaeg1.derive_key(pub2);
+ secret1 = ka1.derive_key(32, ecdh2.public_value());
kex_timer.stop();
kex_timer.start();
- secret2 = eckaeg2.derive_key(pub1);
+ secret2 = ka2.derive_key(32, ecdh1.public_value());
kex_timer.stop();
if(secret1 != secret2)
- std::cerr << "ECDH secrets did not match, bug in the library!?!\n";
+ std::cerr << "ECDH secrets did not match\n";
}
}
@@ -416,7 +482,7 @@ void benchmark_dsa_nr(RandomNumberGenerator& rng,
"dsa/botan/3072",
NULL };
- const std::string algo_name = PRIV_KEY_TYPE().algo_name();
+ std::string algo_name;
for(size_t j = 0; domains[j]; j++)
{
@@ -436,12 +502,13 @@ void benchmark_dsa_nr(RandomNumberGenerator& rng,
keygen_timer.start();
PRIV_KEY_TYPE key(rng, group);
+ algo_name = key.algo_name();
keygen_timer.stop();
- std::unique_ptr<PK_Signer> sig(get_pk_signer(key, padding));
- std::unique_ptr<PK_Verifier> ver(get_pk_verifier(key, padding));
+ PK_Signer sig(key, padding);
+ PK_Verifier ver(key, padding);
- benchmark_sig_ver(*ver, *sig, verify_timer,
+ benchmark_sig_ver(ver, sig, verify_timer,
sig_timer, rng, 1000, seconds);
}
@@ -484,10 +551,10 @@ void benchmark_dh(RandomNumberGenerator& rng,
DH_PrivateKey dh2(rng, group);
keygen_timer.stop();
- DH_PublicKey pub1(dh1);
- DH_PublicKey pub2(dh2);
+ PK_Key_Agreement ka1(dh1, "KDF2(SHA-1)");
+ PK_Key_Agreement ka2(dh2, "KDF2(SHA-1)");
- SecureVector<byte> secret1, secret2;
+ SymmetricKey secret1, secret2;
for(u32bit i = 0; i != 1000; ++i)
{
@@ -495,15 +562,15 @@ void benchmark_dh(RandomNumberGenerator& rng,
break;
kex_timer.start();
- secret1 = dh1.derive_key(pub2);
+ secret1 = ka1.derive_key(32, dh2.public_value());
kex_timer.stop();
kex_timer.start();
- secret2 = dh2.derive_key(pub1);
+ secret2 = ka2.derive_key(32, dh1.public_value());
kex_timer.stop();
if(secret1 != secret2)
- std::cerr << "DH secrets did not match, bug in the library!?!\n";
+ std::cerr << "DH secrets did not match\n";
}
}
@@ -608,10 +675,11 @@ void benchmark_elg(RandomNumberGenerator& rng,
ElGamal_PrivateKey key(rng, group);
keygen_timer.stop();
- std::unique_ptr<PK_Decryptor> dec(get_pk_decryptor(key, padding));
- std::unique_ptr<PK_Encryptor> enc(get_pk_encryptor(key, padding));
+ PK_Decryptor_EME dec(key, padding);
+ PK_Encryptor_EME enc(key, padding);
- benchmark_enc_dec(*enc, *dec, enc_timer, dec_timer, rng, 1000, seconds);
+ benchmark_enc_dec(enc, dec, enc_timer, dec_timer,
+ rng, 1000, seconds);
}
const std::string nm = algo_name + "-" + std::to_string(pbits);
@@ -674,7 +742,12 @@ void bench_pk(RandomNumberGenerator& rng,
#if defined(BOTAN_HAS_ECDH)
if(algo == "All" || algo == "ECDH")
- benchmark_eckaeg(rng, seconds, report);
+ benchmark_ecdh(rng, seconds, report);
+#endif
+
+#if defined(BOTAN_HAS_GOST_34_10_2001)
+ if(algo == "All" || algo == "GOST-34.10")
+ benchmark_gost_3410(rng, seconds, report);
#endif
#if defined(BOTAN_HAS_DIFFIE_HELLMAN)