aboutsummaryrefslogtreecommitdiffstats
path: root/checks
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-03-04 05:03:19 +0000
committerlloyd <[email protected]>2010-03-04 05:03:19 +0000
commit14f73d8df8f6728ab35a0ae39f669665e948b0e8 (patch)
tree7cbecde120585b52d5b5c5428f80bab6ea6b8c05 /checks
parent737dfc9a44103cb3be4a9821f96a30e08d009ac6 (diff)
For each keygen tests, save the file as pem then reload it.
Diffstat (limited to 'checks')
-rw-r--r--checks/pk.cpp107
1 files changed, 80 insertions, 27 deletions
diff --git a/checks/pk.cpp b/checks/pk.cpp
index 4a2005b81..3749b283a 100644
--- a/checks/pk.cpp
+++ b/checks/pk.cpp
@@ -12,6 +12,7 @@
#include <memory>
#include <botan/botan.h>
+#include <botan/oids.h>
#if defined(BOTAN_HAS_RSA)
#include <botan/rsa.h>
@@ -37,6 +38,18 @@
#include <botan/elgamal.h>
#endif
+#if defined(BOTAN_HAS_ECDSA)
+ #include <botan/ecdsa.h>
+#endif
+
+#if defined(BOTAN_HAS_ECDH)
+ #include <botan/ecdh.h>
+#endif
+
+#if defined(BOTAN_HAS_GOST_34_10_2001)
+ #include <botan/gost_3410.h>
+#endif
+
#if defined(BOTAN_HAS_DLIES)
#include <botan/dlies.h>
#include <botan/kdf.h>
@@ -58,12 +71,6 @@ BigInt to_bigint(const std::string& h)
h.length(), BigInt::Hexadecimal);
}
-}
-
-#define DEBUG 0
-
-namespace {
-
void dump_data(const SecureVector<byte>& out,
const SecureVector<byte>& expected)
{
@@ -75,6 +82,33 @@ void dump_data(const SecureVector<byte>& out,
std::cout << "Exp: " << pipe.read_all_as_string(1) << std::endl;
}
+void validate_save_and_load(const Public_Key* public_key,
+ RandomNumberGenerator& rng)
+ {
+ std::string name = public_key->algo_name();
+
+ std::string pem = X509::PEM_encode(*public_key);
+
+ try
+ {
+ DataSource_Memory input(pem);
+ std::auto_ptr<Public_Key> restored(X509::load_key(input));
+
+ if(restored.get() == 0)
+ std::cout << "Could not recover " << name << " key\n";
+ else if(restored->check_key(rng, true) == false)
+ std::cout << "Restored key failed self tests " << name << "\n";
+ }
+ catch(std::exception& e)
+ {
+ std::cout << "Exception during load of " << name
+ << " key: " << e.what() << "\n";
+ std::cout << "PEM was:\n" << pem << "\n";
+ }
+
+ // Check equivalence somehow?
+ }
+
void validate_decryption(PK_Decryptor* d, const std::string& algo,
const SecureVector<byte> ctext,
const SecureVector<byte> ptext,
@@ -212,7 +246,6 @@ u32bit validate_rsa_enc(const std::string& algo,
if(str.size() != 6)
throw std::runtime_error("Invalid input from pk_valid.dat");
-
#if defined(BOTAN_HAS_RSA)
RSA_PrivateKey privkey(rng,
to_bigint(str[1]), to_bigint(str[2]),
@@ -577,24 +610,19 @@ void do_pk_keygen_tests(RandomNumberGenerator& rng)
{
std::cout << "Testing PK key generation: " << std::flush;
-#define DL_SIG_KEY(TYPE, GROUP) \
- { \
- TYPE key(rng, DL_Group(GROUP)); \
- key.check_key(rng, true); \
- std::cout << '.' << std::flush; \
- }
-
-#define DL_ENC_KEY(TYPE, GROUP) \
+#define DL_KEY(TYPE, GROUP) \
{ \
TYPE key(rng, DL_Group(GROUP)); \
key.check_key(rng, true); \
+ validate_save_and_load(&key, rng); \
std::cout << '.' << std::flush; \
}
-#define DL_KEY(TYPE, GROUP) \
+#define EC_KEY(TYPE, GROUP) \
{ \
- TYPE key(rng, DL_Group(GROUP)); \
+ TYPE key(rng, EC_Domain_Params(OIDS::lookup(GROUP))); \
key.check_key(rng, true); \
+ validate_save_and_load(&key, rng); \
std::cout << '.' << std::flush; \
}
@@ -602,6 +630,7 @@ void do_pk_keygen_tests(RandomNumberGenerator& rng)
{
RSA_PrivateKey rsa1024(rng, 1024);
rsa1024.check_key(rng, true);
+ validate_save_and_load(&rsa1024, rng);
std::cout << '.' << std::flush;
}
#endif
@@ -610,14 +639,15 @@ void do_pk_keygen_tests(RandomNumberGenerator& rng)
{
RW_PrivateKey rw1024(rng, 1024);
rw1024.check_key(rng, true);
+ validate_save_and_load(&rw1024, rng);
std::cout << '.' << std::flush;
}
#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");
+ DL_KEY(DSA_PrivateKey, "dsa/jce/512");
+ DL_KEY(DSA_PrivateKey, "dsa/jce/768");
+ DL_KEY(DSA_PrivateKey, "dsa/jce/1024");
#endif
#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
@@ -627,15 +657,38 @@ void do_pk_keygen_tests(RandomNumberGenerator& rng)
#endif
#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");
+ DL_KEY(NR_PrivateKey, "dsa/jce/512");
+ DL_KEY(NR_PrivateKey, "dsa/jce/768");
+ DL_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");
+ DL_KEY(ElGamal_PrivateKey, "modp/ietf/768");
+ DL_KEY(ElGamal_PrivateKey, "modp/ietf/1024");
+ DL_KEY(ElGamal_PrivateKey, "dsa/jce/1024");
+#endif
+
+#if defined(BOTAN_HAS_ECDSA)
+ EC_KEY(ECDSA_PrivateKey, "secp112r1");
+ EC_KEY(ECDSA_PrivateKey, "secp128r1");
+ EC_KEY(ECDSA_PrivateKey, "secp160r1");
+ EC_KEY(ECDSA_PrivateKey, "secp192r1");
+ EC_KEY(ECDSA_PrivateKey, "secp224r1");
+ EC_KEY(ECDSA_PrivateKey, "secp256r1");
+ EC_KEY(ECDSA_PrivateKey, "secp384r1");
+ EC_KEY(ECDSA_PrivateKey, "secp521r1");
+#endif
+
+#if defined(BOTAN_HAS_GOST_34_10_2001)
+ EC_KEY(GOST_3410_PrivateKey, "gost_256A");
+ EC_KEY(GOST_3410_PrivateKey, "secp112r1");
+ EC_KEY(GOST_3410_PrivateKey, "secp128r1");
+ EC_KEY(GOST_3410_PrivateKey, "secp160r1");
+ EC_KEY(GOST_3410_PrivateKey, "secp192r1");
+ EC_KEY(GOST_3410_PrivateKey, "secp224r1");
+ EC_KEY(GOST_3410_PrivateKey, "secp256r1");
+ EC_KEY(GOST_3410_PrivateKey, "secp384r1");
+ //EC_KEY(GOST_3410_PrivateKey, "secp521r1");
#endif
std::cout << std::endl;
@@ -703,7 +756,7 @@ u32bit do_pk_validation_tests(const std::string& filename,
std::vector<std::string> substr = parse(line);
-#if DEBUG
+#if 0
std::cout << "Testing: " << print_algorithm << std::endl;
#endif