diff options
author | lloyd <[email protected]> | 2014-12-28 13:23:40 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2014-12-28 13:23:40 +0000 |
commit | 6322dc69fcf9f3effed4e51de90b3f5b163db47e (patch) | |
tree | 6cc5a7b12b5a6648f53b4b22003f9a28b425d1fa /src/tests | |
parent | 69d883e83569dd81f02fbbd7dfbdcfc5a3918d49 (diff) |
All tests now share an RNG. Uses system RNG if available
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/test_bigint.cpp | 4 | ||||
-rw-r--r-- | src/tests/test_cryptobox.cpp | 4 | ||||
-rw-r--r-- | src/tests/test_cvc.cpp | 4 | ||||
-rw-r--r-- | src/tests/test_dh.cpp | 4 | ||||
-rw-r--r-- | src/tests/test_dlies.cpp | 4 | ||||
-rw-r--r-- | src/tests/test_dsa.cpp | 4 | ||||
-rw-r--r-- | src/tests/test_ecdsa.cpp | 4 | ||||
-rw-r--r-- | src/tests/test_elg.cpp | 4 | ||||
-rw-r--r-- | src/tests/test_gost_3410.cpp | 4 | ||||
-rw-r--r-- | src/tests/test_mceliece.cpp | 4 | ||||
-rw-r--r-- | src/tests/test_nr.cpp | 4 | ||||
-rw-r--r-- | src/tests/test_passhash.cpp | 6 | ||||
-rw-r--r-- | src/tests/test_pubkey.cpp | 6 | ||||
-rw-r--r-- | src/tests/test_rsa.cpp | 8 | ||||
-rw-r--r-- | src/tests/test_rw.cpp | 6 | ||||
-rw-r--r-- | src/tests/test_tss.cpp | 4 | ||||
-rw-r--r-- | src/tests/tests.cpp | 16 | ||||
-rw-r--r-- | src/tests/tests.h | 4 | ||||
-rw-r--r-- | src/tests/unit_ecc.cpp | 8 | ||||
-rw-r--r-- | src/tests/unit_ecdh.cpp | 4 | ||||
-rw-r--r-- | src/tests/unit_ecdsa.cpp | 4 | ||||
-rw-r--r-- | src/tests/unit_tls.cpp | 4 | ||||
-rw-r--r-- | src/tests/unit_x509.cpp | 4 |
23 files changed, 65 insertions, 53 deletions
diff --git a/src/tests/test_bigint.cpp b/src/tests/test_bigint.cpp index 126fff411..7504a30d9 100644 --- a/src/tests/test_bigint.cpp +++ b/src/tests/test_bigint.cpp @@ -13,7 +13,7 @@ #include <cstdlib> #include <iterator> -#include <botan/auto_rng.h> + #include <botan/bigint.h> #include <botan/exceptn.h> #include <botan/numthry.h> @@ -299,7 +299,7 @@ size_t test_bigint() bool first = true; size_t counter = 0; - AutoSeeded_RNG rng; + auto& rng = test_rng(); while(!test_data.eof()) { diff --git a/src/tests/test_cryptobox.cpp b/src/tests/test_cryptobox.cpp index 9a53da74c..f5ae4ce86 100644 --- a/src/tests/test_cryptobox.cpp +++ b/src/tests/test_cryptobox.cpp @@ -1,6 +1,6 @@ #include "tests.h" -#include <botan/auto_rng.h> + #include <iostream> #if defined(BOTAN_HAS_CRYPTO_BOX) @@ -14,7 +14,7 @@ size_t test_cryptobox() size_t fails = 0; #if defined(BOTAN_HAS_CRYPTO_BOX) - AutoSeeded_RNG rng; + auto& rng = test_rng(); const byte msg[] = { 0xAA, 0xBB, 0xCC }; std::string ciphertext = CryptoBox::encrypt(msg, sizeof(msg), diff --git a/src/tests/test_cvc.cpp b/src/tests/test_cvc.cpp index 349eafd44..929f541e5 100644 --- a/src/tests/test_cvc.cpp +++ b/src/tests/test_cvc.cpp @@ -18,7 +18,7 @@ #include <vector> #include <memory> -#include <botan/auto_rng.h> + #include <botan/ecdsa.h> #include <botan/rsa.h> @@ -552,7 +552,7 @@ void test_cvc_chain(RandomNumberGenerator& rng) size_t test_cvc() { - AutoSeeded_RNG rng; + auto& rng = test_rng(); test_enc_gen_selfsigned(rng); test_enc_gen_req(rng); diff --git a/src/tests/test_dh.cpp b/src/tests/test_dh.cpp index 0b125a5ce..f01005dc6 100644 --- a/src/tests/test_dh.cpp +++ b/src/tests/test_dh.cpp @@ -2,7 +2,7 @@ #include "test_pubkey.h" #if defined(BOTAN_HAS_DIFFIE_HELLMAN) -#include <botan/auto_rng.h> + #include <botan/pubkey.h> #include <botan/dh.h> #include <botan/hex.h> @@ -21,7 +21,7 @@ size_t dh_sig_kat(const std::string& p, const std::string& outlen, const std::string& key) { - AutoSeeded_RNG rng; + auto& rng = test_rng(); BigInt p_bn(p), g_bn(g), x_bn(x), y_bn(y); diff --git a/src/tests/test_dlies.cpp b/src/tests/test_dlies.cpp index d1816bf98..f5fecc6d3 100644 --- a/src/tests/test_dlies.cpp +++ b/src/tests/test_dlies.cpp @@ -6,7 +6,7 @@ #include <fstream> #if defined(BOTAN_HAS_DLIES) - #include <botan/auto_rng.h> + #include <botan/pubkey.h> #include <botan/lookup.h> #include <botan/dlies.h> @@ -25,7 +25,7 @@ size_t dlies_kat(const std::string& p, const std::string& msg, const std::string& ciphertext) { - AutoSeeded_RNG rng; + auto& rng = test_rng(); BigInt p_bn(p); BigInt g_bn(g); diff --git a/src/tests/test_dsa.cpp b/src/tests/test_dsa.cpp index 43c415b33..0bb75e277 100644 --- a/src/tests/test_dsa.cpp +++ b/src/tests/test_dsa.cpp @@ -3,7 +3,7 @@ #if defined(BOTAN_HAS_DSA) -#include <botan/auto_rng.h> + #include <botan/pubkey.h> #include <botan/dsa.h> #include <botan/hex.h> @@ -23,7 +23,7 @@ size_t dsa_sig_kat(const std::string& p, const std::string& nonce, const std::string& signature) { - AutoSeeded_RNG rng; + auto& rng = test_rng(); BigInt p_bn("0x" + p), q_bn("0x" + q), g_bn("0x" + g), x_bn("0x" + x); diff --git a/src/tests/test_ecdsa.cpp b/src/tests/test_ecdsa.cpp index d83ba7a4b..e413d04df 100644 --- a/src/tests/test_ecdsa.cpp +++ b/src/tests/test_ecdsa.cpp @@ -2,7 +2,7 @@ #include "test_pubkey.h" #if defined(BOTAN_HAS_ECDSA) -#include <botan/auto_rng.h> + #include <botan/pubkey.h> #include <botan/ecdsa.h> #include <botan/oids.h> @@ -21,7 +21,7 @@ size_t ecdsa_sig_kat(const std::string& group_id, const std::string& nonce, const std::string& signature) { - AutoSeeded_RNG rng; + auto& rng = test_rng(); EC_Group group(OIDS::lookup(group_id)); ECDSA_PrivateKey ecdsa(rng, group, BigInt(x)); diff --git a/src/tests/test_elg.cpp b/src/tests/test_elg.cpp index 8d0a8d1ae..15a1ee452 100644 --- a/src/tests/test_elg.cpp +++ b/src/tests/test_elg.cpp @@ -7,7 +7,7 @@ #if defined(BOTAN_HAS_ELGAMAL) #include <botan/elgamal.h> - #include <botan/auto_rng.h> + #include <botan/pubkey.h> #include <botan/dl_group.h> #endif @@ -26,7 +26,7 @@ size_t elgamal_kat(const std::string& p, const std::string& nonce, const std::string& ciphertext) { - AutoSeeded_RNG rng; + auto& rng = test_rng(); const BigInt p_bn = BigInt(p); const BigInt g_bn = BigInt(g); diff --git a/src/tests/test_gost_3410.cpp b/src/tests/test_gost_3410.cpp index 843a490b1..ccf2ed771 100644 --- a/src/tests/test_gost_3410.cpp +++ b/src/tests/test_gost_3410.cpp @@ -2,7 +2,7 @@ #include "test_pubkey.h" #if defined(BOTAN_HAS_GOST_34_10_2001) -#include <botan/auto_rng.h> + #include <botan/pubkey.h> #include <botan/gost_3410.h> #include <botan/oids.h> @@ -20,8 +20,6 @@ size_t gost_verify(const std::string& group_id, const std::string& msg, const std::string& signature) { - AutoSeeded_RNG rng; - EC_Group group(OIDS::lookup(group_id)); PointGFp public_point = OS2ECP(hex_decode(x), group.get_curve()); diff --git a/src/tests/test_mceliece.cpp b/src/tests/test_mceliece.cpp index cb14af3f1..55dfd234d 100644 --- a/src/tests/test_mceliece.cpp +++ b/src/tests/test_mceliece.cpp @@ -7,7 +7,7 @@ #include <botan/oids.h> #include <botan/mceliece.h> #include <botan/mce_kem.h> -#include <botan/auto_rng.h> + #include <botan/hex.h> #include <iostream> @@ -179,7 +179,7 @@ size_t test_mceliece_raw(RandomNumberGenerator& rng, size_t code_length, size_t size_t test_mceliece() { - AutoSeeded_RNG rng; + auto& rng = test_rng(); size_t err_cnt = 0; size_t params__n__t_min_max[] = { diff --git a/src/tests/test_nr.cpp b/src/tests/test_nr.cpp index 148a527c8..0a16c452e 100644 --- a/src/tests/test_nr.cpp +++ b/src/tests/test_nr.cpp @@ -3,7 +3,7 @@ #if defined(BOTAN_HAS_NYBERG_RUEPPEL) #include <botan/nr.h> - #include <botan/auto_rng.h> + #include <botan/pubkey.h> #include <botan/dl_group.h> #endif @@ -27,7 +27,7 @@ size_t nr_sig_kat(const std::string& p, const std::string& nonce, const std::string& signature) { - AutoSeeded_RNG rng; + auto& rng = test_rng(); BigInt p_bn(p), q_bn(q), g_bn(g), x_bn(x); diff --git a/src/tests/test_passhash.cpp b/src/tests/test_passhash.cpp index 6f66743c5..57b9f6452 100644 --- a/src/tests/test_passhash.cpp +++ b/src/tests/test_passhash.cpp @@ -1,6 +1,6 @@ #include "tests.h" -#include <botan/auto_rng.h> + #include <iostream> #if defined(BOTAN_HAS_PASSHASH9) @@ -34,7 +34,7 @@ size_t test_bcrypt() fails++; } - AutoSeeded_RNG rng; + auto& rng = test_rng(); for(u16bit level = 1; level != 5; ++level) { @@ -73,7 +73,7 @@ size_t test_passhash9() fails++; } - AutoSeeded_RNG rng; + auto& rng = test_rng(); for(byte alg_id = 0; alg_id <= 4; ++alg_id) { diff --git a/src/tests/test_pubkey.cpp b/src/tests/test_pubkey.cpp index eec7e3bde..9de9a6f9d 100644 --- a/src/tests/test_pubkey.cpp +++ b/src/tests/test_pubkey.cpp @@ -21,7 +21,7 @@ #include <botan/x509_key.h> #include <botan/pkcs8.h> #include <botan/pubkey.h> - #include <botan/auto_rng.h> + #endif #if defined(BOTAN_HAS_RSA) @@ -193,7 +193,7 @@ size_t validate_encryption(PK_Encryptor& e, PK_Decryptor& d, if(algo.find("/Raw") == std::string::npos) { - AutoSeeded_RNG rng; + auto& rng = test_rng(); for(size_t i = 0; i != ctext.size(); ++i) { @@ -297,7 +297,7 @@ size_t validate_kas(PK_Key_Agreement& kas, const std::string& algo, size_t test_pk_keygen() { - AutoSeeded_RNG rng; + auto& rng = test_rng(); size_t tests = 0; size_t fails = 0; diff --git a/src/tests/test_rsa.cpp b/src/tests/test_rsa.cpp index 28320ddb0..f1ec8e603 100644 --- a/src/tests/test_rsa.cpp +++ b/src/tests/test_rsa.cpp @@ -1,7 +1,7 @@ #include "tests.h" #include "test_pubkey.h" -#include <botan/auto_rng.h> + #include <botan/pubkey.h> #include <botan/rsa.h> #include <botan/hex.h> @@ -20,7 +20,7 @@ size_t rsaes_kat(const std::string& e, const std::string& nonce, const std::string& output) { - AutoSeeded_RNG rng; + auto& rng = test_rng(); RSA_PrivateKey privkey(rng, BigInt(p), BigInt(q), BigInt(e)); @@ -43,7 +43,7 @@ size_t rsa_sig_kat(const std::string& e, const std::string& nonce, const std::string& output) { - AutoSeeded_RNG rng; + auto& rng = test_rng(); RSA_PrivateKey privkey(rng, BigInt(p), BigInt(q), BigInt(e)); @@ -64,8 +64,6 @@ size_t rsa_sig_verify(const std::string& e, std::string padding, const std::string& signature) { - AutoSeeded_RNG rng; - BigInt e_bn(e); BigInt n_bn(n); diff --git a/src/tests/test_rw.cpp b/src/tests/test_rw.cpp index 09e746add..9db811433 100644 --- a/src/tests/test_rw.cpp +++ b/src/tests/test_rw.cpp @@ -6,7 +6,7 @@ #include <fstream> #if defined(BOTAN_HAS_RW) - #include <botan/auto_rng.h> + #include <botan/pubkey.h> #include <botan/rw.h> #endif @@ -24,7 +24,7 @@ size_t rw_sig_kat(const std::string& e, const std::string& msg, const std::string& signature) { - AutoSeeded_RNG rng; + auto& rng = test_rng(); RW_PrivateKey privkey(rng, BigInt(p), BigInt(q), BigInt(e)); @@ -41,8 +41,6 @@ size_t rw_sig_verify(const std::string& e, const std::string& msg, const std::string& signature) { - AutoSeeded_RNG rng; - BigInt e_bn(e); BigInt n_bn(n); diff --git a/src/tests/test_tss.cpp b/src/tests/test_tss.cpp index 7645af399..646ebe415 100644 --- a/src/tests/test_tss.cpp +++ b/src/tests/test_tss.cpp @@ -5,7 +5,7 @@ */ #include "tests.h" -#include <botan/auto_rng.h> + #include <botan/hex.h> #include <iostream> @@ -17,7 +17,7 @@ size_t test_tss() { using namespace Botan; - AutoSeeded_RNG rng; + auto& rng = test_rng(); size_t fails = 0; diff --git a/src/tests/tests.cpp b/src/tests/tests.cpp index 99a4d8e3a..9ed6785bc 100644 --- a/src/tests/tests.cpp +++ b/src/tests/tests.cpp @@ -2,10 +2,26 @@ #include <botan/init.h> #include <iostream> #include <fstream> +#include <botan/auto_rng.h> + +#if defined(BOTAN_HAS_SYSTEM_RNG) + #include <botan/system_rng.h> +#endif + #include <boost/filesystem.hpp> namespace fs = boost::filesystem; +Botan::RandomNumberGenerator& test_rng() + { +#if defined(BOTAN_HAS_SYSTEM_RNG) + return Botan::system_rng(); +#else + static AutoSeeded_RNG rng; + return rng; +#endif + } + std::vector<std::string> list_dir(const std::string& dir_path) { std::vector<std::string> paths; diff --git a/src/tests/tests.h b/src/tests/tests.h index 61cc405a0..9d39fdc19 100644 --- a/src/tests/tests.h +++ b/src/tests/tests.h @@ -2,13 +2,15 @@ #ifndef BOTAN_TESTS_H__ #define BOTAN_TESTS_H__ -#include <botan/build.h> +#include <botan/rng.h> #include <functional> #include <istream> #include <map> #include <string> #include <vector> +Botan::RandomNumberGenerator& test_rng(); + size_t run_tests_bb(std::istream& src, const std::string& name_key, const std::string& output_key, diff --git a/src/tests/unit_ecc.cpp b/src/tests/unit_ecc.cpp index 976e9d385..f7723fb12 100644 --- a/src/tests/unit_ecc.cpp +++ b/src/tests/unit_ecc.cpp @@ -11,7 +11,7 @@ #include <memory> #if defined(BOTAN_HAS_ECC_GROUP) -#include <botan/auto_rng.h> + #include <botan/bigint.h> #include <botan/numthry.h> #include <botan/curve_gfp.h> @@ -752,7 +752,7 @@ size_t test_point_swap() EC_Group dom_pars(OID("1.3.132.0.8")); - AutoSeeded_RNG rng; + auto& rng = test_rng(); PointGFp a(create_random_point(rng, dom_pars.get_curve())); PointGFp b(create_random_point(rng, dom_pars.get_curve())); @@ -776,7 +776,7 @@ size_t test_mult_sec_mass() { size_t fails = 0; - AutoSeeded_RNG rng; + auto& rng = test_rng(); EC_Group dom_pars(OID("1.3.132.0.8")); for(int i = 0; i<50; i++) @@ -850,7 +850,7 @@ size_t ecc_randomized_test() "x962_p239v3" }; - AutoSeeded_RNG rng; + auto& rng = test_rng(); size_t fails = 0; size_t tests = 0; diff --git a/src/tests/unit_ecdh.cpp b/src/tests/unit_ecdh.cpp index 81e2e8fab..3dc6227e8 100644 --- a/src/tests/unit_ecdh.cpp +++ b/src/tests/unit_ecdh.cpp @@ -13,7 +13,7 @@ #include <iostream> #include <fstream> -#include <botan/auto_rng.h> + #include <botan/pubkey.h> #include <botan/ecdh.h> #if defined(BOTAN_HAS_X509_CERTIFICATES) @@ -123,7 +123,7 @@ size_t test_ecdh_unit() { size_t fails = 0; - AutoSeeded_RNG rng; + auto& rng = test_rng(); fails += test_ecdh_normal_derivation(rng); fails += test_ecdh_some_dp(rng); diff --git a/src/tests/unit_ecdsa.cpp b/src/tests/unit_ecdsa.cpp index 7a2e844e4..f0107c55d 100644 --- a/src/tests/unit_ecdsa.cpp +++ b/src/tests/unit_ecdsa.cpp @@ -10,7 +10,7 @@ #if defined(BOTAN_HAS_ECDSA) #include <botan/hex.h> -#include <botan/auto_rng.h> + #include <botan/pubkey.h> #include <botan/ecdsa.h> #include <botan/rsa.h> @@ -473,7 +473,7 @@ size_t test_ecdsa_unit() { size_t fails = 0; - AutoSeeded_RNG rng; + auto& rng = test_rng(); fails += test_hash_larger_than_n(rng); #if defined(BOTAN_HAS_X509_CERTIFICATES) diff --git a/src/tests/unit_tls.cpp b/src/tests/unit_tls.cpp index cc5c1e240..91cd094f2 100644 --- a/src/tests/unit_tls.cpp +++ b/src/tests/unit_tls.cpp @@ -3,7 +3,7 @@ #if defined(BOTAN_HAS_TLS) -#include <botan/auto_rng.h> + #include <botan/tls_server.h> #include <botan/tls_client.h> #include <botan/pkcs10.h> @@ -282,7 +282,7 @@ size_t test_tls() size_t errors = 0; Test_Policy default_policy; - AutoSeeded_RNG rng; + auto& rng = test_rng(); std::auto_ptr<Credentials_Manager> basic_creds(create_creds(rng)); errors += basic_test_handshake(rng, TLS::Protocol_Version::SSL_V3, *basic_creds, default_policy); diff --git a/src/tests/unit_x509.cpp b/src/tests/unit_x509.cpp index d6e7f6e90..0c469d319 100644 --- a/src/tests/unit_x509.cpp +++ b/src/tests/unit_x509.cpp @@ -7,7 +7,7 @@ #include "tests.h" #include <botan/filters.h> -#include <botan/auto_rng.h> + #if defined(BOTAN_HAS_RSA) #include <botan/rsa.h> @@ -131,7 +131,7 @@ u32bit check_against_copy(const Private_Key& orig, size_t test_x509() { - AutoSeeded_RNG rng; + auto& rng = test_rng(); const std::string hash_fn = "SHA-256"; size_t fails = 0; |