diff options
author | lloyd <[email protected]> | 2008-06-20 10:28:14 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-06-20 10:28:14 +0000 |
commit | 3b28d92a8a90f27f3da55db7afb47ea23e02cfc4 (patch) | |
tree | b5d752cc2c3c21e9dec8a05c5204ad4c6131bde8 | |
parent | 655f3d4c389dbcb1e23c2ba425ccfd85234f6fce (diff) |
Fix remaining -Wmissing-declarations warnings in self-test/benchmark code
-rw-r--r-- | checks/pk.cpp | 256 | ||||
-rw-r--r-- | checks/pk_bench.cpp | 5 | ||||
-rw-r--r-- | checks/validate.h | 1 | ||||
-rw-r--r-- | checks/x509.cpp | 2 |
4 files changed, 129 insertions, 135 deletions
diff --git a/checks/pk.cpp b/checks/pk.cpp index 90b9e1b5d..12b675430 100644 --- a/checks/pk.cpp +++ b/checks/pk.cpp @@ -22,6 +22,7 @@ using namespace Botan; #include "common.h" +#include "validate.h" static BigInt to_bigint(const std::string& h) { @@ -31,141 +32,7 @@ static BigInt to_bigint(const std::string& h) #define DEBUG 0 -void do_pk_keygen_tests(); -extern void do_x509_tests(); - -u32bit validate_dsa_sig(const std::string&, const std::vector<std::string>&); -u32bit validate_dsa_ver(const std::string&, const std::vector<std::string>&); - -u32bit validate_rsa_enc(const std::string&, const std::vector<std::string>&); -u32bit validate_rsa_enc_pkcs8(const std::string&, - const std::vector<std::string>&); -u32bit validate_rsa_sig(const std::string&, const std::vector<std::string>&); -u32bit validate_rsa_ver(const std::string&, const std::vector<std::string>&); -u32bit validate_rsa_ver_x509(const std::string&, - const std::vector<std::string>&); -u32bit validate_rw_ver(const std::string&, const std::vector<std::string>&); -u32bit validate_rw_sig(const std::string&, const std::vector<std::string>&); -u32bit validate_nr_sig(const std::string&, const std::vector<std::string>&); -u32bit validate_elg_enc(const std::string&, const std::vector<std::string>&); -u32bit validate_dh(const std::string&, const std::vector<std::string>&); -u32bit validate_dlies(const std::string&, const std::vector<std::string>&); - -u32bit do_pk_validation_tests(const std::string& filename) - { - std::ifstream test_data(filename.c_str()); - - if(!test_data) - throw Botan::Stream_IO_Error("Couldn't open test file " + filename); - - u32bit errors = 0, alg_count = 0; - std::string algorithm, print_algorithm; - - while(!test_data.eof()) - { - if(test_data.bad() || test_data.fail()) - throw Botan::Stream_IO_Error("File I/O error reading from " + - filename); - - std::string line; - std::getline(test_data, line); - - strip_comments(line); - if(line.size() == 0) continue; - - // Do line continuation - while(line[line.size()-1] == '\\' && !test_data.eof()) - { - line.replace(line.size()-1, 1, ""); - std::string nextline; - std::getline(test_data, nextline); - strip_comments(nextline); - if(nextline.size() == 0) continue; - line.push_back('\n'); - line += nextline; - } - - if(line[0] == '[' && line[line.size() - 1] == ']') - { - std::string old_algo = print_algorithm; - algorithm = line.substr(1, line.size() - 2); - print_algorithm = algorithm; - if(print_algorithm.find("_PKCS8") != std::string::npos) - print_algorithm.replace(print_algorithm.find("_PKCS8"), 6, ""); - if(print_algorithm.find("_X509") != std::string::npos) - print_algorithm.replace(print_algorithm.find("_X509"), 5, ""); - if(print_algorithm.find("_VA") != std::string::npos) - print_algorithm.replace(print_algorithm.find("_VA"), 3, ""); - - if(old_algo != print_algorithm && old_algo != "") - { - std::cout << std::endl; - alg_count = 0; - } - - if(old_algo != print_algorithm) - std::cout << "Testing " << print_algorithm << ": "; - continue; - } - - std::cout << '.'; - std::cout.flush(); - - std::vector<std::string> substr = parse(line); - -#if DEBUG - std::cout << "Testing: " << print_algorithm << std::endl; -#endif - - u32bit new_errors = 0; - - if(algorithm.find("DSA/") != std::string::npos) - new_errors = validate_dsa_sig(algorithm, substr); - else if(algorithm.find("DSA_VA/") != std::string::npos) - new_errors = validate_dsa_ver(algorithm, substr); - - else if(algorithm.find("RSAES_PKCS8/") != std::string::npos) - new_errors = validate_rsa_enc_pkcs8(algorithm, substr); - else if(algorithm.find("RSAVA_X509/") != std::string::npos) - new_errors = validate_rsa_ver_x509(algorithm, substr); - - else if(algorithm.find("RSAES/") != std::string::npos) - new_errors = validate_rsa_enc(algorithm, substr); - else if(algorithm.find("RSASSA/") != std::string::npos) - new_errors = validate_rsa_sig(algorithm, substr); - else if(algorithm.find("RSAVA/") != std::string::npos) - new_errors = validate_rsa_ver(algorithm, substr); - else if(algorithm.find("RWVA/") != std::string::npos) - new_errors = validate_rw_ver(algorithm, substr); - else if(algorithm.find("RW/") != std::string::npos) - new_errors = validate_rw_sig(algorithm, substr); - else if(algorithm.find("NR/") != std::string::npos) - new_errors = validate_nr_sig(algorithm, substr); - else if(algorithm.find("ElGamal/") != std::string::npos) - new_errors = validate_elg_enc(algorithm, substr); - else if(algorithm.find("DH/") != std::string::npos) - new_errors = validate_dh(algorithm, substr); - else if(algorithm.find("DLIES/") != std::string::npos) - new_errors = validate_dlies(algorithm, substr); - else - std::cout << "WARNING: Unknown PK algorithm " - << algorithm << std::endl; - - alg_count++; - errors += new_errors; - - if(new_errors) - std::cout << "ERROR: \"" << algorithm << "\" failed test #" - << std::dec << alg_count << std::endl; - } - - std::cout << std::endl; - - do_pk_keygen_tests(); - do_x509_tests(); - - return errors; - } +namespace { void dump_data(const SecureVector<byte>& out, const SecureVector<byte>& expected) @@ -661,3 +528,122 @@ void do_pk_keygen_tests() std::cout << std::endl; } + +} + +u32bit do_pk_validation_tests(const std::string& filename) + { + std::ifstream test_data(filename.c_str()); + + if(!test_data) + throw Botan::Stream_IO_Error("Couldn't open test file " + filename); + + u32bit errors = 0, alg_count = 0; + std::string algorithm, print_algorithm; + + while(!test_data.eof()) + { + if(test_data.bad() || test_data.fail()) + throw Botan::Stream_IO_Error("File I/O error reading from " + + filename); + + std::string line; + std::getline(test_data, line); + + strip_comments(line); + if(line.size() == 0) continue; + + // Do line continuation + while(line[line.size()-1] == '\\' && !test_data.eof()) + { + line.replace(line.size()-1, 1, ""); + std::string nextline; + std::getline(test_data, nextline); + strip_comments(nextline); + if(nextline.size() == 0) continue; + line.push_back('\n'); + line += nextline; + } + + if(line[0] == '[' && line[line.size() - 1] == ']') + { + std::string old_algo = print_algorithm; + algorithm = line.substr(1, line.size() - 2); + print_algorithm = algorithm; + if(print_algorithm.find("_PKCS8") != std::string::npos) + print_algorithm.replace(print_algorithm.find("_PKCS8"), 6, ""); + if(print_algorithm.find("_X509") != std::string::npos) + print_algorithm.replace(print_algorithm.find("_X509"), 5, ""); + if(print_algorithm.find("_VA") != std::string::npos) + print_algorithm.replace(print_algorithm.find("_VA"), 3, ""); + + if(old_algo != print_algorithm && old_algo != "") + { + std::cout << std::endl; + alg_count = 0; + } + + if(old_algo != print_algorithm) + std::cout << "Testing " << print_algorithm << ": "; + continue; + } + + std::cout << '.'; + std::cout.flush(); + + std::vector<std::string> substr = parse(line); + +#if DEBUG + std::cout << "Testing: " << print_algorithm << std::endl; +#endif + + u32bit new_errors = 0; + + if(algorithm.find("DSA/") != std::string::npos) + new_errors = validate_dsa_sig(algorithm, substr); + else if(algorithm.find("DSA_VA/") != std::string::npos) + new_errors = validate_dsa_ver(algorithm, substr); + + else if(algorithm.find("RSAES_PKCS8/") != std::string::npos) + new_errors = validate_rsa_enc_pkcs8(algorithm, substr); + else if(algorithm.find("RSAVA_X509/") != std::string::npos) + new_errors = validate_rsa_ver_x509(algorithm, substr); + + else if(algorithm.find("RSAES/") != std::string::npos) + new_errors = validate_rsa_enc(algorithm, substr); + else if(algorithm.find("RSASSA/") != std::string::npos) + new_errors = validate_rsa_sig(algorithm, substr); + else if(algorithm.find("RSAVA/") != std::string::npos) + new_errors = validate_rsa_ver(algorithm, substr); + else if(algorithm.find("RWVA/") != std::string::npos) + new_errors = validate_rw_ver(algorithm, substr); + else if(algorithm.find("RW/") != std::string::npos) + new_errors = validate_rw_sig(algorithm, substr); + else if(algorithm.find("NR/") != std::string::npos) + new_errors = validate_nr_sig(algorithm, substr); + else if(algorithm.find("ElGamal/") != std::string::npos) + new_errors = validate_elg_enc(algorithm, substr); + else if(algorithm.find("DH/") != std::string::npos) + new_errors = validate_dh(algorithm, substr); + else if(algorithm.find("DLIES/") != std::string::npos) + new_errors = validate_dlies(algorithm, substr); + else + std::cout << "WARNING: Unknown PK algorithm " + << algorithm << std::endl; + + alg_count++; + errors += new_errors; + + if(new_errors) + std::cout << "ERROR: \"" << algorithm << "\" failed test #" + << std::dec << alg_count << std::endl; + } + + std::cout << std::endl; + + do_pk_keygen_tests(); + do_x509_tests(); + + return errors; + } + diff --git a/checks/pk_bench.cpp b/checks/pk_bench.cpp index e6ab90153..f3f873467 100644 --- a/checks/pk_bench.cpp +++ b/checks/pk_bench.cpp @@ -13,6 +13,7 @@ using namespace Botan; #include "common.h" +#include "bench.h" #include <iostream> #include <fstream> @@ -177,6 +178,8 @@ void bench_pk(const std::string& algo, bool html, double seconds) } } +namespace { + void print_result(bool html, u32bit runs, u64bit clocks_used, const std::string& algo_name, const std::string& op) { @@ -209,6 +212,8 @@ void print_result(bool html, u32bit runs, u64bit clocks_used, } } +} + void bench_enc(PK_Encryptor* enc, const std::string& algo_name, double seconds, bool html) { diff --git a/checks/validate.h b/checks/validate.h index c14fc56d9..c411ff702 100644 --- a/checks/validate.h +++ b/checks/validate.h @@ -5,5 +5,6 @@ u32bit do_validation_tests(const std::string&, bool = true); u32bit do_bigint_tests(const std::string&); u32bit do_pk_validation_tests(const std::string&); +void do_x509_tests(); #endif diff --git a/checks/x509.cpp b/checks/x509.cpp index a544e907b..40966bf01 100644 --- a/checks/x509.cpp +++ b/checks/x509.cpp @@ -13,6 +13,8 @@ using namespace Botan; #include <iostream> #include <memory> +#include "validate.h" + X509_Cert_Options ca_opts(); X509_Cert_Options req_opts1(); X509_Cert_Options req_opts2(); |