aboutsummaryrefslogtreecommitdiffstats
path: root/checks
diff options
context:
space:
mode:
Diffstat (limited to 'checks')
-rw-r--r--checks/pk.cpp139
-rw-r--r--checks/pk_bench.cpp58
-rw-r--r--checks/x509.cpp20
3 files changed, 165 insertions, 52 deletions
diff --git a/checks/pk.cpp b/checks/pk.cpp
index 31c432033..2ebd739d3 100644
--- a/checks/pk.cpp
+++ b/checks/pk.cpp
@@ -6,13 +6,30 @@
#include <memory>
#include <botan/botan.h>
-#include <botan/rsa.h>
-#include <botan/dsa.h>
-#include <botan/dh.h>
-#include <botan/nr.h>
-#include <botan/rw.h>
-#include <botan/elgamal.h>
+#if defined(BOTAN_HAS_RSA)
+ #include <botan/rsa.h>
+#endif
+
+#if defined(BOTAN_HAS_DSA)
+ #include <botan/dsa.h>
+#endif
+
+#if defined(BOTAN_HAS_DH)
+ #include <botan/dh.h>
+#endif
+
+#if defined(BOTAN_HAS_RN)
+ #include <botan/nr.h>
+#endif
+
+#if defined(BOTAN_HAS_RW)
+ #include <botan/rw.h>
+#endif
+
+#if defined(BOTAN_HAS_ELGAMAL)
+ #include <botan/elgamal.h>
+#endif
#if defined(BOTAN_HAS_DLIES)
#include <botan/dlies.h>
@@ -146,6 +163,9 @@ 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;
if(str.size() == 5) pass = str[4];
strip_newlines(pass); /* it will have a newline thanks to the messy
@@ -154,7 +174,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, rng, pass);
+ std::auto_ptr<Private_Key> privkey(PKCS8::load_key(keysource, rng, pass));
RSA_PrivateKey* rsapriv = dynamic_cast<RSA_PrivateKey*>(privkey);
if(!rsapriv)
@@ -167,9 +187,9 @@ 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);
- delete privkey;
+#endif
+
return (failure ? 1 : 0);
}
@@ -180,6 +200,9 @@ 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,
to_bigint(str[1]), to_bigint(str[2]),
to_bigint(str[0]));
@@ -191,8 +214,9 @@ 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);
+#endif
+
return (failure ? 1 : 0);
}
@@ -203,6 +227,9 @@ 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]));
ElGamal_PrivateKey privkey(rng, domain, to_bigint(str[2]));
ElGamal_PublicKey pubkey = privkey;
@@ -210,7 +237,6 @@ u32bit validate_elg_enc(const std::string& algo,
std::string eme = algo.substr(8, std::string::npos);
PK_Decryptor* d = get_pk_decryptor(privkey, eme);
- bool failure = false;
if(str.size() == 7)
{
@@ -220,6 +246,7 @@ u32bit validate_elg_enc(const std::string& algo,
else
validate_decryption(d, algo, decode_hex(str[5]),
decode_hex(str[4]), failure);
+#endif
return (failure ? 1 : 0);
}
@@ -231,6 +258,9 @@ 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,
to_bigint(str[1]), to_bigint(str[2]),
to_bigint(str[0]));
@@ -241,9 +271,9 @@ 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);
+#endif
+
return (failure ? 1 : 0);
}
@@ -253,18 +283,20 @@ 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]));
std::string emsa = algo.substr(6, std::string::npos);
- PK_Verifier* v = get_pk_verifier(key, emsa);
+ std::auto_ptr<PK_Verifier> v(get_pk_verifier(key, emsa));
SecureVector<byte> msg = decode_hex(str[2]);
SecureVector<byte> sig = decode_hex(str[3]);
- bool passed = v->verify_message(msg, msg.size(), sig, sig.size());
-
- delete v;
+ passed = v->verify_message(msg, msg.size(), sig, sig.size());
+#endif
return (passed ? 0 : 1);
}
@@ -275,10 +307,13 @@ 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());
- Public_Key* key = X509::load_key(keysource);
+ std::auto_ptr<Public_Key> key(X509::load_key(keysource));
RSA_PublicKey* rsakey = dynamic_cast<RSA_PublicKey*>(key);
@@ -287,15 +322,13 @@ u32bit validate_rsa_ver_x509(const std::string& algo,
std::string emsa = algo.substr(11, std::string::npos);
- PK_Verifier* v = get_pk_verifier(*rsakey, emsa);
+ std::auto_ptr<PK_Verifier> v(get_pk_verifier(*rsakey, emsa));
SecureVector<byte> msg = decode_hex(str[1]);
SecureVector<byte> sig = decode_hex(str[2]);
- bool passed = v->verify_message(msg, msg.size(), sig, sig.size());
-
- delete v;
- delete key;
+ passed = v->verify_message(msg, msg.size(), sig, sig.size());
+#endif
return (passed ? 0 : 1);
}
@@ -306,18 +339,20 @@ 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]));
std::string emsa = algo.substr(5, std::string::npos);
- PK_Verifier* v = get_pk_verifier(key, emsa);
+ std::auto_ptr<PK_Verifier> v(get_pk_verifier(key, emsa));
SecureVector<byte> msg = decode_hex(str[2]);
SecureVector<byte> sig = decode_hex(str[3]);
- bool passed = v->verify_message(msg, msg.size(), sig, sig.size());
-
- delete v;
+ passed = v->verify_message(msg, msg.size(), sig, sig.size());
+#endif
return (passed ? 0 : 1);
}
@@ -329,6 +364,9 @@ 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]),
to_bigint(str[0]));
RW_PublicKey pubkey = privkey;
@@ -338,8 +376,9 @@ 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);
+#endif
+
return (failure ? 1 : 0);
}
@@ -355,10 +394,13 @@ u32bit validate_dsa_sig(const std::string& algo,
strip_newlines(pass); /* it will have a newline thanks to the messy
decoding method we use */
+ bool failure = false;
+
+#if defined(BOTAN_HAS_DSA)
DataSource_Memory keysource(reinterpret_cast<const byte*>(str[0].c_str()),
str[0].length());
- Private_Key* privkey = PKCS8::load_key(keysource, rng, pass);
+ std::auto_ptr<Private_Key> privkey(PKCS8::load_key(keysource, rng, pass));
DSA_PrivateKey* dsapriv = dynamic_cast<DSA_PrivateKey*>(privkey);
if(!dsapriv)
@@ -371,9 +413,9 @@ u32bit validate_dsa_sig(const std::string& algo,
PK_Verifier* v = get_pk_verifier(*dsapub, emsa);
PK_Signer* s = get_pk_signer(*dsapriv, emsa);
- bool failure = false;
validate_signature(v, s, algo, str[1], str[2], str[3], failure);
delete privkey;
+#endif
return (failure ? 1 : 0);
}
@@ -387,7 +429,10 @@ u32bit validate_dsa_ver(const std::string& algo,
DataSource_Memory keysource(reinterpret_cast<const byte*>(str[0].c_str()),
str[0].length());
- Public_Key* key = X509::load_key(keysource);
+ bool passed = true;
+
+#if defined(BOTAN_HAS_DSA)
+ std::auto_ptr<Public_Key> key(X509::load_key(keysource));
DSA_PublicKey* dsakey = dynamic_cast<DSA_PublicKey*>(key);
@@ -396,15 +441,14 @@ u32bit validate_dsa_ver(const std::string& algo,
std::string emsa = algo.substr(7, std::string::npos);
- PK_Verifier* v = get_pk_verifier(*dsakey, emsa);
+ std::auto_ptr<PK_Verifier> v(get_pk_verifier(*dsakey, emsa));
SecureVector<byte> msg = decode_hex(str[1]);
SecureVector<byte> sig = decode_hex(str[2]);
v->set_input_format(DER_SEQUENCE);
- bool passed = v->verify_message(msg, msg.size(), sig, sig.size());
- delete v;
- delete key;
+ passed = v->verify_message(msg, msg.size(), sig, sig.size());
+#endif
return (passed ? 0 : 1);
}
@@ -416,6 +460,9 @@ u32bit validate_nr_sig(const std::string& algo,
if(str.size() != 8)
throw Exception("Invalid input from pk_valid.dat");
+ bool failure = false;
+
+#if defined(BOTAN_HAS_NR)
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;
@@ -425,8 +472,9 @@ u32bit validate_nr_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[5], str[6], str[7], failure);
+#endif
+
return (failure ? 1 : 0);
}
@@ -437,6 +485,9 @@ u32bit validate_dh(const std::string& algo,
if(str.size() != 5 && str.size() != 6)
throw Exception("Invalid input from pk_valid.dat");
+ bool failure = false;
+
+#if defined(BOTAN_HAS_DH)
DL_Group domain(to_bigint(str[0]), to_bigint(str[1]));
DH_PrivateKey mykey(rng, domain, to_bigint(str[2]));
@@ -450,9 +501,10 @@ u32bit validate_dh(const std::string& algo,
PK_Key_Agreement* kas = get_pk_kas(mykey, kdf);
- bool failure = false;
validate_kas(kas, algo, otherkey.public_value(),
str[4], keylen, failure);
+#endif
+
return (failure ? 1 : 0);
}
@@ -526,24 +578,37 @@ void do_pk_keygen_tests(RandomNumberGenerator& rng)
std::cout << '.' << std::flush; \
}
+#if defined(BOTAN_HAS_RSA)
IF_SIG_KEY(RSA_PrivateKey, 1024);
+#endif
+
+#if defined(BOTAN_HAS_RW)
IF_SIG_KEY(RW_PrivateKey, 1024);
+#endif
+#if defined(BOTAN_HAS_DSA)
DL_SIG_KEY(DSA_PrivateKey, "dsa/jce/512");
DL_SIG_KEY(DSA_PrivateKey, "dsa/jce/768");
DL_SIG_KEY(DSA_PrivateKey, "dsa/jce/1024");
+#endif
+#if defined(BOTAN_HAS_DH)
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)
DL_SIG_KEY(NR_PrivateKey, "dsa/jce/512");
DL_SIG_KEY(NR_PrivateKey, "dsa/jce/768");
DL_SIG_KEY(NR_PrivateKey, "dsa/jce/1024");
+#endif
+#if defined(BOTAN_HAS_ELGAMAL)
DL_ENC_KEY(ElGamal_PrivateKey, "modp/ietf/768");
DL_ENC_KEY(ElGamal_PrivateKey, "modp/ietf/1024");
DL_ENC_KEY(ElGamal_PrivateKey, "dsa/jce/1024");
+#endif
std::cout << std::endl;
}
diff --git a/checks/pk_bench.cpp b/checks/pk_bench.cpp
index 9701827dd..0ea381795 100644
--- a/checks/pk_bench.cpp
+++ b/checks/pk_bench.cpp
@@ -1,15 +1,36 @@
-#include <botan/dsa.h>
-#include <botan/rsa.h>
-#include <botan/dh.h>
-#include <botan/nr.h>
-#include <botan/rw.h>
-#include <botan/elgamal.h>
-#include <botan/parsing.h>
-
#include <botan/pkcs8.h>
#include <botan/mem_ops.h>
#include <botan/look_pk.h>
#include <botan/libstate.h>
+#include <botan/parsing.h>
+
+#if defined(BOTAN_HAS_RSA)
+ #include <botan/rsa.h>
+#endif
+
+#if defined(BOTAN_HAS_DSA)
+ #include <botan/dsa.h>
+#endif
+
+#if defined(BOTAN_HAS_DH)
+ #include <botan/dh.h>
+#endif
+
+#if defined(BOTAN_HAS_RN)
+ #include <botan/nr.h>
+#endif
+
+#if defined(BOTAN_HAS_RW)
+ #include <botan/rw.h>
+#endif
+
+#if defined(BOTAN_HAS_ELGAMAL)
+ #include <botan/elgamal.h>
+#endif
+
+#if defined(BOTAN_HAS_DLIES)
+ #include <botan/dlies.h>
+#endif
using namespace Botan;
@@ -121,6 +142,8 @@ void benchmark_rsa(RandomNumberGenerator& rng,
double seconds,
Benchmark_Report& report)
{
+#if defined(BOTAN_HAS_RSA)
+
for(size_t keylen = 1024; keylen <= 4096; keylen += 1024)
{
Timer keygen_timer("keygen");
@@ -175,12 +198,16 @@ void benchmark_rsa(RandomNumberGenerator& rng,
std::cout << e.what() << "\n";
}
}
+
+#endif
}
void benchmark_rw(RandomNumberGenerator& rng,
double seconds,
Benchmark_Report& report)
{
+#if defined(BOTAN_HAS_RW)
+
const u32bit keylens[] = { 512, 1024, 2048, 3072, 4096, 6144, 8192, 0 };
for(size_t j = 0; keylens[j]; j++)
@@ -211,6 +238,8 @@ void benchmark_rw(RandomNumberGenerator& rng,
report.report(nm, verify_timer);
report.report(nm, sig_timer);
}
+
+#endif
}
template<typename PRIV_KEY_TYPE>
@@ -218,6 +247,7 @@ void benchmark_dsa_nr(RandomNumberGenerator& rng,
double seconds,
Benchmark_Report& report)
{
+#if defined(BOTAN_HAS_NR) || defined(BOTAN_HAS_DSA)
const char* domains[] = { "dsa/jce/512",
"dsa/jce/768",
"dsa/jce/1024",
@@ -258,12 +288,15 @@ void benchmark_dsa_nr(RandomNumberGenerator& rng,
report.report(nm, verify_timer);
report.report(nm, sig_timer);
}
+#endif
}
void benchmark_dh(RandomNumberGenerator& rng,
double seconds,
Benchmark_Report& report)
{
+#ifdef BOTAN_HAS_DH
+
const char* domains[] = { "modp/ietf/768",
"modp/ietf/1024",
"modp/ietf/2048",
@@ -321,12 +354,16 @@ void benchmark_dh(RandomNumberGenerator& rng,
report.report(nm, keygen_timer);
report.report(nm, kex_timer);
}
+
+#endif
}
void benchmark_elg(RandomNumberGenerator& rng,
double seconds,
Benchmark_Report& report)
{
+#ifdef BOTAN_HAS_ELGAMAL
+
const char* domains[] = { "modp/ietf/768",
"modp/ietf/1024",
"modp/ietf/2048",
@@ -368,6 +405,7 @@ void benchmark_elg(RandomNumberGenerator& rng,
report.report(nm, enc_timer);
report.report(nm, dec_timer);
}
+#endif
}
}
@@ -408,8 +446,10 @@ void bench_pk(RandomNumberGenerator& rng,
if(algo == "All" || algo == "RSA")
benchmark_rsa(rng, seconds, report);
+#if defined(BOTAN_HAS_DSA)
if(algo == "All" || algo == "DSA")
benchmark_dsa_nr<DSA_PrivateKey>(rng, seconds, report);
+#endif
if(algo == "All" || algo == "DH")
benchmark_dh(rng, seconds, report);
@@ -417,8 +457,10 @@ void bench_pk(RandomNumberGenerator& rng,
if(algo == "All" || algo == "ELG" || algo == "ElGamal")
benchmark_elg(rng, seconds, report);
+#if defined(BOTAN_HAS_NR)
if(algo == "All" || algo == "NR")
benchmark_dsa_nr<NR_PrivateKey>(rng, seconds, report);
+#endif
if(algo == "All" || algo == "RW")
benchmark_rw(rng, seconds, report);
diff --git a/checks/x509.cpp b/checks/x509.cpp
index 5f5c6b1fa..d3fbc2bd9 100644
--- a/checks/x509.cpp
+++ b/checks/x509.cpp
@@ -1,13 +1,19 @@
#include <botan/filters.h>
-#include <botan/rsa.h>
-#include <botan/dsa.h>
+
+#if defined(BOTAN_HAS_RSA)
+ #include <botan/rsa.h>
+#endif
+
+#if defined(BOTAN_HAS_DSA)
+ #include <botan/dsa.h>
+#endif
#ifdef BOTAN_HAS_X509
-#include <botan/x509self.h>
-#include <botan/x509stor.h>
-#include <botan/x509_ca.h>
-#include <botan/pkcs10.h>
+ #include <botan/x509self.h>
+ #include <botan/x509stor.h>
+ #include <botan/x509_ca.h>
+ #include <botan/pkcs10.h>
#endif
using namespace Botan;
@@ -18,7 +24,7 @@ using namespace Botan;
#include "validate.h"
#include "common.h"
-#ifdef BOTAN_HAS_X509
+#if defined(BOTAN_HAS_X509) && defined(BOTAN_HAS_RSA) && defined(BOTAN_HAS_DSA)
namespace {