diff options
-rw-r--r-- | checks/pk.cpp | 65 | ||||
-rw-r--r-- | checks/pk_bench.cpp | 19 | ||||
-rw-r--r-- | src/build-data/cc/gcc | 4 | ||||
-rw-r--r-- | src/core/libstate/eng_def.h | 13 | ||||
-rw-r--r-- | src/core/libstate/engine.cpp | 10 | ||||
-rw-r--r-- | src/core/libstate/engine.h | 26 | ||||
-rw-r--r-- | src/pubkey/dh/info.txt | 4 | ||||
-rw-r--r-- | src/pubkey/nr/info.txt | 2 | ||||
-rw-r--r-- | src/pubkey/pubkey/pk_algs.cpp | 12 |
9 files changed, 102 insertions, 53 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 diff --git a/src/build-data/cc/gcc b/src/build-data/cc/gcc index 4194892a7..bb0849c51 100644 --- a/src/build-data/cc/gcc +++ b/src/build-data/cc/gcc @@ -9,8 +9,8 @@ add_lib_dir_option "-L" add_lib_option "-l" lang_flags "-D_REENTRANT -ansi -Wno-long-long" -warning_flags "-W -Wall" -#warning_flags "-Werror -Wextra -Wall -Wstrict-aliasing -Wstrict-overflow=5 -Wcast-align -Wmissing-declarations" +#warning_flags "-W -Wall" +warning_flags "-Werror -Wextra -Wall -Wstrict-aliasing -Wstrict-overflow=5 -Wcast-align -Wmissing-declarations" lib_opt_flags "-O2 -finline-functions" check_opt_flags "-O2" diff --git a/src/core/libstate/eng_def.h b/src/core/libstate/eng_def.h index 7d7ecce58..66cb774d2 100644 --- a/src/core/libstate/eng_def.h +++ b/src/core/libstate/eng_def.h @@ -16,16 +16,27 @@ namespace Botan { class BOTAN_DLL Default_Engine : public Engine { public: +#if defined(BOTAN_HAS_IF_PUBLIC_KEY_FAMILY) IF_Operation* if_op(const BigInt&, const BigInt&, const BigInt&, const BigInt&, const BigInt&, const BigInt&, const BigInt&, const BigInt&) const; +#endif + +#if defined(BOTAN_HAS_DSA) DSA_Operation* dsa_op(const DL_Group&, const BigInt&, const BigInt&) const; +#endif + +#if defined(BOTAN_HAS_NYBERG_RUEPPEL) NR_Operation* nr_op(const DL_Group&, const BigInt&, const BigInt&) const; +#endif + +#if defined(BOTAN_HAS_ELGAMAL) ELG_Operation* elg_op(const DL_Group&, const BigInt&, const BigInt&) const; +#endif -#if defined(BOTAN_HAS_DH) +#if defined(BOTAN_HAS_DIFFIE_HELLMAN) DH_Operation* dh_op(const DL_Group&, const BigInt&) const; #endif diff --git a/src/core/libstate/engine.cpp b/src/core/libstate/engine.cpp index 13ab63193..4f58fb040 100644 --- a/src/core/libstate/engine.cpp +++ b/src/core/libstate/engine.cpp @@ -13,6 +13,7 @@ namespace Botan { namespace Engine_Core { +#if defined(BOTAN_HAS_IF_PUBLIC_KEY_FAMILY) /************************************************* * Acquire an IF op * *************************************************/ @@ -31,7 +32,9 @@ IF_Operation* if_op(const BigInt& e, const BigInt& n, const BigInt& d, throw Lookup_Error("Engine_Core::if_op: Unable to find a working engine"); } +#endif +#if defined(BOTAN_HAS_DSA) /************************************************* * Acquire a DSA op * *************************************************/ @@ -48,7 +51,9 @@ DSA_Operation* dsa_op(const DL_Group& group, const BigInt& y, const BigInt& x) throw Lookup_Error("Engine_Core::dsa_op: Unable to find a working engine"); } +#endif +#if defined(BOTAN_HAS_NYBERG_RUEPPEL) /************************************************* * Acquire a NR op * *************************************************/ @@ -65,7 +70,9 @@ NR_Operation* nr_op(const DL_Group& group, const BigInt& y, const BigInt& x) throw Lookup_Error("Engine_Core::nr_op: Unable to find a working engine"); } +#endif +#if defined(BOTAN_HAS_ELGAMAL) /************************************************* * Acquire an ElGamal op * *************************************************/ @@ -82,8 +89,9 @@ ELG_Operation* elg_op(const DL_Group& group, const BigInt& y, const BigInt& x) throw Lookup_Error("Engine_Core::elg_op: Unable to find a working engine"); } +#endif -#if defined(BOTAN_HAS_DH) +#if defined(BOTAN_HAS_DIFFIE_HELLMAN) /************************************************* * Acquire a DH op * *************************************************/ diff --git a/src/core/libstate/engine.h b/src/core/libstate/engine.h index 72f5b28ca..bf33fa24d 100644 --- a/src/core/libstate/engine.h +++ b/src/core/libstate/engine.h @@ -20,11 +20,11 @@ #include <botan/dsa_op.h> #endif -#if defined(BOTAN_HAS_DH) +#if defined(BOTAN_HAS_DIFFIE_HELLMAN) #include <botan/dh_op.h> #endif -#if defined(BOTAN_HAS_NR) +#if defined(BOTAN_HAS_NYBERG_RUEPPEL) #include <botan/nr_op.h> #endif @@ -32,7 +32,6 @@ #include <botan/elg_op.h> #endif - #if defined(BOTAN_HAS_ECDSA) #include <botan/ecc_op.h> #endif @@ -57,24 +56,32 @@ class BOTAN_DLL Engine virtual ~Algorithm_Cache() {} }; +#if defined(BOTAN_HAS_IF_PUBLIC_KEY_FAMILY) virtual IF_Operation* if_op(const BigInt&, const BigInt&, const BigInt&, const BigInt&, const BigInt&, const BigInt&, const BigInt&, const BigInt&) const { return 0; } +#endif +#if defined(BOTAN_HAS_DSA) virtual DSA_Operation* dsa_op(const DL_Group&, const BigInt&, const BigInt&) const { return 0; } +#endif +#if defined(BOTAN_HAS_NYBERG_RUEPPEL) virtual NR_Operation* nr_op(const DL_Group&, const BigInt&, const BigInt&) const { return 0; } +#endif +#if defined(BOTAN_HAS_ELGAMAL) virtual ELG_Operation* elg_op(const DL_Group&, const BigInt&, const BigInt&) const { return 0; } +#endif -#if defined(BOTAN_HAS_DH) +#if defined(BOTAN_HAS_DIFFIE_HELLMAN) virtual DH_Operation* dh_op(const DL_Group&, const BigInt&) const { return 0; } #endif @@ -154,16 +161,25 @@ namespace Engine_Core { *************************************************/ Modular_Exponentiator* mod_exp(const BigInt&, Power_Mod::Usage_Hints); +#if defined(BOTAN_HAS_IF_PUBLIC_KEY_FAMILY) IF_Operation* if_op(const BigInt&, const BigInt&, const BigInt&, const BigInt&, const BigInt&, const BigInt&, const BigInt&, const BigInt&); +#endif +#if defined(BOTAN_HAS_DSA) DSA_Operation* dsa_op(const DL_Group&, const BigInt&, const BigInt&); +#endif + +#if defined(BOTAN_HAS_NYBERG_RUEPPEL) NR_Operation* nr_op(const DL_Group&, const BigInt&, const BigInt&); +#endif +#if defined(BOTAN_HAS_ELGAMAL) ELG_Operation* elg_op(const DL_Group&, const BigInt&, const BigInt&); +#endif -#if defined(BOTAN_HAS_DH) +#if defined(BOTAN_HAS_DIFFIE_HELLMAN) DH_Operation* dh_op(const DL_Group&, const BigInt&); #endif diff --git a/src/pubkey/dh/info.txt b/src/pubkey/dh/info.txt index a54188c57..7c38b027e 100644 --- a/src/pubkey/dh/info.txt +++ b/src/pubkey/dh/info.txt @@ -1,6 +1,6 @@ -realname "DH" +realname "Diffie-Hellman Key Agreement" -define DH +define DIFFIE_HELLMAN load_on auto diff --git a/src/pubkey/nr/info.txt b/src/pubkey/nr/info.txt index b574af0e7..6434d4385 100644 --- a/src/pubkey/nr/info.txt +++ b/src/pubkey/nr/info.txt @@ -1,6 +1,6 @@ realname "Nyberg-Rueppel" -define NR +define NYBERG_RUEPPEL load_on auto diff --git a/src/pubkey/pubkey/pk_algs.cpp b/src/pubkey/pubkey/pk_algs.cpp index 3c1b81ba9..c1fc569a0 100644 --- a/src/pubkey/pubkey/pk_algs.cpp +++ b/src/pubkey/pubkey/pk_algs.cpp @@ -13,7 +13,7 @@ #include <botan/dsa.h> #endif -#ifdef BOTAN_HAS_DH +#ifdef BOTAN_HAS_DIFFIE_HELLMAN #include <botan/dh.h> #endif @@ -21,7 +21,7 @@ #include <botan/ec.h> #endif -#ifdef BOTAN_HAS_NR +#ifdef BOTAN_HAS_NYBERG_RUEPPEL #include <botan/nr.h> #endif @@ -48,11 +48,11 @@ Public_Key* get_public_key(const std::string& alg_name) if(alg_name == "DSA") return new DSA_PublicKey; #endif -#if defined(BOTAN_HAS_DH) +#if defined(BOTAN_HAS_DIFFIE_HELLMAN) if(alg_name == "DH") return new DH_PublicKey; #endif -#if defined(BOTAN_HAS_NR) +#if defined(BOTAN_HAS_NYBERG_RUEPPEL) if(alg_name == "NR") return new NR_PublicKey; #endif @@ -84,11 +84,11 @@ Private_Key* get_private_key(const std::string& alg_name) if(alg_name == "DSA") return new DSA_PrivateKey; #endif -#if defined(BOTAN_HAS_DH) +#if defined(BOTAN_HAS_DIFFIE_HELLMAN) if(alg_name == "DH") return new DH_PrivateKey; #endif -#if defined(BOTAN_HAS_NR) +#if defined(BOTAN_HAS_NYBERG_RUEPPEL) if(alg_name == "NR") return new NR_PrivateKey; #endif |