diff options
author | Jack Lloyd <[email protected]> | 2018-05-29 16:09:12 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-05-29 16:09:12 -0400 |
commit | b3e4f1421b432e239ce76d72869a0e28089748f5 (patch) | |
tree | b1357b3ad81717a0827af35b22ed797c2a3704d0 /src | |
parent | 5b60dae056a652c9eb0b480db8bfa020ead9d4e1 (diff) | |
parent | 5f26125dc579d0ee5297a0233305496365c69e63 (diff) |
Merge GH #1592 Refactor VarMap
Diffstat (limited to 'src')
47 files changed, 474 insertions, 489 deletions
diff --git a/src/tests/test_aead.cpp b/src/tests/test_aead.cpp index afd169396..e92d8f4b6 100644 --- a/src/tests/test_aead.cpp +++ b/src/tests/test_aead.cpp @@ -319,11 +319,11 @@ class AEAD_Tests final : public Text_Based_Test Test::Result run_one_test(const std::string& algo, const VarMap& vars) override { - const std::vector<uint8_t> key = get_req_bin(vars, "Key"); - const std::vector<uint8_t> nonce = get_opt_bin(vars, "Nonce"); - const std::vector<uint8_t> input = get_req_bin(vars, "In"); - const std::vector<uint8_t> expected = get_req_bin(vars, "Out"); - const std::vector<uint8_t> ad = get_opt_bin(vars, "AD"); + const std::vector<uint8_t> key = vars.get_req_bin("Key"); + const std::vector<uint8_t> nonce = vars.get_opt_bin("Nonce"); + const std::vector<uint8_t> input = vars.get_req_bin("In"); + const std::vector<uint8_t> expected = vars.get_req_bin("Out"); + const std::vector<uint8_t> ad = vars.get_opt_bin("AD"); Test::Result result(algo); diff --git a/src/tests/test_asn1.cpp b/src/tests/test_asn1.cpp index d025fe9f5..714328514 100644 --- a/src/tests/test_asn1.cpp +++ b/src/tests/test_asn1.cpp @@ -301,7 +301,7 @@ class ASN1_Time_Parsing_Tests final : public Text_Based_Test { Test::Result result("ASN.1 date parsing"); - const std::string tspec = get_req_str(vars, "Tspec"); + const std::string tspec = vars.get_req_str("Tspec"); if(tag_str != "UTC" && tag_str != "UTC.invalid" && diff --git a/src/tests/test_bigint.cpp b/src/tests/test_bigint.cpp index c7547194b..b62fa307d 100644 --- a/src/tests/test_bigint.cpp +++ b/src/tests/test_bigint.cpp @@ -256,9 +256,9 @@ class BigInt_Add_Test final : public Text_Based_Test using Botan::BigInt; - const BigInt a = get_req_bn(vars, "In1"); - const BigInt b = get_req_bn(vars, "In2"); - const BigInt c = get_req_bn(vars, "Output"); + const BigInt a = vars.get_req_bn("In1"); + const BigInt b = vars.get_req_bn("In2"); + const BigInt c = vars.get_req_bn("Output"); result.test_eq("a + b", a + b, c); result.test_eq("b + a", b + a, c); @@ -287,9 +287,9 @@ class BigInt_Sub_Test final : public Text_Based_Test { Test::Result result("BigInt Subtraction"); - const BigInt a = get_req_bn(vars, "In1"); - const BigInt b = get_req_bn(vars, "In2"); - const BigInt c = get_req_bn(vars, "Output"); + const BigInt a = vars.get_req_bn("In1"); + const BigInt b = vars.get_req_bn("In2"); + const BigInt c = vars.get_req_bn("Output"); result.test_eq("a - b", a - b, c); @@ -312,9 +312,9 @@ class BigInt_Mul_Test final : public Text_Based_Test { Test::Result result("BigInt Multiply"); - const BigInt a = get_req_bn(vars, "In1"); - const BigInt b = get_req_bn(vars, "In2"); - const BigInt c = get_req_bn(vars, "Output"); + const BigInt a = vars.get_req_bn("In1"); + const BigInt b = vars.get_req_bn("In2"); + const BigInt c = vars.get_req_bn("Output"); result.test_eq("a * b", a * b, c); result.test_eq("b * a", b * a, c); @@ -342,8 +342,8 @@ class BigInt_Sqr_Test final : public Text_Based_Test { Test::Result result("BigInt Square"); - const BigInt input = get_req_bn(vars, "Input"); - const BigInt output = get_req_bn(vars, "Output"); + const BigInt input = vars.get_req_bn("Input"); + const BigInt output = vars.get_req_bn("Output"); result.test_eq("a * a", input * input, output); result.test_eq("sqr(a)", square(input), output); @@ -363,9 +363,9 @@ class BigInt_Div_Test final : public Text_Based_Test { Test::Result result("BigInt Divide"); - const BigInt a = get_req_bn(vars, "In1"); - const BigInt b = get_req_bn(vars, "In2"); - const BigInt c = get_req_bn(vars, "Output"); + const BigInt a = vars.get_req_bn("In1"); + const BigInt b = vars.get_req_bn("In2"); + const BigInt c = vars.get_req_bn("Output"); result.test_eq("a / b", a / b, c); @@ -388,9 +388,9 @@ class BigInt_Mod_Test final : public Text_Based_Test { Test::Result result("BigInt Mod"); - const BigInt a = get_req_bn(vars, "In1"); - const BigInt b = get_req_bn(vars, "In2"); - const BigInt c = get_req_bn(vars, "Output"); + const BigInt a = vars.get_req_bn("In1"); + const BigInt b = vars.get_req_bn("In2"); + const BigInt c = vars.get_req_bn("Output"); result.test_eq("a % b", a % b, c); @@ -422,9 +422,9 @@ class BigInt_GCD_Test final : public Text_Based_Test { Test::Result result("BigInt Mod"); - const BigInt x = get_req_bn(vars, "X"); - const BigInt y = get_req_bn(vars, "Y"); - const BigInt expected = get_req_bn(vars, "GCD"); + const BigInt x = vars.get_req_bn("X"); + const BigInt y = vars.get_req_bn("Y"); + const BigInt expected = vars.get_req_bn("GCD"); const BigInt g = Botan::gcd(x, y); @@ -444,9 +444,9 @@ class BigInt_Lshift_Test final : public Text_Based_Test { Test::Result result("BigInt Lshift"); - const BigInt value = get_req_bn(vars, "Value"); - const size_t shift = get_req_bn(vars, "Shift").to_u32bit(); - const BigInt output = get_req_bn(vars, "Output"); + const BigInt value = vars.get_req_bn("Value"); + const size_t shift = vars.get_req_bn("Shift").to_u32bit(); + const BigInt output = vars.get_req_bn("Output"); result.test_eq("a << s", value << shift, output); @@ -469,9 +469,9 @@ class BigInt_Rshift_Test final : public Text_Based_Test { Test::Result result("BigInt Rshift"); - const BigInt value = get_req_bn(vars, "Value"); - const size_t shift = get_req_bn(vars, "Shift").to_u32bit(); - const BigInt output = get_req_bn(vars, "Output"); + const BigInt value = vars.get_req_bn("Value"); + const size_t shift = vars.get_req_bn("Shift").to_u32bit(); + const BigInt output = vars.get_req_bn("Output"); result.test_eq("a >> s", value >> shift, output); @@ -494,10 +494,10 @@ class BigInt_Powmod_Test final : public Text_Based_Test { Test::Result result("BigInt Powmod"); - const BigInt base = get_req_bn(vars, "Base"); - const BigInt exponent = get_req_bn(vars, "Exponent"); - const BigInt modulus = get_req_bn(vars, "Modulus"); - const BigInt expected = get_req_bn(vars, "Output"); + const BigInt base = vars.get_req_bn("Base"); + const BigInt exponent = vars.get_req_bn("Exponent"); + const BigInt modulus = vars.get_req_bn("Modulus"); + const BigInt expected = vars.get_req_bn("Output"); result.test_eq("power_mod", Botan::power_mod(base, exponent, modulus), expected); @@ -550,7 +550,7 @@ class BigInt_IsPrime_Test final : public Text_Based_Test throw Test_Error("Bad header for prime test " + header); } - const BigInt value = get_req_bn(vars, "X"); + const BigInt value = vars.get_req_bn("X"); const bool is_prime = (header == "Prime"); Test::Result result("BigInt Test " + header); @@ -570,9 +570,9 @@ class BigInt_Ressol_Test final : public Text_Based_Test { Test::Result result("BigInt Ressol"); - const Botan::BigInt a = get_req_bn(vars, "Input"); - const Botan::BigInt p = get_req_bn(vars, "Modulus"); - const Botan::BigInt exp = get_req_bn(vars, "Output"); + const Botan::BigInt a = vars.get_req_bn("Input"); + const Botan::BigInt p = vars.get_req_bn("Modulus"); + const Botan::BigInt exp = vars.get_req_bn("Output"); const Botan::BigInt a_sqrt = Botan::ressol(a, p); @@ -599,9 +599,9 @@ class BigInt_InvMod_Test final : public Text_Based_Test { Test::Result result("BigInt InvMod"); - const Botan::BigInt a = get_req_bn(vars, "Input"); - const Botan::BigInt mod = get_req_bn(vars, "Modulus"); - const Botan::BigInt expected = get_req_bn(vars, "Output"); + const Botan::BigInt a = vars.get_req_bn("Input"); + const Botan::BigInt mod = vars.get_req_bn("Modulus"); + const Botan::BigInt expected = vars.get_req_bn("Output"); const Botan::BigInt a_inv = Botan::inverse_euclid(a, mod); @@ -641,10 +641,10 @@ class BigInt_Rand_Test final : public Text_Based_Test { Test::Result result("BigInt Random"); - const std::vector<uint8_t> seed = get_req_bin(vars, "Seed"); - const Botan::BigInt min = get_req_bn(vars, "Min"); - const Botan::BigInt max = get_req_bn(vars, "Max"); - const Botan::BigInt expected = get_req_bn(vars, "Output"); + const std::vector<uint8_t> seed = vars.get_req_bin("Seed"); + const Botan::BigInt min = vars.get_req_bn("Min"); + const Botan::BigInt max = vars.get_req_bn("Max"); + const Botan::BigInt expected = vars.get_req_bn("Output"); Fixed_Output_RNG rng(seed); Botan::BigInt generated = BigInt::random_integer(rng, min, max); @@ -664,11 +664,11 @@ class DSA_ParamGen_Test final : public Text_Based_Test Test::Result run_one_test(const std::string& header, const VarMap& vars) override { - const std::vector<uint8_t> seed = get_req_bin(vars, "Seed"); - const size_t offset = get_req_sz(vars, "Counter"); + const std::vector<uint8_t> seed = vars.get_req_bin("Seed"); + const size_t offset = vars.get_req_sz("Counter"); - const Botan::BigInt exp_P = get_req_bn(vars, "P"); - const Botan::BigInt exp_Q = get_req_bn(vars, "Q"); + const Botan::BigInt exp_P = vars.get_req_bn("P"); + const Botan::BigInt exp_Q = vars.get_req_bn("Q"); const std::vector<std::string> header_parts = Botan::split_on(header, ','); diff --git a/src/tests/test_block.cpp b/src/tests/test_block.cpp index cb2eff807..111e79b4b 100644 --- a/src/tests/test_block.cpp +++ b/src/tests/test_block.cpp @@ -24,10 +24,10 @@ class Block_Cipher_Tests final : public Text_Based_Test Test::Result run_one_test(const std::string& algo, const VarMap& vars) override { - const std::vector<uint8_t> key = get_req_bin(vars, "Key"); - const std::vector<uint8_t> input = get_req_bin(vars, "In"); - const std::vector<uint8_t> expected = get_req_bin(vars, "Out"); - const size_t iterations = get_opt_sz(vars, "Iterations", 1); + const std::vector<uint8_t> key = vars.get_req_bin("Key"); + const std::vector<uint8_t> input = vars.get_req_bin("In"); + const std::vector<uint8_t> expected = vars.get_req_bin("Out"); + const size_t iterations = vars.get_opt_sz("Iterations", 1); Test::Result result(algo); diff --git a/src/tests/test_c25519.cpp b/src/tests/test_c25519.cpp index 8c8129a18..9fa1a955b 100644 --- a/src/tests/test_c25519.cpp +++ b/src/tests/test_c25519.cpp @@ -27,9 +27,9 @@ class Curve25519_Sclarmult_Tests final : public Text_Based_Test Test::Result run_one_test(const std::string&, const VarMap& vars) override { - const std::vector<uint8_t> secret = get_req_bin(vars, "Secret"); - const std::vector<uint8_t> basepoint = get_req_bin(vars, "Basepoint"); - const std::vector<uint8_t> expected = get_req_bin(vars, "Out"); + const std::vector<uint8_t> secret = vars.get_req_bin("Secret"); + const std::vector<uint8_t> basepoint = vars.get_req_bin("Basepoint"); + const std::vector<uint8_t> expected = vars.get_req_bin("Out"); std::vector<uint8_t> got(32); Botan::curve25519_donna(got.data(), secret.data(), basepoint.data()); diff --git a/src/tests/test_dh.cpp b/src/tests/test_dh.cpp index 8a7fb169c..77778925f 100644 --- a/src/tests/test_dh.cpp +++ b/src/tests/test_dh.cpp @@ -35,10 +35,10 @@ class Diffie_Hellman_KAT_Tests final : public PK_Key_Agreement_Test std::unique_ptr<Botan::Private_Key> load_our_key(const std::string&, const VarMap& vars) override { - const Botan::BigInt p = get_req_bn(vars, "P"); - const Botan::BigInt q = get_opt_bn(vars, "Q", 0); - const Botan::BigInt g = get_req_bn(vars, "G"); - const Botan::BigInt x = get_req_bn(vars, "X"); + const Botan::BigInt p = vars.get_req_bn("P"); + const Botan::BigInt q = vars.get_opt_bn("Q", 0); + const Botan::BigInt g = vars.get_req_bn("G"); + const Botan::BigInt x = vars.get_req_bn("X"); Botan::DL_Group grp; if(q == 0) @@ -56,10 +56,10 @@ class Diffie_Hellman_KAT_Tests final : public PK_Key_Agreement_Test std::vector<uint8_t> load_their_key(const std::string&, const VarMap& vars) override { - const Botan::BigInt p = get_req_bn(vars, "P"); - const Botan::BigInt q = get_opt_bn(vars, "Q", 0); - const Botan::BigInt g = get_req_bn(vars, "G"); - const Botan::BigInt y = get_req_bn(vars, "Y"); + const Botan::BigInt p = vars.get_req_bn("P"); + const Botan::BigInt q = vars.get_opt_bn("Q", 0); + const Botan::BigInt g = vars.get_req_bn("G"); + const Botan::BigInt y = vars.get_req_bn("Y"); Botan::DL_Group grp; if(q == 0) @@ -124,10 +124,10 @@ class DH_Invalid_Key_Tests final : public Text_Based_Test { Test::Result result("DH invalid keys"); - const Botan::BigInt p = get_req_bn(vars, "P"); - const Botan::BigInt q = get_req_bn(vars, "Q"); - const Botan::BigInt g = get_req_bn(vars, "G"); - const Botan::BigInt pubkey = get_req_bn(vars, "InvalidKey"); + const Botan::BigInt p = vars.get_req_bn("P"); + const Botan::BigInt q = vars.get_req_bn("Q"); + const Botan::BigInt g = vars.get_req_bn("G"); + const Botan::BigInt pubkey = vars.get_req_bn("InvalidKey"); Botan::DL_Group grp(p, q, g); std::unique_ptr<Botan::Public_Key> key(new Botan::DH_PublicKey(grp, pubkey)); diff --git a/src/tests/test_dlies.cpp b/src/tests/test_dlies.cpp index d3fb76498..de1dfbd25 100644 --- a/src/tests/test_dlies.cpp +++ b/src/tests/test_dlies.cpp @@ -29,18 +29,18 @@ class DLIES_KAT_Tests final : public Text_Based_Test Test::Result run_one_test(const std::string& cipher_algo, const VarMap& vars) override { - const Botan::BigInt x1 = get_req_bn(vars, "X1"); - const Botan::BigInt x2 = get_req_bn(vars, "X2"); + const Botan::BigInt x1 = vars.get_req_bn("X1"); + const Botan::BigInt x2 = vars.get_req_bn("X2"); - const std::vector<uint8_t> input = get_req_bin(vars, "Msg"); - const std::vector<uint8_t> expected = get_req_bin(vars, "Ciphertext"); + const std::vector<uint8_t> input = vars.get_req_bin("Msg"); + const std::vector<uint8_t> expected = vars.get_req_bin("Ciphertext"); - const std::string kdf_algo = get_req_str(vars, "Kdf"); - const std::string mac_algo = get_req_str(vars, "Mac"); - const size_t mac_key_len = get_req_sz(vars, "MacKeyLen"); - const std::string group_name = get_req_str(vars, "Group"); + const std::string kdf_algo = vars.get_req_str("Kdf"); + const std::string mac_algo = vars.get_req_str("Mac"); + const size_t mac_key_len = vars.get_req_sz("MacKeyLen"); + const std::string group_name = vars.get_req_str("Group"); - const std::vector<uint8_t> iv = get_opt_bin(vars, "IV"); + const std::vector<uint8_t> iv = vars.get_opt_bin("IV"); Test::Result result("DLIES " + cipher_algo); diff --git a/src/tests/test_dsa.cpp b/src/tests/test_dsa.cpp index c0b2508c0..86a9714b8 100644 --- a/src/tests/test_dsa.cpp +++ b/src/tests/test_dsa.cpp @@ -38,10 +38,10 @@ class DSA_KAT_Tests final : public PK_Signature_Generation_Test std::unique_ptr<Botan::Private_Key> load_private_key(const VarMap& vars) override { - const Botan::BigInt p = get_req_bn(vars, "P"); - const Botan::BigInt q = get_req_bn(vars, "Q"); - const Botan::BigInt g = get_req_bn(vars, "G"); - const Botan::BigInt x = get_req_bn(vars, "X"); + const Botan::BigInt p = vars.get_req_bn("P"); + const Botan::BigInt q = vars.get_req_bn("Q"); + const Botan::BigInt g = vars.get_req_bn("G"); + const Botan::BigInt x = vars.get_req_bn("X"); const Botan::DL_Group grp(p, q, g); @@ -51,7 +51,7 @@ class DSA_KAT_Tests final : public PK_Signature_Generation_Test std::string default_padding(const VarMap& vars) const override { - return "EMSA1(" + get_req_str(vars, "Hash") + ")"; + return "EMSA1(" + vars.get_req_str("Hash") + ")"; } }; @@ -70,10 +70,10 @@ class DSA_Verification_Tests final : public PK_Signature_Verification_Test std::unique_ptr<Botan::Public_Key> load_public_key(const VarMap& vars) override { - const Botan::BigInt p = get_req_bn(vars, "P"); - const Botan::BigInt q = get_req_bn(vars, "Q"); - const Botan::BigInt g = get_req_bn(vars, "G"); - const Botan::BigInt y = get_req_bn(vars, "Y"); + const Botan::BigInt p = vars.get_req_bn("P"); + const Botan::BigInt q = vars.get_req_bn("Q"); + const Botan::BigInt g = vars.get_req_bn("G"); + const Botan::BigInt y = vars.get_req_bn("Y"); const Botan::DL_Group grp(p, q, g); diff --git a/src/tests/test_ecc_pointmul.cpp b/src/tests/test_ecc_pointmul.cpp index 6ee0034a0..2a3c1727c 100644 --- a/src/tests/test_ecc_pointmul.cpp +++ b/src/tests/test_ecc_pointmul.cpp @@ -23,9 +23,9 @@ class ECC_Pointmult_Tests final : public Text_Based_Test Test::Result run_one_test(const std::string& group_id, const VarMap& vars) override { - const Botan::BigInt m = get_req_bn(vars, "m"); - const Botan::BigInt X = get_req_bn(vars, "X"); - const Botan::BigInt Y = get_req_bn(vars, "Y"); + const Botan::BigInt m = vars.get_req_bn("m"); + const Botan::BigInt X = vars.get_req_bn("X"); + const Botan::BigInt Y = vars.get_req_bn("Y"); Botan::EC_Group group(Botan::OIDS::lookup(group_id)); diff --git a/src/tests/test_ecdh.cpp b/src/tests/test_ecdh.cpp index 7ea19eb53..50ff7c53e 100644 --- a/src/tests/test_ecdh.cpp +++ b/src/tests/test_ecdh.cpp @@ -36,14 +36,14 @@ class ECDH_KAT_Tests final : public PK_Key_Agreement_Test const VarMap& vars) override { Botan::EC_Group group(group_id); - const Botan::BigInt secret = get_req_bn(vars, "Secret"); + const Botan::BigInt secret = vars.get_req_bn("Secret"); std::unique_ptr<Botan::Private_Key> key(new Botan::ECDH_PrivateKey(Test::rng(), group, secret)); return key; } std::vector<uint8_t> load_their_key(const std::string&, const VarMap& vars) override { - return get_req_bin(vars, "CounterKey"); + return vars.get_req_bin("CounterKey"); } }; diff --git a/src/tests/test_ecdsa.cpp b/src/tests/test_ecdsa.cpp index 331a1dcaf..6464bc7a0 100644 --- a/src/tests/test_ecdsa.cpp +++ b/src/tests/test_ecdsa.cpp @@ -36,9 +36,9 @@ class ECDSA_Verification_Tests final : public PK_Signature_Verification_Test std::unique_ptr<Botan::Public_Key> load_public_key(const VarMap& vars) override { - const std::string group_id = get_req_str(vars, "Group"); - const BigInt px = get_req_bn(vars, "Px"); - const BigInt py = get_req_bn(vars, "Py"); + const std::string group_id = vars.get_req_str("Group"); + const BigInt px = vars.get_req_bn("Px"); + const BigInt py = vars.get_req_bn("Py"); Botan::EC_Group group(Botan::OIDS::lookup(group_id)); const Botan::PointGFp public_point = group.point(px, py); @@ -73,8 +73,8 @@ class ECDSA_Signature_KAT_Tests final : public PK_Signature_Generation_Test std::unique_ptr<Botan::Private_Key> load_private_key(const VarMap& vars) override { - const std::string group_id = get_req_str(vars, "Group"); - const BigInt x = get_req_bn(vars, "X"); + const std::string group_id = vars.get_req_str("Group"); + const BigInt x = vars.get_req_bn("X"); Botan::EC_Group group(Botan::OIDS::lookup(group_id)); std::unique_ptr<Botan::Private_Key> key(new Botan::ECDSA_PrivateKey(Test::rng(), group, x)); @@ -83,7 +83,7 @@ class ECDSA_Signature_KAT_Tests final : public PK_Signature_Generation_Test std::string default_padding(const VarMap& vars) const override { - const std::string hash = get_req_str(vars, "Hash"); + const std::string hash = vars.get_req_str("Hash"); if(hash.substr(0,3) == "Raw") return hash; return "EMSA1(" + hash + ")"; @@ -127,10 +127,10 @@ class ECDSA_Invalid_Key_Tests final : public Text_Based_Test { Test::Result result("ECDSA invalid keys"); - const std::string group_id = get_req_str(vars, "Group"); + const std::string group_id = vars.get_req_str("Group"); Botan::EC_Group group(Botan::OIDS::lookup(group_id)); - const Botan::BigInt x = get_req_bn(vars, "InvalidKeyX"); - const Botan::BigInt y = get_req_bn(vars, "InvalidKeyY"); + const Botan::BigInt x = vars.get_req_bn("InvalidKeyX"); + const Botan::BigInt y = vars.get_req_bn("InvalidKeyY"); std::unique_ptr<Botan::PointGFp> public_point; diff --git a/src/tests/test_ecgdsa.cpp b/src/tests/test_ecgdsa.cpp index 325c53b55..5ddb5b9f8 100644 --- a/src/tests/test_ecgdsa.cpp +++ b/src/tests/test_ecgdsa.cpp @@ -35,8 +35,8 @@ class ECGDSA_Signature_KAT_Tests final : public PK_Signature_Generation_Test std::unique_ptr<Botan::Private_Key> load_private_key(const VarMap& vars) override { - const std::string group_id = get_req_str(vars, "Group"); - const BigInt x = get_req_bn(vars, "X"); + const std::string group_id = vars.get_req_str("Group"); + const BigInt x = vars.get_req_bn("X"); Botan::EC_Group group(Botan::OIDS::lookup(group_id)); std::unique_ptr<Botan::Private_Key> key(new Botan::ECGDSA_PrivateKey(Test::rng(), group, x)); @@ -45,7 +45,7 @@ class ECGDSA_Signature_KAT_Tests final : public PK_Signature_Generation_Test std::string default_padding(const VarMap& vars) const override { - return "EMSA1(" + get_req_str(vars, "Hash") + ")"; + return "EMSA1(" + vars.get_req_str("Hash") + ")"; } Botan::RandomNumberGenerator* test_rng(const std::vector<uint8_t>& nonce) const override diff --git a/src/tests/test_ecies.cpp b/src/tests/test_ecies.cpp index 911d0c3a3..63619a8a4 100644 --- a/src/tests/test_ecies.cpp +++ b/src/tests/test_ecies.cpp @@ -112,20 +112,20 @@ class ECIES_ISO_Tests final : public Text_Based_Test Test::Result result("ECIES-ISO"); // get test vectors defined by ISO 18033 - const Botan::PointGFp::Compression_Type compression_type = get_compression_type(get_req_str(vars, "format")); - const Botan::BigInt p = get_req_bn(vars, "p"); - const Botan::BigInt a = get_req_bn(vars, "a"); - const Botan::BigInt b = get_req_bn(vars, "b"); - const Botan::BigInt mu = get_req_bn(vars, "mu"); // order - const Botan::BigInt nu = get_req_bn(vars, "nu"); // cofactor - const Botan::BigInt gx = get_req_bn(vars, "gx"); // base point x - const Botan::BigInt gy = get_req_bn(vars, "gy"); // base point y - const Botan::BigInt hx = get_req_bn(vars, "hx"); // x of public point of bob - const Botan::BigInt hy = get_req_bn(vars, "hy"); // y of public point of bob - const Botan::BigInt x = get_req_bn(vars, "x"); // private key of bob - const Botan::BigInt r = get_req_bn(vars, "r"); // (ephemeral) private key of alice - const std::vector<uint8_t> c0 = get_req_bin(vars, "C0"); // expected encoded (ephemeral) public key - const std::vector<uint8_t> k = get_req_bin(vars, "K"); // expected derived secret + const Botan::PointGFp::Compression_Type compression_type = get_compression_type(vars.get_req_str("format")); + const Botan::BigInt p = vars.get_req_bn("p"); + const Botan::BigInt a = vars.get_req_bn("a"); + const Botan::BigInt b = vars.get_req_bn("b"); + const Botan::BigInt mu = vars.get_req_bn("mu"); // order + const Botan::BigInt nu = vars.get_req_bn("nu"); // cofactor + const Botan::BigInt gx = vars.get_req_bn("gx"); // base point x + const Botan::BigInt gy = vars.get_req_bn("gy"); // base point y + const Botan::BigInt hx = vars.get_req_bn("hx"); // x of public point of bob + const Botan::BigInt hy = vars.get_req_bn("hy"); // y of public point of bob + const Botan::BigInt x = vars.get_req_bn("x"); // private key of bob + const Botan::BigInt r = vars.get_req_bn("r"); // (ephemeral) private key of alice + const std::vector<uint8_t> c0 = vars.get_req_bin("C0"); // expected encoded (ephemeral) public key + const std::vector<uint8_t> k = vars.get_req_bin("K"); // expected derived secret const Botan::EC_Group domain(p, a, b, gx, gy, mu, nu); @@ -203,23 +203,23 @@ class ECIES_Tests final : public Text_Based_Test { Test::Result result("ECIES"); - const std::string curve = get_req_str(vars, "Curve"); - const Botan::BigInt private_key_value = get_req_bn(vars, "PrivateKey"); - const Botan::BigInt other_private_key_value = get_req_bn(vars, "OtherPrivateKey"); - const std::string kdf = get_req_str(vars, "Kdf"); - const std::string dem = get_req_str(vars, "Dem"); - const size_t dem_key_len = get_req_sz(vars, "DemKeyLen"); - const std::vector<uint8_t> iv = get_req_bin(vars, "Iv"); - const std::string mac = get_req_str(vars, "Mac"); - const size_t mac_key_len = get_req_sz(vars, "MacKeyLen"); - const Botan::PointGFp::Compression_Type compression_type = get_compression_type(get_req_str(vars, "Format")); - const bool cofactor_mode = get_req_sz(vars, "CofactorMode") != 0; - const bool old_cofactor_mode = get_req_sz(vars, "OldCofactorMode") != 0; - const bool check_mode = get_req_sz(vars, "CheckMode") != 0; - const bool single_hash_mode = get_req_sz(vars, "SingleHashMode") != 0; - const std::string label = get_req_str(vars, "Label"); - const std::vector<uint8_t> plaintext = get_req_bin(vars, "Plaintext"); - const std::vector<uint8_t> ciphertext = get_req_bin(vars, "Ciphertext"); + const std::string curve = vars.get_req_str("Curve"); + const Botan::BigInt private_key_value = vars.get_req_bn("PrivateKey"); + const Botan::BigInt other_private_key_value = vars.get_req_bn("OtherPrivateKey"); + const std::string kdf = vars.get_req_str("Kdf"); + const std::string dem = vars.get_req_str("Dem"); + const size_t dem_key_len = vars.get_req_sz("DemKeyLen"); + const std::vector<uint8_t> iv = vars.get_req_bin("Iv"); + const std::string mac = vars.get_req_str("Mac"); + const size_t mac_key_len = vars.get_req_sz("MacKeyLen"); + const Botan::PointGFp::Compression_Type compression_type = get_compression_type(vars.get_req_str("Format")); + const bool cofactor_mode = vars.get_req_sz("CofactorMode") != 0; + const bool old_cofactor_mode = vars.get_req_sz("OldCofactorMode") != 0; + const bool check_mode = vars.get_req_sz("CheckMode") != 0; + const bool single_hash_mode = vars.get_req_sz("SingleHashMode") != 0; + const std::string label = vars.get_req_str("Label"); + const std::vector<uint8_t> plaintext = vars.get_req_bin("Plaintext"); + const std::vector<uint8_t> ciphertext = vars.get_req_bin("Ciphertext"); const Flags flags = ecies_flags(cofactor_mode, old_cofactor_mode, check_mode, single_hash_mode); const Botan::EC_Group domain(curve); diff --git a/src/tests/test_eckcdsa.cpp b/src/tests/test_eckcdsa.cpp index f32ef92db..c6a8cdd7b 100644 --- a/src/tests/test_eckcdsa.cpp +++ b/src/tests/test_eckcdsa.cpp @@ -36,8 +36,8 @@ class ECKCDSA_Signature_KAT_Tests final : public PK_Signature_Generation_Test std::unique_ptr<Botan::Private_Key> load_private_key(const VarMap& vars) override { - const std::string group_id = get_req_str(vars, "Group"); - const BigInt x = get_req_bn(vars, "X"); + const std::string group_id = vars.get_req_str("Group"); + const BigInt x = vars.get_req_bn("X"); Botan::EC_Group group(Botan::OIDS::lookup(group_id)); std::unique_ptr<Botan::Private_Key> key(new Botan::ECKCDSA_PrivateKey(Test::rng(), group, x)); @@ -46,7 +46,7 @@ class ECKCDSA_Signature_KAT_Tests final : public PK_Signature_Generation_Test std::string default_padding(const VarMap& vars) const override { - return "EMSA1(" + get_req_str(vars, "Hash") + ")"; + return "EMSA1(" + vars.get_req_str("Hash") + ")"; } Botan::RandomNumberGenerator* test_rng(const std::vector<uint8_t>& nonce) const override diff --git a/src/tests/test_ed25519.cpp b/src/tests/test_ed25519.cpp index c822fb320..05a5ce30c 100644 --- a/src/tests/test_ed25519.cpp +++ b/src/tests/test_ed25519.cpp @@ -30,7 +30,7 @@ class Ed25519_Verification_Tests : public PK_Signature_Verification_Test std::unique_ptr<Botan::Public_Key> load_public_key(const VarMap& vars) override { - const std::vector<uint8_t> pubkey = get_req_bin(vars, "Pubkey"); + const std::vector<uint8_t> pubkey = vars.get_req_bin("Pubkey"); std::unique_ptr<Botan::Ed25519_PublicKey> key(new Botan::Ed25519_PublicKey(pubkey)); @@ -49,8 +49,8 @@ class Ed25519_Signature_Tests final : public PK_Signature_Generation_Test std::unique_ptr<Botan::Private_Key> load_private_key(const VarMap& vars) override { - const std::vector<uint8_t> privkey = get_req_bin(vars, "Privkey"); - const std::vector<uint8_t> pubkey = get_req_bin(vars, "Pubkey"); + const std::vector<uint8_t> privkey = vars.get_req_bin("Privkey"); + const std::vector<uint8_t> pubkey = vars.get_req_bin("Pubkey"); Botan::secure_vector<uint8_t> seed(privkey.begin(), privkey.end()); diff --git a/src/tests/test_elg.cpp b/src/tests/test_elg.cpp index abd4dd5fc..5bdd88c93 100644 --- a/src/tests/test_elg.cpp +++ b/src/tests/test_elg.cpp @@ -29,9 +29,9 @@ class ElGamal_KAT_Tests final : public PK_Encryption_Decryption_Test std::unique_ptr<Botan::Private_Key> load_private_key(const VarMap& vars) override { - const Botan::BigInt p = get_req_bn(vars, "P"); - const Botan::BigInt g = get_req_bn(vars, "G"); - const Botan::BigInt x = get_req_bn(vars, "X"); + const Botan::BigInt p = vars.get_req_bn("P"); + const Botan::BigInt g = vars.get_req_bn("G"); + const Botan::BigInt x = vars.get_req_bn("X"); const Botan::DL_Group grp(p, g); diff --git a/src/tests/test_fpe.cpp b/src/tests/test_fpe.cpp index e0cc1de01..dc2e82afc 100644 --- a/src/tests/test_fpe.cpp +++ b/src/tests/test_fpe.cpp @@ -21,11 +21,11 @@ class FPE_FE1_Tests final : public Text_Based_Test Test::Result run_one_test(const std::string&, const VarMap& vars) override { - const Botan::BigInt modulus = get_req_bn(vars, "Mod"); - const Botan::BigInt input = get_req_bn(vars, "In"); - const Botan::BigInt expected = get_req_bn(vars, "Out"); - const std::vector<uint8_t> key = get_req_bin(vars, "Key"); - const std::vector<uint8_t> tweak = get_req_bin(vars, "Tweak"); + const Botan::BigInt modulus = vars.get_req_bn("Mod"); + const Botan::BigInt input = vars.get_req_bn("In"); + const Botan::BigInt expected = vars.get_req_bn("Out"); + const std::vector<uint8_t> key = vars.get_req_bin("Key"); + const std::vector<uint8_t> tweak = vars.get_req_bin("Tweak"); Test::Result result("FPE_FE1"); diff --git a/src/tests/test_gost_3410.cpp b/src/tests/test_gost_3410.cpp index f5b2e1ec8..d99251075 100644 --- a/src/tests/test_gost_3410.cpp +++ b/src/tests/test_gost_3410.cpp @@ -28,16 +28,16 @@ class GOST_3410_2001_Verification_Tests final : public PK_Signature_Verification std::unique_ptr<Botan::Public_Key> load_public_key(const VarMap& vars) override { - const BigInt p = get_req_bn(vars, "P"); - const BigInt a = get_req_bn(vars, "A"); - const BigInt b = get_req_bn(vars, "B"); - const BigInt Gx = get_req_bn(vars, "Gx"); - const BigInt Gy = get_req_bn(vars, "Gy"); - const BigInt order = get_req_bn(vars, "Order"); - const BigInt cofactor = get_req_bn(vars, "Cofactor"); + const BigInt p = vars.get_req_bn("P"); + const BigInt a = vars.get_req_bn("A"); + const BigInt b = vars.get_req_bn("B"); + const BigInt Gx = vars.get_req_bn("Gx"); + const BigInt Gy = vars.get_req_bn("Gy"); + const BigInt order = vars.get_req_bn("Order"); + const BigInt cofactor = vars.get_req_bn("Cofactor"); - const BigInt Px = get_req_bn(vars, "Px"); - const BigInt Py = get_req_bn(vars, "Py"); + const BigInt Px = vars.get_req_bn("Px"); + const BigInt Py = vars.get_req_bn("Py"); Botan::EC_Group group(p, a, b, Gx, Gy, order, cofactor); @@ -49,7 +49,7 @@ class GOST_3410_2001_Verification_Tests final : public PK_Signature_Verification std::string default_padding(const VarMap& vars) const override { - const std::string hash = get_req_str(vars, "Hash"); + const std::string hash = vars.get_req_str("Hash"); if(hash == "Raw") return hash; return "EMSA1(" + hash + ")"; @@ -66,15 +66,15 @@ class GOST_3410_2001_Signature_Tests final : public PK_Signature_Generation_Test std::unique_ptr<Botan::Private_Key> load_private_key(const VarMap& vars) override { - const BigInt p = get_req_bn(vars, "P"); - const BigInt a = get_req_bn(vars, "A"); - const BigInt b = get_req_bn(vars, "B"); - const BigInt Gx = get_req_bn(vars, "Gx"); - const BigInt Gy = get_req_bn(vars, "Gy"); - const BigInt order = get_req_bn(vars, "Order"); - const BigInt cofactor = get_req_bn(vars, "Cofactor"); + const BigInt p = vars.get_req_bn("P"); + const BigInt a = vars.get_req_bn("A"); + const BigInt b = vars.get_req_bn("B"); + const BigInt Gx = vars.get_req_bn("Gx"); + const BigInt Gy = vars.get_req_bn("Gy"); + const BigInt order = vars.get_req_bn("Order"); + const BigInt cofactor = vars.get_req_bn("Cofactor"); - const BigInt x = get_req_bn(vars, "X"); + const BigInt x = vars.get_req_bn("X"); const Botan::OID oid("1.3.6.1.4.1.25258.2"); @@ -86,7 +86,7 @@ class GOST_3410_2001_Signature_Tests final : public PK_Signature_Generation_Test std::string default_padding(const VarMap& vars) const override { - const std::string hash = get_req_str(vars, "Hash"); + const std::string hash = vars.get_req_str("Hash"); if(hash == "Raw") return hash; return "EMSA1(" + hash + ")"; diff --git a/src/tests/test_hash.cpp b/src/tests/test_hash.cpp index 009d93ea1..b3d2d2599 100644 --- a/src/tests/test_hash.cpp +++ b/src/tests/test_hash.cpp @@ -81,8 +81,8 @@ class Hash_Function_Tests final : public Text_Based_Test Test::Result run_one_test(const std::string& algo, const VarMap& vars) override { - const std::vector<uint8_t> input = get_req_bin(vars, "In"); - const std::vector<uint8_t> expected = get_req_bin(vars, "Out"); + const std::vector<uint8_t> input = vars.get_req_bin("In"); + const std::vector<uint8_t> expected = vars.get_req_bin("Out"); Test::Result result(algo); diff --git a/src/tests/test_kdf.cpp b/src/tests/test_kdf.cpp index 6bc910d2a..24211a32d 100644 --- a/src/tests/test_kdf.cpp +++ b/src/tests/test_kdf.cpp @@ -36,10 +36,10 @@ class KDF_KAT_Tests final : public Text_Based_Test return result; } - const std::vector<uint8_t> salt = get_opt_bin(vars, "Salt"); - const std::vector<uint8_t> secret = get_req_bin(vars, "Secret"); - const std::vector<uint8_t> label = get_opt_bin(vars, "Label"); - const std::vector<uint8_t> expected = get_req_bin(vars, "Output"); + const std::vector<uint8_t> salt = vars.get_opt_bin("Salt"); + const std::vector<uint8_t> secret = vars.get_req_bin("Secret"); + const std::vector<uint8_t> label = vars.get_opt_bin("Label"); + const std::vector<uint8_t> expected = vars.get_req_bin("Output"); result.test_eq("name", kdf->name(), kdf_name); result.test_eq("derived key", kdf->derive_key(expected.size(), secret, salt, label), expected); @@ -69,10 +69,10 @@ class HKDF_Expand_Label_Tests final : public Text_Based_Test { Test::Result result("HKDF-Expand-Label(" + hash_name + ")"); - const std::vector<uint8_t> secret = get_req_bin(vars, "Secret"); - const std::vector<uint8_t> hashval = get_req_bin(vars, "HashValue"); - const std::string label = get_req_str(vars, "Label"); - const std::vector<uint8_t> expected = get_req_bin(vars, "Output"); + const std::vector<uint8_t> secret = vars.get_req_bin("Secret"); + const std::vector<uint8_t> hashval = vars.get_req_bin("HashValue"); + const std::string label = vars.get_req_str("Label"); + const std::vector<uint8_t> expected = vars.get_req_bin("Output"); Botan::secure_vector<uint8_t> output = Botan::hkdf_expand_label(hash_name, diff --git a/src/tests/test_keywrap.cpp b/src/tests/test_keywrap.cpp index de63d8067..49e84ebcf 100644 --- a/src/tests/test_keywrap.cpp +++ b/src/tests/test_keywrap.cpp @@ -31,9 +31,9 @@ class RFC3394_Keywrap_Tests final : public Text_Based_Test try { - const std::vector<uint8_t> expected = get_req_bin(vars, "Output"); - const std::vector<uint8_t> key = get_req_bin(vars, "Key"); - const std::vector<uint8_t> kek = get_req_bin(vars, "KEK"); + const std::vector<uint8_t> expected = vars.get_req_bin("Output"); + const std::vector<uint8_t> key = vars.get_req_bin("Key"); + const std::vector<uint8_t> kek = vars.get_req_bin("KEK"); const Botan::SymmetricKey kek_sym(kek); const Botan::secure_vector<uint8_t> key_l(key.begin(), key.end()); @@ -71,9 +71,9 @@ class NIST_Keywrap_Tests final : public Text_Based_Test if(typ != "KW" && typ != "KWP") throw Test_Error("Unknown type in NIST key wrap tests"); - const std::vector<uint8_t> expected = get_req_bin(vars, "Output"); - const std::vector<uint8_t> input = get_req_bin(vars, "Input"); - const std::vector<uint8_t> key = get_req_bin(vars, "Key"); + const std::vector<uint8_t> expected = vars.get_req_bin("Output"); + const std::vector<uint8_t> input = vars.get_req_bin("Input"); + const std::vector<uint8_t> key = vars.get_req_bin("Key"); std::unique_ptr<Botan::BlockCipher> bc = Botan::BlockCipher::create_or_throw("AES-" + std::to_string(key.size()*8)); @@ -138,8 +138,8 @@ class NIST_Keywrap_Invalid_Tests final : public Text_Based_Test if(typ != "KW" && typ != "KWP") throw Test_Error("Unknown type in NIST key wrap tests"); - const std::vector<uint8_t> input = get_req_bin(vars, "Input"); - const std::vector<uint8_t> key = get_req_bin(vars, "Key"); + const std::vector<uint8_t> input = vars.get_req_bin("Input"); + const std::vector<uint8_t> key = vars.get_req_bin("Key"); std::unique_ptr<Botan::BlockCipher> bc = Botan::BlockCipher::create_or_throw("AES-" + std::to_string(key.size()*8)); diff --git a/src/tests/test_mac.cpp b/src/tests/test_mac.cpp index 2f5afe783..e92736b6d 100644 --- a/src/tests/test_mac.cpp +++ b/src/tests/test_mac.cpp @@ -29,10 +29,10 @@ class Message_Auth_Tests final : public Text_Based_Test Test::Result run_one_test(const std::string& algo, const VarMap& vars) override { - const std::vector<uint8_t> key = get_req_bin(vars, "Key"); - const std::vector<uint8_t> input = get_req_bin(vars, "In"); - const std::vector<uint8_t> expected = get_req_bin(vars, "Out"); - const std::vector<uint8_t> iv = get_opt_bin(vars, "IV"); + const std::vector<uint8_t> key = vars.get_req_bin("Key"); + const std::vector<uint8_t> input = vars.get_req_bin("In"); + const std::vector<uint8_t> expected = vars.get_req_bin("Out"); + const std::vector<uint8_t> iv = vars.get_opt_bin("IV"); Test::Result result(algo); diff --git a/src/tests/test_mceliece.cpp b/src/tests/test_mceliece.cpp index bcc467344..ba463ebcd 100644 --- a/src/tests/test_mceliece.cpp +++ b/src/tests/test_mceliece.cpp @@ -44,14 +44,14 @@ class McEliece_Keygen_Encrypt_Test final : public Text_Based_Test Test::Result run_one_test(const std::string&, const VarMap& vars) override { - const std::vector<uint8_t> keygen_seed = get_req_bin(vars, "McElieceSeed"); - const std::vector<uint8_t> fprint_pub = get_req_bin(vars, "PublicKeyFingerprint"); - const std::vector<uint8_t> fprint_priv = get_req_bin(vars, "PrivateKeyFingerprint"); - const std::vector<uint8_t> encrypt_seed = get_req_bin(vars, "EncryptPRNGSeed"); - const std::vector<uint8_t> ciphertext = get_req_bin(vars, "Ciphertext"); - const std::vector<uint8_t> shared_key = get_req_bin(vars, "SharedKey"); - const size_t keygen_n = get_req_sz(vars, "KeyN"); - const size_t keygen_t = get_req_sz(vars, "KeyT"); + const std::vector<uint8_t> keygen_seed = vars.get_req_bin("McElieceSeed"); + const std::vector<uint8_t> fprint_pub = vars.get_req_bin("PublicKeyFingerprint"); + const std::vector<uint8_t> fprint_priv = vars.get_req_bin("PrivateKeyFingerprint"); + const std::vector<uint8_t> encrypt_seed = vars.get_req_bin("EncryptPRNGSeed"); + const std::vector<uint8_t> ciphertext = vars.get_req_bin("Ciphertext"); + const std::vector<uint8_t> shared_key = vars.get_req_bin("SharedKey"); + const size_t keygen_n = vars.get_req_sz("KeyN"); + const size_t keygen_t = vars.get_req_sz("KeyT"); Test::Result result("McEliece keygen"); result.start_timer(); diff --git a/src/tests/test_modes.cpp b/src/tests/test_modes.cpp index 6cdcd73b0..5fd0fc606 100644 --- a/src/tests/test_modes.cpp +++ b/src/tests/test_modes.cpp @@ -28,10 +28,10 @@ class Cipher_Mode_Tests final : public Text_Based_Test Test::Result run_one_test(const std::string& algo, const VarMap& vars) override { - const std::vector<uint8_t> key = get_req_bin(vars, "Key"); - const std::vector<uint8_t> nonce = get_opt_bin(vars, "Nonce"); - const std::vector<uint8_t> input = get_req_bin(vars, "In"); - const std::vector<uint8_t> expected = get_req_bin(vars, "Out"); + const std::vector<uint8_t> key = vars.get_req_bin("Key"); + const std::vector<uint8_t> nonce = vars.get_opt_bin("Nonce"); + const std::vector<uint8_t> input = vars.get_req_bin("In"); + const std::vector<uint8_t> expected = vars.get_req_bin("Out"); Test::Result result(algo); diff --git a/src/tests/test_newhope.cpp b/src/tests/test_newhope.cpp index 171ddd22e..38e1539ce 100644 --- a/src/tests/test_newhope.cpp +++ b/src/tests/test_newhope.cpp @@ -112,12 +112,12 @@ class NEWHOPE_Tests final : public Text_Based_Test { Test::Result result("NEWHOPE"); - const std::vector<uint8_t> h_output_a = get_req_bin(vars, "H_OutputA"); - const std::vector<uint8_t> h_output_b = get_req_bin(vars, "H_OutputB"); - const std::vector<uint8_t> shared_key = get_req_bin(vars, "SharedKey"); + const std::vector<uint8_t> h_output_a = vars.get_req_bin("H_OutputA"); + const std::vector<uint8_t> h_output_b = vars.get_req_bin("H_OutputB"); + const std::vector<uint8_t> shared_key = vars.get_req_bin("SharedKey"); - NEWHOPE_RNG drbg_a(get_req_bin(vars, "DRBG_SeedA")); - NEWHOPE_RNG drbg_b(get_req_bin(vars, "DRBG_SeedB")); + NEWHOPE_RNG drbg_a(vars.get_req_bin("DRBG_SeedA")); + NEWHOPE_RNG drbg_b(vars.get_req_bin("DRBG_SeedB")); Botan::SHA_3_256 sha3; diff --git a/src/tests/test_ocb.cpp b/src/tests/test_ocb.cpp index 490a52f4f..169a86dd9 100644 --- a/src/tests/test_ocb.cpp +++ b/src/tests/test_ocb.cpp @@ -121,11 +121,11 @@ class OCB_Wide_KAT_Tests final : public Text_Based_Test { Test::Result result("OCB wide block KAT"); - const std::vector<uint8_t> key = get_req_bin(vars, "Key"); - const std::vector<uint8_t> nonce = get_req_bin(vars, "Nonce"); - const std::vector<uint8_t> ad = get_req_bin(vars, "AD"); - const std::vector<uint8_t> input = get_req_bin(vars, "In"); - const std::vector<uint8_t> expected = get_req_bin(vars, "Out"); + const std::vector<uint8_t> key = vars.get_req_bin("Key"); + const std::vector<uint8_t> nonce = vars.get_req_bin("Nonce"); + const std::vector<uint8_t> ad = vars.get_req_bin("AD"); + const std::vector<uint8_t> input = vars.get_req_bin("In"); + const std::vector<uint8_t> expected = vars.get_req_bin("Out"); const size_t bs = key.size(); Botan::secure_vector<uint8_t> buf(input.begin(), input.end()); @@ -160,7 +160,7 @@ class OCB_Wide_Long_KAT_Tests final : public Text_Based_Test { Test::Result result("OCB wide block long test"); - const std::vector<uint8_t> expected = get_req_bin(vars, "Output"); + const std::vector<uint8_t> expected = vars.get_req_bin("Output"); std::unique_ptr<Botan::BlockCipher> cipher; size_t bs = 0; @@ -272,9 +272,9 @@ class OCB_Long_KAT_Tests final : public Text_Based_Test Test::Result run_one_test(const std::string&, const VarMap& vars) override { - const size_t keylen = get_req_sz(vars, "Keylen"); - const size_t taglen = get_req_sz(vars, "Taglen"); - const std::vector<uint8_t> expected = get_req_bin(vars, "Output"); + const size_t keylen = vars.get_req_sz("Keylen"); + const size_t taglen = vars.get_req_sz("Taglen"); + const std::vector<uint8_t> expected = vars.get_req_bin("Output"); // Test from RFC 7253 Appendix A diff --git a/src/tests/test_otp.cpp b/src/tests/test_otp.cpp index 4604356f9..cc96eea0f 100644 --- a/src/tests/test_otp.cpp +++ b/src/tests/test_otp.cpp @@ -40,10 +40,10 @@ class HOTP_KAT_Tests final : public Text_Based_Test if(!hash_test) return {result}; - const std::vector<uint8_t> key = get_req_bin(vars, "Key"); - const size_t otp = get_req_sz(vars, "OTP"); - const uint64_t counter = get_req_sz(vars, "Counter"); - const size_t digits = get_req_sz(vars, "Digits"); + const std::vector<uint8_t> key = vars.get_req_bin("Key"); + const size_t otp = vars.get_req_sz("OTP"); + const uint64_t counter = vars.get_req_sz("Counter"); + const size_t digits = vars.get_req_sz("Digits"); Botan::HOTP hotp(key, hash_algo, digits); @@ -95,11 +95,11 @@ class TOTP_KAT_Tests final : public Text_Based_Test if(!hash_test) return {result}; - const std::vector<uint8_t> key = get_req_bin(vars, "Key"); - const size_t otp = get_req_sz(vars, "OTP"); - const size_t digits = get_req_sz(vars, "Digits"); - const size_t timestep = get_req_sz(vars, "Timestep"); - const std::string timestamp = get_req_str(vars, "Timestamp"); + const std::vector<uint8_t> key = vars.get_req_bin("Key"); + const size_t otp = vars.get_req_sz("OTP"); + const size_t digits = vars.get_req_sz("Digits"); + const size_t timestep = vars.get_req_sz("Timestep"); + const std::string timestamp = vars.get_req_str("Timestamp"); Botan::TOTP totp(key, hash_algo, digits, timestep); diff --git a/src/tests/test_pad.cpp b/src/tests/test_pad.cpp index 2cf914600..c1f054ae4 100644 --- a/src/tests/test_pad.cpp +++ b/src/tests/test_pad.cpp @@ -21,9 +21,9 @@ class Cipher_Mode_Padding_Tests final : public Text_Based_Test Test::Result run_one_test(const std::string& header, const VarMap& vars) override { - const std::vector<uint8_t> input = get_req_bin(vars, "In"); - const std::vector<uint8_t> expected = get_opt_bin(vars, "Out"); - const size_t block_size = get_req_sz(vars, "Blocksize"); + const std::vector<uint8_t> input = vars.get_req_bin("In"); + const std::vector<uint8_t> expected = vars.get_opt_bin("Out"); + const size_t block_size = vars.get_req_sz("Blocksize"); std::string algo = header; diff --git a/src/tests/test_passhash.cpp b/src/tests/test_passhash.cpp index be194b553..7f8d6a4f9 100644 --- a/src/tests/test_passhash.cpp +++ b/src/tests/test_passhash.cpp @@ -27,11 +27,11 @@ class Bcrypt_Tests final : public Text_Based_Test Test::Result run_one_test(const std::string&, const VarMap& vars) override { // Encoded as binary so we can test binary inputs - const std::vector<uint8_t> password_vec = get_req_bin(vars, "Password"); + const std::vector<uint8_t> password_vec = vars.get_req_bin("Password"); const std::string password(reinterpret_cast<const char*>(password_vec.data()), password_vec.size()); - const std::string passhash = get_req_str(vars, "Passhash"); + const std::string passhash = vars.get_req_str("Passhash"); Test::Result result("bcrypt"); result.test_eq("correct hash accepted", Botan::check_bcrypt(password, passhash), true); @@ -81,12 +81,12 @@ class Passhash9_Tests final : public Text_Based_Test Test::Result run_one_test(const std::string&, const VarMap& vars) override { // Encoded as binary so we can test binary inputs - const std::vector<uint8_t> password_vec = get_req_bin(vars, "Password"); + const std::vector<uint8_t> password_vec = vars.get_req_bin("Password"); const std::string password(reinterpret_cast<const char*>(password_vec.data()), password_vec.size()); - const std::string passhash = get_req_str(vars, "Passhash"); - const std::size_t prf = get_req_sz(vars, "PRF"); + const std::string passhash = vars.get_req_str("Passhash"); + const std::size_t prf = vars.get_req_sz("PRF"); Test::Result result("passhash9"); diff --git a/src/tests/test_pbkdf.cpp b/src/tests/test_pbkdf.cpp index 6694e0522..eb344b2ea 100644 --- a/src/tests/test_pbkdf.cpp +++ b/src/tests/test_pbkdf.cpp @@ -30,11 +30,11 @@ class PBKDF_KAT_Tests final : public Text_Based_Test Test::Result run_one_test(const std::string& pbkdf_name, const VarMap& vars) override { - const size_t iterations = get_req_sz(vars, "Iterations"); - const std::vector<uint8_t> salt = get_req_bin(vars, "Salt"); - const std::string passphrase = get_req_str(vars, "Passphrase"); - const std::vector<uint8_t> expected = get_req_bin(vars, "Output"); - const size_t outlen = get_opt_sz(vars, "OutputLen", expected.size()); + const size_t iterations = vars.get_req_sz("Iterations"); + const std::vector<uint8_t> salt = vars.get_req_bin("Salt"); + const std::string passphrase = vars.get_req_str("Passphrase"); + const std::vector<uint8_t> expected = vars.get_req_bin("Output"); + const size_t outlen = vars.get_opt_sz("OutputLen", expected.size()); Test::Result result(pbkdf_name); std::unique_ptr<Botan::PBKDF> pbkdf(Botan::PBKDF::create(pbkdf_name)); @@ -70,12 +70,12 @@ class Scrypt_KAT_Tests final : public Text_Based_Test Test::Result run_one_test(const std::string&, const VarMap& vars) override { - const size_t N = get_req_sz(vars, "N"); - const size_t R = get_req_sz(vars, "R"); - const size_t P = get_req_sz(vars, "P"); - const std::vector<uint8_t> salt = get_req_bin(vars, "Salt"); - const std::string passphrase = get_req_str(vars, "Passphrase"); - const std::vector<uint8_t> expected = get_req_bin(vars, "Output"); + const size_t N = vars.get_req_sz("N"); + const size_t R = vars.get_req_sz("R"); + const size_t P = vars.get_req_sz("P"); + const std::vector<uint8_t> salt = vars.get_req_bin("Salt"); + const std::string passphrase = vars.get_req_str("Passphrase"); + const std::vector<uint8_t> expected = vars.get_req_bin("Output"); Test::Result result("scrypt"); diff --git a/src/tests/test_pk_pad.cpp b/src/tests/test_pk_pad.cpp index ecfdba5d5..babe5242d 100644 --- a/src/tests/test_pk_pad.cpp +++ b/src/tests/test_pk_pad.cpp @@ -40,9 +40,9 @@ class EME_Decoding_Tests final : public Text_Based_Test return result; } - const std::vector<uint8_t> ciphertext = get_req_bin(vars, "RawCiphertext"); - const std::vector<uint8_t> plaintext = get_opt_bin(vars, "Plaintext"); - const bool is_valid = get_req_bool(vars, "ValidInput"); + const std::vector<uint8_t> ciphertext = vars.get_req_bin("RawCiphertext"); + const std::vector<uint8_t> plaintext = vars.get_opt_bin("Plaintext"); + const bool is_valid = vars.get_req_bool("ValidInput"); if(is_valid == false) { diff --git a/src/tests/test_pubkey.cpp b/src/tests/test_pubkey.cpp index ea794b9ba..8860aeed2 100644 --- a/src/tests/test_pubkey.cpp +++ b/src/tests/test_pubkey.cpp @@ -88,7 +88,7 @@ std::string PK_Test::choose_padding(const VarMap& vars, { if(pad_hdr != "") return pad_hdr; - return get_opt_str(vars, "Padding", this->default_padding(vars)); + return vars.get_opt_str("Padding", this->default_padding(vars)); } std::vector<std::string> PK_Test::possible_providers(const std::string& /*params*/) @@ -99,8 +99,8 @@ std::vector<std::string> PK_Test::possible_providers(const std::string& /*params Test::Result PK_Signature_Generation_Test::run_one_test(const std::string& pad_hdr, const VarMap& vars) { - const std::vector<uint8_t> message = get_req_bin(vars, "Msg"); - const std::vector<uint8_t> signature = get_req_bin(vars, "Signature"); + const std::vector<uint8_t> message = vars.get_req_bin("Msg"); + const std::vector<uint8_t> signature = vars.get_req_bin("Signature"); const std::string padding = choose_padding(vars, pad_hdr); Test::Result result(algo_name() + "/" + padding + " signature generation"); @@ -143,9 +143,9 @@ PK_Signature_Generation_Test::run_one_test(const std::string& pad_hdr, const Var for(auto const& sign_provider : possible_providers(algo_name())) { std::unique_ptr<Botan::RandomNumberGenerator> rng; - if(vars.count("Nonce")) + if(vars.has_key("Nonce")) { - rng.reset(test_rng(get_req_bin(vars, "Nonce"))); + rng.reset(test_rng(vars.get_req_bin("Nonce"))); } std::unique_ptr<Botan::PK_Signer> signer; @@ -187,11 +187,11 @@ PK_Signature_Generation_Test::run_one_test(const std::string& pad_hdr, const Var Test::Result PK_Signature_Verification_Test::run_one_test(const std::string& pad_hdr, const VarMap& vars) { - const std::vector<uint8_t> message = get_req_bin(vars, "Msg"); - const std::vector<uint8_t> signature = get_req_bin(vars, "Signature"); + const std::vector<uint8_t> message = vars.get_req_bin("Msg"); + const std::vector<uint8_t> signature = vars.get_req_bin("Signature"); const std::string padding = choose_padding(vars, pad_hdr); - const bool expected_valid = (get_opt_sz(vars, "Valid", 1) == 1); + const bool expected_valid = (vars.get_opt_sz("Valid", 1) == 1); std::unique_ptr<Botan::Public_Key> pubkey = load_public_key(vars); @@ -231,10 +231,10 @@ Test::Result PK_Signature_NonVerification_Test::run_one_test(const std::string& pad_hdr, const VarMap& vars) { const std::string padding = choose_padding(vars, pad_hdr); - const std::vector<uint8_t> message = get_req_bin(vars, "Msg"); + const std::vector<uint8_t> message = vars.get_req_bin("Msg"); std::unique_ptr<Botan::Public_Key> pubkey = load_public_key(vars); - const std::vector<uint8_t> invalid_signature = get_req_bin(vars, "InvalidSignature"); + const std::vector<uint8_t> invalid_signature = vars.get_req_bin("InvalidSignature"); Test::Result result(algo_name() + "/" + padding + " verify invalid signature"); @@ -259,8 +259,8 @@ PK_Signature_NonVerification_Test::run_one_test(const std::string& pad_hdr, cons Test::Result PK_Encryption_Decryption_Test::run_one_test(const std::string& pad_hdr, const VarMap& vars) { - const std::vector<uint8_t> plaintext = get_req_bin(vars, "Msg"); - const std::vector<uint8_t> ciphertext = get_req_bin(vars, "Ciphertext"); + const std::vector<uint8_t> plaintext = vars.get_req_bin("Msg"); + const std::vector<uint8_t> ciphertext = vars.get_req_bin("Ciphertext"); const std::string padding = choose_padding(vars, pad_hdr); Test::Result result(algo_name() + (padding.empty() ? padding : "/" + padding) + " encryption"); @@ -315,9 +315,9 @@ PK_Encryption_Decryption_Test::run_one_test(const std::string& pad_hdr, const Va } std::unique_ptr<Botan::RandomNumberGenerator> kat_rng; - if(vars.count("Nonce")) + if(vars.has_key("Nonce")) { - kat_rng.reset(test_rng(get_req_bin(vars, "Nonce"))); + kat_rng.reset(test_rng(vars.get_req_bin("Nonce"))); } if(padding == "Raw") @@ -360,8 +360,8 @@ PK_Encryption_Decryption_Test::run_one_test(const std::string& pad_hdr, const Va Test::Result PK_Decryption_Test::run_one_test(const std::string& pad_hdr, const VarMap& vars) { - const std::vector<uint8_t> plaintext = get_req_bin(vars, "Msg"); - const std::vector<uint8_t> ciphertext = get_req_bin(vars, "Ciphertext"); + const std::vector<uint8_t> plaintext = vars.get_req_bin("Msg"); + const std::vector<uint8_t> ciphertext = vars.get_req_bin("Ciphertext"); const std::string padding = choose_padding(vars, pad_hdr); Test::Result result(algo_name() + (padding.empty() ? padding : "/" + padding) + " decryption"); @@ -402,10 +402,10 @@ PK_Decryption_Test::run_one_test(const std::string& pad_hdr, const VarMap& vars) Test::Result PK_KEM_Test::run_one_test(const std::string&, const VarMap& vars) { - const std::vector<uint8_t> K = get_req_bin(vars, "K"); - const std::vector<uint8_t> C0 = get_req_bin(vars, "C0"); - const std::vector<uint8_t> salt = get_opt_bin(vars, "Salt"); - const std::string kdf = get_req_str(vars, "KDF"); + const std::vector<uint8_t> K = vars.get_req_bin("K"); + const std::vector<uint8_t> C0 = vars.get_req_bin("C0"); + const std::vector<uint8_t> salt = vars.get_opt_bin("Salt"); + const std::string kdf = vars.get_req_str("KDF"); Test::Result result(algo_name() + "/" + kdf + " KEM"); @@ -426,7 +426,7 @@ Test::Result PK_KEM_Test::run_one_test(const std::string&, const VarMap& vars) return result; } - Fixed_Output_RNG fixed_output_rng(get_req_bin(vars, "R")); + Fixed_Output_RNG fixed_output_rng(vars.get_req_bin("R")); Botan::secure_vector<uint8_t> produced_encap_key, shared_key; enc->encrypt(produced_encap_key, @@ -462,8 +462,8 @@ Test::Result PK_KEM_Test::run_one_test(const std::string&, const VarMap& vars) Test::Result PK_Key_Agreement_Test::run_one_test(const std::string& header, const VarMap& vars) { - const std::vector<uint8_t> shared = get_req_bin(vars, "K"); - const std::string kdf = get_opt_str(vars, "KDF", default_kdf(vars)); + const std::vector<uint8_t> shared = vars.get_req_bin("K"); + const std::string kdf = vars.get_opt_str("KDF", default_kdf(vars)); Test::Result result(algo_name() + "/" + kdf + (header.empty() ? header : " " + header) + @@ -472,7 +472,7 @@ Test::Result PK_Key_Agreement_Test::run_one_test(const std::string& header, cons std::unique_ptr<Botan::Private_Key> privkey = load_our_key(header, vars); const std::vector<uint8_t> pubkey = load_their_key(header, vars); - const size_t key_len = get_opt_sz(vars, "OutLen", 0); + const size_t key_len = vars.get_opt_sz("OutLen", 0); for(auto const& provider : possible_providers(algo_name())) { diff --git a/src/tests/test_rfc6979.cpp b/src/tests/test_rfc6979.cpp index b9de7fcb9..e65d94c78 100644 --- a/src/tests/test_rfc6979.cpp +++ b/src/tests/test_rfc6979.cpp @@ -24,10 +24,10 @@ class RFC6979_KAT_Tests final : public Text_Based_Test Test::Result run_one_test(const std::string& hash, const VarMap& vars) override { - const BigInt Q = get_req_bn(vars, "Q"); - const BigInt X = get_req_bn(vars, "X"); - const BigInt H = get_req_bn(vars, "H"); - const BigInt K = get_req_bn(vars, "K"); + const BigInt Q = vars.get_req_bn("Q"); + const BigInt X = vars.get_req_bn("X"); + const BigInt H = vars.get_req_bn("H"); + const BigInt K = vars.get_req_bn("K"); Test::Result result("RFC 6979 nonce generation"); diff --git a/src/tests/test_rng_kat.cpp b/src/tests/test_rng_kat.cpp index e1d4ded36..0c124cdf2 100644 --- a/src/tests/test_rng_kat.cpp +++ b/src/tests/test_rng_kat.cpp @@ -31,12 +31,12 @@ class HMAC_DRBG_Tests final : public Text_Based_Test Test::Result run_one_test(const std::string& algo, const VarMap& vars) override { - const std::vector<uint8_t> seed_input = get_req_bin(vars, "EntropyInput"); - const std::vector<uint8_t> reseed_input = get_req_bin(vars, "EntropyInputReseed"); - const std::vector<uint8_t> expected = get_req_bin(vars, "Out"); + const std::vector<uint8_t> seed_input = vars.get_req_bin("EntropyInput"); + const std::vector<uint8_t> reseed_input = vars.get_req_bin("EntropyInputReseed"); + const std::vector<uint8_t> expected = vars.get_req_bin("Out"); - const std::vector<uint8_t> ad1 = get_opt_bin(vars, "AdditionalInput1"); - const std::vector<uint8_t> ad2 = get_opt_bin(vars, "AdditionalInput2"); + const std::vector<uint8_t> ad1 = vars.get_opt_bin("AdditionalInput1"); + const std::vector<uint8_t> ad2 = vars.get_opt_bin("AdditionalInput2"); Test::Result result("HMAC_DRBG(" + algo + ")"); @@ -81,12 +81,12 @@ class ChaCha_RNG_Tests final : public Text_Based_Test Test::Result run_one_test(const std::string&, const VarMap& vars) override { - const std::vector<uint8_t> seed_input = get_req_bin(vars, "EntropyInput"); - const std::vector<uint8_t> reseed_input = get_req_bin(vars, "EntropyInputReseed"); - const std::vector<uint8_t> expected = get_req_bin(vars, "Out"); + const std::vector<uint8_t> seed_input = vars.get_req_bin("EntropyInput"); + const std::vector<uint8_t> reseed_input = vars.get_req_bin("EntropyInputReseed"); + const std::vector<uint8_t> expected = vars.get_req_bin("Out"); - const std::vector<uint8_t> ad1 = get_opt_bin(vars, "AdditionalInput1"); - const std::vector<uint8_t> ad2 = get_opt_bin(vars, "AdditionalInput2"); + const std::vector<uint8_t> ad1 = vars.get_opt_bin("AdditionalInput1"); + const std::vector<uint8_t> ad2 = vars.get_opt_bin("AdditionalInput2"); Test::Result result("ChaCha_RNG"); diff --git a/src/tests/test_rsa.cpp b/src/tests/test_rsa.cpp index 88c086812..32e4ab9e6 100644 --- a/src/tests/test_rsa.cpp +++ b/src/tests/test_rsa.cpp @@ -18,6 +18,23 @@ namespace { #if defined(BOTAN_HAS_RSA) +std::unique_ptr<Botan::Private_Key> load_rsa_private_key(const VarMap& vars) + { + const BigInt p = vars.get_req_bn("P"); + const BigInt q = vars.get_req_bn("Q"); + const BigInt e = vars.get_req_bn("E"); + + return std::unique_ptr<Botan::Private_Key>(new Botan::RSA_PrivateKey(p, q, e)); + } + +std::unique_ptr<Botan::Public_Key> load_rsa_public_key(const VarMap& vars) + { + const BigInt n = vars.get_req_bn("N"); + const BigInt e = vars.get_req_bn("E"); + + return std::unique_ptr<Botan::Public_Key>(new Botan::RSA_PublicKey(n, e)); + } + class RSA_ES_KAT_Tests final : public PK_Encryption_Decryption_Test { public: @@ -30,12 +47,7 @@ class RSA_ES_KAT_Tests final : public PK_Encryption_Decryption_Test std::unique_ptr<Botan::Private_Key> load_private_key(const VarMap& vars) override { - const BigInt p = get_req_bn(vars, "P"); - const BigInt q = get_req_bn(vars, "Q"); - const BigInt e = get_req_bn(vars, "E"); - - std::unique_ptr<Botan::Private_Key> key(new Botan::RSA_PrivateKey(p, q, e)); - return key; + return load_rsa_private_key(vars); } }; @@ -54,12 +66,7 @@ class RSA_Decryption_KAT_Tests final : public PK_Decryption_Test std::unique_ptr<Botan::Private_Key> load_private_key(const VarMap& vars) override { - const BigInt p = get_req_bn(vars, "P"); - const BigInt q = get_req_bn(vars, "Q"); - const BigInt e = get_req_bn(vars, "E"); - - std::unique_ptr<Botan::Private_Key> key(new Botan::RSA_PrivateKey(p, q, e)); - return key; + return load_rsa_private_key(vars); } }; @@ -74,12 +81,7 @@ class RSA_KEM_Tests final : public PK_KEM_Test std::unique_ptr<Botan::Private_Key> load_private_key(const VarMap& vars) override { - const BigInt p = get_req_bn(vars, "P"); - const BigInt q = get_req_bn(vars, "Q"); - const BigInt e = get_req_bn(vars, "E"); - - std::unique_ptr<Botan::Private_Key> key(new Botan::RSA_PrivateKey(p, q, e)); - return key; + return load_rsa_private_key(vars); } }; @@ -101,12 +103,7 @@ class RSA_Signature_KAT_Tests final : public PK_Signature_Generation_Test std::unique_ptr<Botan::Private_Key> load_private_key(const VarMap& vars) override { - const BigInt p = get_req_bn(vars, "P"); - const BigInt q = get_req_bn(vars, "Q"); - const BigInt e = get_req_bn(vars, "E"); - - std::unique_ptr<Botan::Private_Key> key(new Botan::RSA_PrivateKey(p, q, e)); - return key; + return load_rsa_private_key(vars); } }; @@ -120,10 +117,10 @@ class RSA_PSS_KAT_Tests final : public PK_Signature_Generation_Test "P,Q,E,Hash,Nonce,Msg,Signature", "") {} - std::string default_padding(const VarMap& var) const override + std::string default_padding(const VarMap& vars) const override { - const std::string hash_name = get_req_str(var, "Hash"); - const size_t salt_size = get_req_bin(var, "Nonce").size(); + const std::string hash_name = vars.get_req_str("Hash"); + const size_t salt_size = vars.get_req_bin("Nonce").size(); return "PSSR(" + hash_name + ",MGF1," + std::to_string(salt_size) + ")"; } @@ -134,12 +131,7 @@ class RSA_PSS_KAT_Tests final : public PK_Signature_Generation_Test std::unique_ptr<Botan::Private_Key> load_private_key(const VarMap& vars) override { - const BigInt p = get_req_bn(vars, "P"); - const BigInt q = get_req_bn(vars, "Q"); - const BigInt e = get_req_bn(vars, "E"); - - std::unique_ptr<Botan::Private_Key> key(new Botan::RSA_PrivateKey(p, q, e)); - return key; + return load_rsa_private_key(vars); } }; @@ -153,10 +145,10 @@ class RSA_PSS_Raw_KAT_Tests final : public PK_Signature_Generation_Test "P,Q,E,Hash,Nonce,Msg,Signature", "") {} - std::string default_padding(const VarMap& var) const override + std::string default_padding(const VarMap& vars) const override { - const std::string hash_name = get_req_str(var, "Hash"); - const size_t salt_size = get_req_bin(var, "Nonce").size(); + const std::string hash_name = vars.get_req_str("Hash"); + const size_t salt_size = vars.get_req_bin("Nonce").size(); return "PSSR_Raw(" + hash_name + ",MGF1," + std::to_string(salt_size) + ")"; } @@ -167,12 +159,7 @@ class RSA_PSS_Raw_KAT_Tests final : public PK_Signature_Generation_Test std::unique_ptr<Botan::Private_Key> load_private_key(const VarMap& vars) override { - const BigInt p = get_req_bn(vars, "P"); - const BigInt q = get_req_bn(vars, "Q"); - const BigInt e = get_req_bn(vars, "E"); - - std::unique_ptr<Botan::Private_Key> key(new Botan::RSA_PrivateKey(p, q, e)); - return key; + return load_rsa_private_key(vars); } }; @@ -192,11 +179,7 @@ class RSA_Signature_Verify_Tests final : public PK_Signature_Verification_Test std::unique_ptr<Botan::Public_Key> load_public_key(const VarMap& vars) override { - const BigInt n = get_req_bn(vars, "N"); - const BigInt e = get_req_bn(vars, "E"); - - std::unique_ptr<Botan::Public_Key> key(new Botan::RSA_PublicKey(n, e)); - return key; + return load_rsa_public_key(vars); } }; @@ -216,10 +199,7 @@ class RSA_Signature_Verify_Invalid_Tests final : public PK_Signature_NonVerifica std::unique_ptr<Botan::Public_Key> load_public_key(const VarMap& vars) override { - const BigInt n = get_req_bn(vars, "N"); - const BigInt e = get_req_bn(vars, "E"); - std::unique_ptr<Botan::Public_Key> key(new Botan::RSA_PublicKey(n, e)); - return key; + return load_rsa_public_key(vars); } }; diff --git a/src/tests/test_siv.cpp b/src/tests/test_siv.cpp index 99fb35f9b..d7380a9ba 100644 --- a/src/tests/test_siv.cpp +++ b/src/tests/test_siv.cpp @@ -25,12 +25,12 @@ class SIV_Tests final : public Text_Based_Test Test::Result run_one_test(const std::string& algo, const VarMap& vars) override { - const std::vector<uint8_t> key = get_req_bin(vars, "Key"); - const std::vector<uint8_t> nonce = get_opt_bin(vars, "Nonce"); - const std::vector<uint8_t> input = get_req_bin(vars, "In"); - const std::vector<uint8_t> expected = get_req_bin(vars, "Out"); + const std::vector<uint8_t> key = vars.get_req_bin("Key"); + const std::vector<uint8_t> nonce = vars.get_opt_bin("Nonce"); + const std::vector<uint8_t> input = vars.get_req_bin("In"); + const std::vector<uint8_t> expected = vars.get_req_bin("Out"); const std::vector<std::string> ad_list = - Botan::split_on(get_req_str(vars, "ADs"), ','); + Botan::split_on(vars.get_req_str("ADs"), ','); Test::Result result(algo + "/SIV"); diff --git a/src/tests/test_sm2.cpp b/src/tests/test_sm2.cpp index c4ddf6ddf..333e198b7 100644 --- a/src/tests/test_sm2.cpp +++ b/src/tests/test_sm2.cpp @@ -19,6 +19,24 @@ namespace Botan_Tests { namespace { +std::unique_ptr<Botan::Private_Key> load_sm2_private_key(const VarMap& vars) + { + // group params + const BigInt p = vars.get_req_bn("P"); + const BigInt a = vars.get_req_bn("A"); + const BigInt b = vars.get_req_bn("B"); + const BigInt xG = vars.get_req_bn("xG"); + const BigInt yG = vars.get_req_bn("yG"); + const BigInt order = vars.get_req_bn("Order"); + const BigInt cofactor = vars.get_req_bn("Cofactor"); + const BigInt x = vars.get_req_bn("x"); + + Botan::EC_Group domain(p, a, b, xG, yG, order, cofactor); + + Botan::Null_RNG null_rng; + return std::unique_ptr<Botan::Private_Key>(new Botan::SM2_Signature_PrivateKey(null_rng, domain, x)); + } + class SM2_Signature_KAT_Tests final : public PK_Signature_Generation_Test { public: @@ -31,7 +49,7 @@ class SM2_Signature_KAT_Tests final : public PK_Signature_Generation_Test std::string default_padding(const VarMap& vars) const override { - return get_req_str(vars, "Ident") + "," + get_opt_str(vars, "Hash", "SM3"); + return vars.get_req_str("Ident") + "," + vars.get_opt_str("Hash", "SM3"); } Botan::RandomNumberGenerator* test_rng(const std::vector<uint8_t>& nonce) const override @@ -41,21 +59,7 @@ class SM2_Signature_KAT_Tests final : public PK_Signature_Generation_Test std::unique_ptr<Botan::Private_Key> load_private_key(const VarMap& vars) override { - // group params - const BigInt p = get_req_bn(vars, "P"); - const BigInt a = get_req_bn(vars, "A"); - const BigInt b = get_req_bn(vars, "B"); - const BigInt xG = get_req_bn(vars, "xG"); - const BigInt yG = get_req_bn(vars, "yG"); - const BigInt order = get_req_bn(vars, "Order"); - const BigInt cofactor = get_req_bn(vars, "Cofactor"); - const BigInt x = get_req_bn(vars, "x"); - - Botan::EC_Group domain(p, a, b, xG, yG, order, cofactor); - - Botan::Null_RNG null_rng; - std::unique_ptr<Botan::Private_Key> key(new Botan::SM2_Signature_PrivateKey(null_rng, domain, x)); - return key; + return load_sm2_private_key(vars); } }; @@ -73,7 +77,7 @@ class SM2_Encryption_KAT_Tests final : public PK_Encryption_Decryption_Test std::string default_padding(const VarMap& vars) const override { - return get_opt_str(vars, "Hash", "SM3"); + return vars.get_opt_str("Hash", "SM3"); } bool clear_between_callbacks() const override { return false; } @@ -85,21 +89,7 @@ class SM2_Encryption_KAT_Tests final : public PK_Encryption_Decryption_Test std::unique_ptr<Botan::Private_Key> load_private_key(const VarMap& vars) override { - // group params - const BigInt p = get_req_bn(vars, "P"); - const BigInt a = get_req_bn(vars, "A"); - const BigInt b = get_req_bn(vars, "B"); - const BigInt xG = get_req_bn(vars, "xG"); - const BigInt yG = get_req_bn(vars, "yG"); - const BigInt order = get_req_bn(vars, "Order"); - const BigInt cofactor = get_req_bn(vars, "Cofactor"); - const BigInt x = get_req_bn(vars, "x"); - - Botan::EC_Group domain(p, a, b, xG, yG, order, cofactor); - - Botan::Null_RNG null_rng; - std::unique_ptr<Botan::Private_Key> key(new Botan::SM2_Encryption_PrivateKey(null_rng, domain, x)); - return key; + return load_sm2_private_key(vars); } }; diff --git a/src/tests/test_stream.cpp b/src/tests/test_stream.cpp index 219d58e4b..1f26a5cfd 100644 --- a/src/tests/test_stream.cpp +++ b/src/tests/test_stream.cpp @@ -21,11 +21,11 @@ class Stream_Cipher_Tests final : public Text_Based_Test Test::Result run_one_test(const std::string& algo, const VarMap& vars) override { - const std::vector<uint8_t> key = get_req_bin(vars, "Key"); - const std::vector<uint8_t> expected = get_req_bin(vars, "Out"); - const std::vector<uint8_t> nonce = get_opt_bin(vars, "Nonce"); - const size_t seek = get_opt_sz(vars, "Seek", 0); - std::vector<uint8_t> input = get_opt_bin(vars, "In"); + const std::vector<uint8_t> key = vars.get_req_bin("Key"); + const std::vector<uint8_t> expected = vars.get_req_bin("Out"); + const std::vector<uint8_t> nonce = vars.get_opt_bin("Nonce"); + const size_t seek = vars.get_opt_sz("Seek", 0); + std::vector<uint8_t> input = vars.get_opt_bin("In"); if(input.empty()) { diff --git a/src/tests/test_tls.cpp b/src/tests/test_tls.cpp index 702919290..a64a3fa48 100644 --- a/src/tests/test_tls.cpp +++ b/src/tests/test_tls.cpp @@ -79,8 +79,8 @@ class TLS_CBC_Padding_Tests final : public Text_Based_Test Test::Result run_one_test(const std::string&, const VarMap& vars) override { - const std::vector<uint8_t> record = get_req_bin(vars, "Record"); - const size_t output = get_req_sz(vars, "Output"); + const std::vector<uint8_t> record = vars.get_req_bin("Record"); + const size_t output = vars.get_req_sz("Output"); uint16_t res = Botan::TLS::check_tls_cbc_padding(record.data(), record.size()); @@ -163,10 +163,10 @@ class TLS_CBC_Tests final : public Text_Based_Test { Test::Result result("TLS CBC"); - const size_t block_size = get_req_sz(vars, "Blocksize"); - const size_t mac_len = get_req_sz(vars, "MACsize"); - const std::vector<uint8_t> record = get_req_bin(vars, "Record"); - const bool is_valid = get_req_sz(vars, "Valid") == 1; + const size_t block_size = vars.get_req_sz("Blocksize"); + const size_t mac_len = vars.get_req_sz("MACsize"); + const std::vector<uint8_t> record = vars.get_req_bin("Record"); + const bool is_valid = vars.get_req_sz("Valid") == 1; // todo test permutations bool explicit_iv = true; diff --git a/src/tests/test_tls_messages.cpp b/src/tests/test_tls_messages.cpp index 68318eb8d..038b79085 100644 --- a/src/tests/test_tls_messages.cpp +++ b/src/tests/test_tls_messages.cpp @@ -51,11 +51,11 @@ class TLS_Message_Parsing_Test final : public Text_Based_Test Test::Result run_one_test(const std::string& algo, const VarMap& vars) override { - const std::vector<uint8_t> buffer = get_req_bin(vars, "Buffer"); - const std::vector<uint8_t> protocol = get_opt_bin(vars, "Protocol"); - const std::vector<uint8_t> ciphersuite = get_opt_bin(vars, "Ciphersuite"); - const std::string exception = get_req_str(vars, "Exception"); - const std::string expected_name = get_opt_str(vars, "Name", ""); + const std::vector<uint8_t> buffer = vars.get_req_bin("Buffer"); + const std::vector<uint8_t> protocol = vars.get_opt_bin("Protocol"); + const std::vector<uint8_t> ciphersuite = vars.get_opt_bin("Ciphersuite"); + const std::string exception = vars.get_req_str("Exception"); + const std::string expected_name = vars.get_opt_str("Name", ""); const bool is_positive_test = exception.empty(); Test::Result result(algo + " parsing"); @@ -71,7 +71,7 @@ class TLS_Message_Parsing_Test final : public Text_Based_Test } else if(algo == "client_hello") { - const std::string extensions = get_req_str(vars, "AdditionalData"); + const std::string extensions = vars.get_req_str("AdditionalData"); Botan::TLS::Protocol_Version pv(protocol[0], protocol[1]); Botan::TLS::Client_Hello message(buffer); result.test_eq("Protocol version", message.version().to_string(), pv.to_string()); @@ -98,7 +98,7 @@ class TLS_Message_Parsing_Test final : public Text_Based_Test } else if(algo == "server_hello") { - const std::string extensions = get_req_str(vars, "AdditionalData"); + const std::string extensions = vars.get_req_str("AdditionalData"); Botan::TLS::Protocol_Version pv(protocol[0], protocol[1]); Botan::TLS::Ciphersuite cs = Botan::TLS::Ciphersuite::by_id(Botan::make_uint16(ciphersuite[0], ciphersuite[1])); Botan::TLS::Server_Hello message(buffer); diff --git a/src/tests/test_utils.cpp b/src/tests/test_utils.cpp index ee5f06187..d3b00e897 100644 --- a/src/tests/test_utils.cpp +++ b/src/tests/test_utils.cpp @@ -41,10 +41,10 @@ class Utility_Function_Tests final : public Text_Based_Test if(algo == "round_up") { - const size_t x = get_req_sz(vars, "In1"); - const size_t to = get_req_sz(vars, "In2"); + const size_t x = vars.get_req_sz("In1"); + const size_t to = vars.get_req_sz("In2"); - result.test_eq(algo, Botan::round_up(x, to), get_req_sz(vars, "Out")); + result.test_eq(algo, Botan::round_up(x, to), vars.get_req_sz("Out")); try { @@ -55,10 +55,10 @@ class Utility_Function_Tests final : public Text_Based_Test } else if(algo == "round_down") { - const size_t x = get_req_sz(vars, "In1"); - const size_t to = get_req_sz(vars, "In2"); + const size_t x = vars.get_req_sz("In1"); + const size_t to = vars.get_req_sz("In2"); - result.test_eq(algo, Botan::round_down<size_t>(x, to), get_req_sz(vars, "Out")); + result.test_eq(algo, Botan::round_down<size_t>(x, to), vars.get_req_sz("Out")); result.test_eq(algo, Botan::round_down<size_t>(x, 0), x); } @@ -228,8 +228,8 @@ class Poly_Double_Tests final : public Text_Based_Test Test::Result run_one_test(const std::string&, const VarMap& vars) override { Test::Result result("Polynomial doubling"); - const std::vector<uint8_t> in = get_req_bin(vars, "In"); - const std::vector<uint8_t> out = get_req_bin(vars, "Out"); + const std::vector<uint8_t> in = vars.get_req_bin("In"); + const std::vector<uint8_t> out = vars.get_req_bin("Out"); std::vector<uint8_t> b = in; Botan::poly_double_n(b.data(), b.size()); @@ -266,7 +266,7 @@ class Date_Format_Tests final : public Text_Based_Test Test::Result run_one_test(const std::string& type, const VarMap& vars) override { - const std::string date_str = get_req_str(vars, "Date"); + const std::string date_str = vars.get_req_str("Date"); Test::Result result("Date parsing"); const std::vector<uint32_t> d = parse_date(date_str); @@ -332,13 +332,13 @@ class Base64_Tests final : public Text_Based_Test Test::Result result("Base64"); const bool is_valid = (type == "valid"); - const std::string base64 = get_req_str(vars, "Base64"); + const std::string base64 = vars.get_req_str("Base64"); try { if(is_valid) { - const std::vector<uint8_t> binary = get_req_bin(vars, "Binary"); + const std::vector<uint8_t> binary = vars.get_req_bin("Binary"); result.test_eq("base64 decoding", Botan::base64_decode(base64), binary); result.test_eq("base64 encoding", Botan::base64_encode(binary), base64); } @@ -409,8 +409,8 @@ class Charset_Tests final : public Text_Based_Test { Test::Result result("Charset"); - const std::vector<uint8_t> in = get_req_bin(vars, "In"); - const std::vector<uint8_t> expected = get_req_bin(vars, "Out"); + const std::vector<uint8_t> in = vars.get_req_bin("In"); + const std::vector<uint8_t> expected = vars.get_req_bin("Out"); const std::string in_str(in.begin(), in.end()); @@ -533,8 +533,8 @@ class Hostname_Tests final : public Text_Based_Test { Test::Result result("Hostname Matching"); - const std::string issued = get_req_str(vars, "Issued"); - const std::string hostname = get_req_str(vars, "Hostname"); + const std::string issued = vars.get_req_str("Issued"); + const std::string hostname = vars.get_req_str("Hostname"); const bool expected = (type == "Invalid") ? false : true; const std::string what = hostname + ((expected == true) ? diff --git a/src/tests/test_workfactor.cpp b/src/tests/test_workfactor.cpp index c16041cf0..8e6c80f7c 100644 --- a/src/tests/test_workfactor.cpp +++ b/src/tests/test_workfactor.cpp @@ -21,8 +21,8 @@ class PK_Workfactor_Tests final : public Text_Based_Test Test::Result run_one_test(const std::string& type, const VarMap& vars) override { - const size_t param_size = get_req_sz(vars, "ParamSize"); - const size_t exp_output = get_req_sz(vars, "Workfactor"); + const size_t param_size = vars.get_req_sz("ParamSize"); + const size_t exp_output = vars.get_req_sz("Workfactor"); size_t output = 0; diff --git a/src/tests/test_x509_dn.cpp b/src/tests/test_x509_dn.cpp index 378e7b109..662c11e74 100644 --- a/src/tests/test_x509_dn.cpp +++ b/src/tests/test_x509_dn.cpp @@ -21,8 +21,8 @@ class X509_DN_Comparisons_Tests final : public Text_Based_Test Test::Result run_one_test(const std::string& type, const VarMap& vars) override { - const std::vector<uint8_t> dn_bits1 = get_req_bin(vars, "DN1"); - const std::vector<uint8_t> dn_bits2 = get_req_bin(vars, "DN2"); + const std::vector<uint8_t> dn_bits1 = vars.get_req_bin("DN1"); + const std::vector<uint8_t> dn_bits2 = vars.get_req_bin("DN2"); const bool dn_same = (type == "Equal"); Test::Result result("X509_DN comparisons"); diff --git a/src/tests/test_xmss.cpp b/src/tests/test_xmss.cpp index f8610e1e1..1c0b713f6 100644 --- a/src/tests/test_xmss.cpp +++ b/src/tests/test_xmss.cpp @@ -32,7 +32,7 @@ class XMSS_Signature_Tests final : public PK_Signature_Generation_Test { if(Test::run_long_tests() == false) { - const std::string params = get_req_str(vars, "Params"); + const std::string params = vars.get_req_str("Params"); if(params == "SHAKE128_W16_H10") { @@ -47,12 +47,12 @@ class XMSS_Signature_Tests final : public PK_Signature_Generation_Test std::string default_padding(const VarMap& vars) const override { - return get_req_str(vars, "Params"); + return vars.get_req_str("Params"); } std::unique_ptr<Botan::Private_Key> load_private_key(const VarMap& vars) override { - const std::vector<uint8_t> raw_key = get_req_bin(vars, "PrivateKey"); + const std::vector<uint8_t> raw_key = vars.get_req_bin("PrivateKey"); const Botan::secure_vector<uint8_t> sec_key(raw_key.begin(), raw_key.end()); std::unique_ptr<Botan::Private_Key> key(new Botan::XMSS_PrivateKey(sec_key)); @@ -71,12 +71,12 @@ class XMSS_Signature_Verify_Tests final : public PK_Signature_Verification_Test std::string default_padding(const VarMap& vars) const override { - return get_req_str(vars, "Params"); + return vars.get_req_str("Params"); } std::unique_ptr<Botan::Public_Key> load_public_key(const VarMap& vars) override { - const std::vector<uint8_t> raw_key = get_req_bin(vars, "PublicKey"); + const std::vector<uint8_t> raw_key = vars.get_req_bin("PublicKey"); std::unique_ptr<Botan::Public_Key> key(new Botan::XMSS_PublicKey(raw_key)); return key; } @@ -93,12 +93,12 @@ class XMSS_Signature_Verify_Invalid_Tests final : public PK_Signature_NonVerific std::string default_padding(const VarMap& vars) const override { - return get_req_str(vars, "Params"); + return vars.get_req_str("Params"); } std::unique_ptr<Botan::Public_Key> load_public_key(const VarMap& vars) override { - const std::vector<uint8_t> raw_key = get_req_bin(vars, "PublicKey"); + const std::vector<uint8_t> raw_key = vars.get_req_bin("PublicKey"); std::unique_ptr<Botan::Public_Key> key(new Botan::XMSS_PublicKey(raw_key)); return key; } diff --git a/src/tests/tests.cpp b/src/tests/tests.cpp index beb7e770d..076f85f0d 100644 --- a/src/tests/tests.cpp +++ b/src/tests/tests.cpp @@ -626,29 +626,11 @@ std::string Test::random_password() return Botan::hex_encode(Test::rng().random_vec(len)); } -Text_Based_Test::Text_Based_Test(const std::string& data_src, - const std::string& required_keys_str, - const std::string& optional_keys_str) : - m_data_src(data_src) - { - if(required_keys_str.empty()) - { - throw Test_Error("Invalid test spec"); - } - - std::vector<std::string> required_keys = Botan::split_on(required_keys_str, ','); - std::vector<std::string> optional_keys = Botan::split_on(optional_keys_str, ','); - - m_required_keys.insert(required_keys.begin(), required_keys.end()); - m_optional_keys.insert(optional_keys.begin(), optional_keys.end()); - m_output_key = required_keys.at(required_keys.size() - 1); - } - -std::vector<uint8_t> Text_Based_Test::get_req_bin(const VarMap& vars, +std::vector<uint8_t> VarMap::get_req_bin( const std::string& key) const { - auto i = vars.find(key); - if(i == vars.end()) + auto i = m_vars.find(key); + if(i == m_vars.end()) { throw Test_Error("Test missing variable " + key); } @@ -664,22 +646,20 @@ std::vector<uint8_t> Text_Based_Test::get_req_bin(const VarMap& vars, } } -std::string Text_Based_Test::get_opt_str(const VarMap& vars, - const std::string& key, const std::string& def_value) const - +std::string VarMap::get_opt_str(const std::string& key, const std::string& def_value) const { - auto i = vars.find(key); - if(i == vars.end()) + auto i = m_vars.find(key); + if(i == m_vars.end()) { return def_value; } return i->second; } -bool Text_Based_Test::get_req_bool(const VarMap& vars, const std::string& key) const +bool VarMap::get_req_bool( const std::string& key) const { - auto i = vars.find(key); - if(i == vars.end()) + auto i = m_vars.find(key); + if(i == m_vars.end()) { throw Test_Error("Test missing variable " + key); } @@ -698,31 +678,31 @@ bool Text_Based_Test::get_req_bool(const VarMap& vars, const std::string& key) c } } -size_t Text_Based_Test::get_req_sz(const VarMap& vars, const std::string& key) const +size_t VarMap::get_req_sz( const std::string& key) const { - auto i = vars.find(key); - if(i == vars.end()) + auto i = m_vars.find(key); + if(i == m_vars.end()) { throw Test_Error("Test missing variable " + key); } return Botan::to_u32bit(i->second); } -size_t Text_Based_Test::get_opt_sz(const VarMap& vars, const std::string& key, const size_t def_value) const +size_t VarMap::get_opt_sz( const std::string& key, const size_t def_value) const { - auto i = vars.find(key); - if(i == vars.end()) + auto i = m_vars.find(key); + if(i == m_vars.end()) { return def_value; } return Botan::to_u32bit(i->second); } -std::vector<uint8_t> Text_Based_Test::get_opt_bin(const VarMap& vars, +std::vector<uint8_t> VarMap::get_opt_bin( const std::string& key) const { - auto i = vars.find(key); - if(i == vars.end()) + auto i = m_vars.find(key); + if(i == m_vars.end()) { return std::vector<uint8_t>(); } @@ -738,10 +718,10 @@ std::vector<uint8_t> Text_Based_Test::get_opt_bin(const VarMap& vars, } } -std::string Text_Based_Test::get_req_str(const VarMap& vars, const std::string& key) const +std::string VarMap::get_req_str( const std::string& key) const { - auto i = vars.find(key); - if(i == vars.end()) + auto i = m_vars.find(key); + if(i == m_vars.end()) { throw Test_Error("Test missing variable " + key); } @@ -749,11 +729,11 @@ std::string Text_Based_Test::get_req_str(const VarMap& vars, const std::string& } #if defined(BOTAN_HAS_BIGINT) -Botan::BigInt Text_Based_Test::get_req_bn(const VarMap& vars, +Botan::BigInt VarMap::get_req_bn( const std::string& key) const { - auto i = vars.find(key); - if(i == vars.end()) + auto i = m_vars.find(key); + if(i == m_vars.end()) { throw Test_Error("Test missing variable " + key); } @@ -768,13 +748,12 @@ Botan::BigInt Text_Based_Test::get_req_bn(const VarMap& vars, } } -Botan::BigInt Text_Based_Test::get_opt_bn(const VarMap& vars, - const std::string& key, - const Botan::BigInt& def_value) const +Botan::BigInt VarMap::get_opt_bn(const std::string& key, + const Botan::BigInt& def_value) const { - auto i = vars.find(key); - if(i == vars.end()) + auto i = m_vars.find(key); + if(i == m_vars.end()) { return def_value; } @@ -790,6 +769,24 @@ Botan::BigInt Text_Based_Test::get_opt_bn(const VarMap& vars, } #endif +Text_Based_Test::Text_Based_Test(const std::string& data_src, + const std::string& required_keys_str, + const std::string& optional_keys_str) : + m_data_src(data_src) + { + if(required_keys_str.empty()) + { + throw Test_Error("Invalid test spec"); + } + + std::vector<std::string> required_keys = Botan::split_on(required_keys_str, ','); + std::vector<std::string> optional_keys = Botan::split_on(optional_keys_str, ','); + + m_required_keys.insert(required_keys.begin(), required_keys.end()); + m_optional_keys.insert(optional_keys.begin(), optional_keys.end()); + m_output_key = required_keys.at(required_keys.size() - 1); + } + std::string Text_Based_Test::get_next_line() { while(true) @@ -973,7 +970,7 @@ std::vector<Test::Result> Text_Based_Test::run() results.push_back(Test::Result::Failure(header_or_name, test_id + " failed unknown key " + key)); - vars[key] = val; + vars.add(key, val); if(key == m_output_key) { diff --git a/src/tests/tests.h b/src/tests/tests.h index 87ea16379..8b9bc7d0a 100644 --- a/src/tests/tests.h +++ b/src/tests/tests.h @@ -508,6 +508,42 @@ class Test #define BOTAN_REGISTER_TEST(type, Test_Class) \ Test::Registration reg_ ## Test_Class ## _tests(type, new Test_Class) +class VarMap + { + public: + void clear() { m_vars.clear(); } + + void add(const std::string& key, const std::string& value) + { + m_vars[key] = value; + } + + bool has_key(const std::string& key) const + { + return m_vars.count(key) == 1; + } + + bool get_req_bool(const std::string& key) const; + + std::vector<uint8_t> get_req_bin(const std::string& key) const; + std::vector<uint8_t> get_opt_bin(const std::string& key) const; + +#if defined(BOTAN_HAS_BIGINT) + Botan::BigInt get_req_bn(const std::string& key) const; + Botan::BigInt get_opt_bn(const std::string& key, const Botan::BigInt& def_value) const; +#endif + + std::string get_req_str(const std::string& key) const; + std::string get_opt_str(const std::string& key, + const std::string& def_value) const; + + size_t get_req_sz(const std::string& key) const; + size_t get_opt_sz(const std::string& key, const size_t def_value) const; + + private: + std::unordered_map<std::string, std::string> m_vars; + }; + /* * A test based on reading an input file which contains key/value pairs * Special note: the last value in required_key (there must be at least @@ -516,8 +552,8 @@ class Test * Calls run_one_test with the variables set. If an ini-style [header] * is used in the file, then header will be set to that value. This allows * splitting up tests between [valid] and [invalid] tests, or different -* related algorithms tested in the same file. Use the protected get_XXX -* functions to retrieve formatted values from the VarMap +* related algorithms tested in the same file. Use the get_XXX functions +* on VarMap to retrieve formatted values. * * If most of your tests are text-based but you find yourself with a few * odds-and-ends tests that you want to do, override run_final_tests which @@ -537,7 +573,6 @@ class Text_Based_Test : public Test std::vector<Test::Result> run() override; protected: - typedef std::unordered_map<std::string, std::string> VarMap; std::string get_next_line(); virtual Test::Result run_one_test(const std::string& header, @@ -551,23 +586,6 @@ class Text_Based_Test : public Test return std::vector<Test::Result>(); } - bool get_req_bool(const VarMap& vars, const std::string& key) const; - - std::vector<uint8_t> get_req_bin(const VarMap& vars, const std::string& key) const; - std::vector<uint8_t> get_opt_bin(const VarMap& vars, const std::string& key) const; - -#if defined(BOTAN_HAS_BIGINT) - Botan::BigInt get_req_bn(const VarMap& vars, const std::string& key) const; - Botan::BigInt get_opt_bn(const VarMap& vars, const std::string& key, const Botan::BigInt& def_value) const; -#endif - - std::string get_req_str(const VarMap& vars, const std::string& key) const; - std::string get_opt_str(const VarMap& vars, - const std::string& key, - const std::string& def_value) const; - - size_t get_req_sz(const VarMap& vars, const std::string& key) const; - size_t get_opt_sz(const VarMap& vars, const std::string& key, const size_t def_value) const; private: std::string m_data_src; std::set<std::string> m_required_keys; diff --git a/src/tests/unit_ecc.cpp b/src/tests/unit_ecc.cpp index c980d4a24..c79307c10 100644 --- a/src/tests/unit_ecc.cpp +++ b/src/tests/unit_ecc.cpp @@ -708,7 +708,7 @@ class ECC_Invalid_Key_Tests final : public Text_Based_Test { Test::Result result("ECC invalid keys"); - const std::string encoded = get_req_str(vars, "SubjectPublicKey"); + const std::string encoded = vars.get_req_str("SubjectPublicKey"); Botan::DataSource_Memory key_data(Botan::hex_decode(encoded)); try |