aboutsummaryrefslogtreecommitdiffstats
path: root/checks
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-10-01 15:37:15 +0000
committerlloyd <[email protected]>2008-10-01 15:37:15 +0000
commit0d8e86081eb51c698df28b362453b2ef5654fc7b (patch)
tree0a99edff848d1f8284bbdb07ceb6b3991ff1eedb /checks
parent9b8d9c877ffdf544e180112bfb7dede6da5aa5c6 (diff)
Handle building Botan with almost all public key code disabled (though only
with the aid of macro hackery, at the moment). Change DH feature macro to BOTAN_HAS_DIFFIE_HELLMAN Change NR feature macro to BOTAN_HAS_NYBERG_RUEPPEL
Diffstat (limited to 'checks')
-rw-r--r--checks/pk.cpp65
-rw-r--r--checks/pk_bench.cpp19
2 files changed, 49 insertions, 35 deletions
diff --git a/checks/pk.cpp b/checks/pk.cpp
index 550135bb3..57eb12936 100644
--- a/checks/pk.cpp
+++ b/checks/pk.cpp
@@ -15,11 +15,11 @@
#include <botan/dsa.h>
#endif
-#if defined(BOTAN_HAS_DH)
+#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
#include <botan/dh.h>
#endif
-#if defined(BOTAN_HAS_NR)
+#if defined(BOTAN_HAS_NYBERG_RUEPPEL)
#include <botan/nr.h>
#endif
@@ -43,12 +43,16 @@ using namespace Botan;
#include "common.h"
#include "validate.h"
-static BigInt to_bigint(const std::string& h)
+namespace {
+
+BigInt to_bigint(const std::string& h)
{
return BigInt::decode(reinterpret_cast<const byte*>(h.data()),
h.length(), BigInt::Hexadecimal);
}
+}
+
#define DEBUG 0
namespace {
@@ -163,7 +167,6 @@ u32bit validate_rsa_enc_pkcs8(const std::string& algo,
if(str.size() != 4 && str.size() != 5)
throw Exception("Invalid input from pk_valid.dat");
- bool failure = false;
#if defined(BOTAN_HAS_RSA)
std::string pass;
@@ -187,10 +190,12 @@ u32bit validate_rsa_enc_pkcs8(const std::string& algo,
PK_Encryptor* e = get_pk_encryptor(*rsapub, eme);
PK_Decryptor* d = get_pk_decryptor(*rsapriv, eme);
+ bool failure = false;
validate_encryption(e, d, algo, str[1], str[2], str[3], failure);
+ return (failure ? 1 : 0);
#endif
- return (failure ? 1 : 0);
+ return 2;
}
u32bit validate_rsa_enc(const std::string& algo,
@@ -200,7 +205,6 @@ u32bit validate_rsa_enc(const std::string& algo,
if(str.size() != 6)
throw Exception("Invalid input from pk_valid.dat");
- bool failure = false;
#if defined(BOTAN_HAS_RSA)
RSA_PrivateKey privkey(rng,
@@ -214,10 +218,12 @@ u32bit validate_rsa_enc(const std::string& algo,
PK_Encryptor* e = get_pk_encryptor(pubkey, eme);
PK_Decryptor* d = get_pk_decryptor(privkey, eme);
+ bool failure = false;
validate_encryption(e, d, algo, str[3], str[4], str[5], failure);
+ return (failure ? 1 : 0);
#endif
- return (failure ? 1 : 0);
+ return 2;
}
u32bit validate_elg_enc(const std::string& algo,
@@ -227,7 +233,6 @@ u32bit validate_elg_enc(const std::string& algo,
if(str.size() != 6 && str.size() != 7)
throw Exception("Invalid input from pk_valid.dat");
- bool failure = false;
#if defined(BOTAN_HAS_ELGAMAL)
DL_Group domain(to_bigint(str[0]), to_bigint(str[1]));
@@ -238,6 +243,7 @@ u32bit validate_elg_enc(const std::string& algo,
PK_Decryptor* d = get_pk_decryptor(privkey, eme);
+ bool failure = false;
if(str.size() == 7)
{
PK_Encryptor* e = get_pk_encryptor(pubkey, eme);
@@ -246,9 +252,10 @@ u32bit validate_elg_enc(const std::string& algo,
else
validate_decryption(d, algo, decode_hex(str[5]),
decode_hex(str[4]), failure);
+ return (failure ? 1 : 0);
#endif
- return (failure ? 1 : 0);
+ return 2;
}
u32bit validate_rsa_sig(const std::string& algo,
@@ -258,7 +265,6 @@ u32bit validate_rsa_sig(const std::string& algo,
if(str.size() != 6)
throw Exception("Invalid input from pk_valid.dat");
- bool failure = false;
#if defined(BOTAN_HAS_RSA)
RSA_PrivateKey privkey(rng,
@@ -271,10 +277,12 @@ u32bit validate_rsa_sig(const std::string& algo,
PK_Verifier* v = get_pk_verifier(pubkey, emsa);
PK_Signer* s = get_pk_signer(privkey, emsa);
+ bool failure = false;
validate_signature(v, s, algo, str[3], str[4], str[5], failure);
+ return (failure ? 1 : 0);
#endif
- return (failure ? 1 : 0);
+ return 2;
}
u32bit validate_rsa_ver(const std::string& algo,
@@ -283,8 +291,6 @@ u32bit validate_rsa_ver(const std::string& algo,
if(str.size() != 5) /* is actually 4, parse() adds an extra empty one */
throw Exception("Invalid input from pk_valid.dat");
- bool passed = true;
-
#if defined(BOTAN_HAS_RSA)
RSA_PublicKey key(to_bigint(str[1]), to_bigint(str[0]));
@@ -295,10 +301,12 @@ u32bit validate_rsa_ver(const std::string& algo,
SecureVector<byte> msg = decode_hex(str[2]);
SecureVector<byte> sig = decode_hex(str[3]);
+ bool passed = true;
passed = v->verify_message(msg, msg.size(), sig, sig.size());
+ return (passed ? 0 : 1);
#endif
- return (passed ? 0 : 1);
+ return 2;
}
u32bit validate_rsa_ver_x509(const std::string& algo,
@@ -307,8 +315,6 @@ u32bit validate_rsa_ver_x509(const std::string& algo,
if(str.size() != 5) /* is actually 3, parse() adds extra empty ones */
throw Exception("Invalid input from pk_valid.dat");
- bool passed = true;
-
#if defined(BOTAN_HAS_RSA)
DataSource_Memory keysource(reinterpret_cast<const byte*>(str[0].c_str()),
str[0].length());
@@ -327,10 +333,12 @@ u32bit validate_rsa_ver_x509(const std::string& algo,
SecureVector<byte> msg = decode_hex(str[1]);
SecureVector<byte> sig = decode_hex(str[2]);
- passed = v->verify_message(msg, msg.size(), sig, sig.size());
+ bool passed = v->verify_message(msg, msg.size(), sig, sig.size());
+ return (passed ? 0 : 1);
+
#endif
- return (passed ? 0 : 1);
+ return 2;
}
u32bit validate_rw_ver(const std::string& algo,
@@ -339,7 +347,7 @@ u32bit validate_rw_ver(const std::string& algo,
if(str.size() != 5)
throw Exception("Invalid input from pk_valid.dat");
- bool passed = true;
+
#if defined(BOTAN_HAS_RW)
RW_PublicKey key(to_bigint(str[1]), to_bigint(str[0]));
@@ -351,10 +359,12 @@ u32bit validate_rw_ver(const std::string& algo,
SecureVector<byte> msg = decode_hex(str[2]);
SecureVector<byte> sig = decode_hex(str[3]);
+ bool passed = true;
passed = v->verify_message(msg, msg.size(), sig, sig.size());
+ return (passed ? 0 : 1);
#endif
- return (passed ? 0 : 1);
+ return 2;
}
u32bit validate_rw_sig(const std::string& algo,
@@ -364,7 +374,6 @@ u32bit validate_rw_sig(const std::string& algo,
if(str.size() != 6)
throw Exception("Invalid input from pk_valid.dat");
- bool failure = false;
#if defined(BOTAN_HAS_RW)
RW_PrivateKey privkey(rng, to_bigint(str[1]), to_bigint(str[2]),
@@ -376,10 +385,12 @@ u32bit validate_rw_sig(const std::string& algo,
PK_Verifier* v = get_pk_verifier(pubkey, emsa);
PK_Signer* s = get_pk_signer(privkey, emsa);
+ bool failure = false;
validate_signature(v, s, algo, str[3], str[4], str[5], failure);
+ return (failure ? 1 : 0);
#endif
- return (failure ? 1 : 0);
+ return 2;
}
u32bit validate_dsa_sig(const std::string& algo,
@@ -461,7 +472,7 @@ u32bit validate_nr_sig(const std::string& algo,
throw Exception("Invalid input from pk_valid.dat");
-#if defined(BOTAN_HAS_NR)
+#if defined(BOTAN_HAS_NYBERG_RUEPPEL)
DL_Group domain(to_bigint(str[0]), to_bigint(str[1]), to_bigint(str[2]));
NR_PrivateKey privkey(rng, domain, to_bigint(str[4]));
@@ -488,7 +499,7 @@ u32bit validate_dh(const std::string& algo,
throw Exception("Invalid input from pk_valid.dat");
-#if defined(BOTAN_HAS_DH)
+#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
DL_Group domain(to_bigint(str[0]), to_bigint(str[1]));
DH_PrivateKey mykey(rng, domain, to_bigint(str[2]));
@@ -544,7 +555,7 @@ u32bit validate_dlies(const std::string& algo,
validate_encryption(e, d, algo, str[4], empty, str[5], failure);
return (failure ? 1 : 0);
#else
- return 0;
+ return 2;
#endif
}
@@ -595,13 +606,13 @@ void do_pk_keygen_tests(RandomNumberGenerator& rng)
DL_SIG_KEY(DSA_PrivateKey, "dsa/jce/1024");
#endif
-#if defined(BOTAN_HAS_DH)
+#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
DL_KEY(DH_PrivateKey, "modp/ietf/768");
DL_KEY(DH_PrivateKey, "modp/ietf/2048");
DL_KEY(DH_PrivateKey, "dsa/jce/1024");
#endif
-#if defined(BOTAN_HAS_NR)
+#if defined(BOTAN_HAS_NYBERG_RUEPPEL)
DL_SIG_KEY(NR_PrivateKey, "dsa/jce/512");
DL_SIG_KEY(NR_PrivateKey, "dsa/jce/768");
DL_SIG_KEY(NR_PrivateKey, "dsa/jce/1024");
diff --git a/checks/pk_bench.cpp b/checks/pk_bench.cpp
index ac8f5649f..ac470b88a 100644
--- a/checks/pk_bench.cpp
+++ b/checks/pk_bench.cpp
@@ -12,11 +12,11 @@
#include <botan/dsa.h>
#endif
-#if defined(BOTAN_HAS_DH)
+#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
#include <botan/dh.h>
#endif
-#if defined(BOTAN_HAS_NR)
+#if defined(BOTAN_HAS_NYBERG_RUEPPEL)
#include <botan/nr.h>
#endif
@@ -160,7 +160,8 @@ void benchmark_rsa(RandomNumberGenerator& rng,
#if 0
// for profiling
- PKCS8_PrivateKey* pkcs8_key = PKCS8::load_key("rsa/" + to_string(keylen) + ".pem", rng);
+ PKCS8_PrivateKey* pkcs8_key =
+ PKCS8::load_key("rsa/" + to_string(keylen) + ".pem", rng);
RSA_PrivateKey* key_ptr = dynamic_cast<RSA_PrivateKey*>(pkcs8_key);
RSA_PrivateKey key = *key_ptr;
@@ -179,7 +180,8 @@ void benchmark_rsa(RandomNumberGenerator& rng,
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);
+ benchmark_sig_ver(*ver, *sig, verify_timer,
+ sig_timer, rng, 10000, seconds);
}
const std::string rsa_keylen = "RSA " + to_string(keylen);
@@ -247,7 +249,7 @@ void benchmark_dsa_nr(RandomNumberGenerator& rng,
double seconds,
Benchmark_Report& report)
{
-#if defined(BOTAN_HAS_NR) || defined(BOTAN_HAS_DSA)
+#if defined(BOTAN_HAS_NYBERG_RUEPPEL) || defined(BOTAN_HAS_DSA)
const char* domains[] = { "dsa/jce/512",
"dsa/jce/768",
"dsa/jce/1024",
@@ -280,7 +282,8 @@ void benchmark_dsa_nr(RandomNumberGenerator& rng,
std::auto_ptr<PK_Signer> sig(get_pk_signer(key, padding));
std::auto_ptr<PK_Verifier> ver(get_pk_verifier(key, padding));
- benchmark_sig_ver(*ver, *sig, verify_timer, sig_timer, rng, 1000, seconds);
+ benchmark_sig_ver(*ver, *sig, verify_timer,
+ sig_timer, rng, 1000, seconds);
}
const std::string nm = algo_name + "-" + to_string(pbits);
@@ -295,7 +298,7 @@ void benchmark_dh(RandomNumberGenerator& rng,
double seconds,
Benchmark_Report& report)
{
-#ifdef BOTAN_HAS_DH
+#ifdef BOTAN_HAS_DIFFIE_HELLMAN
const char* domains[] = { "modp/ietf/768",
"modp/ietf/1024",
@@ -457,7 +460,7 @@ void bench_pk(RandomNumberGenerator& rng,
if(algo == "All" || algo == "ELG" || algo == "ElGamal")
benchmark_elg(rng, seconds, report);
-#if defined(BOTAN_HAS_NR)
+#if defined(BOTAN_HAS_NYBERG_RUEPPEL)
if(algo == "All" || algo == "NR")
benchmark_dsa_nr<NR_PrivateKey>(rng, seconds, report);
#endif