diff options
author | Jack Lloyd <[email protected]> | 2015-11-11 05:43:01 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2015-11-11 05:43:01 -0500 |
commit | cf05aea092fad448c2f4a8e8b66159237096ba8e (patch) | |
tree | 00631bcc84809a1eeac5dd32dd92c62143ef831b /src/tests/test_kdf.cpp | |
parent | 6bb38ae2fa0e1be46b3a3256ac03f435b16a57ea (diff) |
Update and consolidate the test framework.
The tests previously had used 4 to 6 different schemes internally (the vec file
reader framework, Catch, the old InSiTo Boost.Test tests, the PK/BigInt tests
which escaped the rewrite in 1.11.7, plus a number of one-offs). Converge on a
design that works everywhere, and update all the things.
Fix also a few bugs found by the test changes: SHA-512-256 name incorrect,
OpenSSL RC4 name incorrect, signature of FFI function botan_pubkey_destroy
was wrong.
Diffstat (limited to 'src/tests/test_kdf.cpp')
-rw-r--r-- | src/tests/test_kdf.cpp | 59 |
1 files changed, 35 insertions, 24 deletions
diff --git a/src/tests/test_kdf.cpp b/src/tests/test_kdf.cpp index 30541d459..d9a172bad 100644 --- a/src/tests/test_kdf.cpp +++ b/src/tests/test_kdf.cpp @@ -7,38 +7,49 @@ #include "tests.h" #if defined(BOTAN_HAS_KDF_BASE) + #include <botan/kdf.h> +#endif -#include <botan/kdf.h> -#include <botan/hex.h> -#include <iostream> -#include <fstream> +namespace Botan_Tests { -using namespace Botan; +namespace { -size_t test_kdf() +#if defined(BOTAN_HAS_KDF_BASE) +class KDF_KAT_Tests : public Text_Based_Test { - auto test = [](const std::string& input) - { - return run_tests(input, "KDF", "Output", true, - [](std::map<std::string, std::string> vec) - { - std::unique_ptr<KDF> kdf(get_kdf(vec["KDF"])); + public: + KDF_KAT_Tests() : Text_Based_Test(Test::data_dir("kdf"), + {"OutputLen", "Salt", "Secret", "Output"}, + {"IKM","XTS"}) + {} + + Test::Result run_one_test(const std::string& kdf_name, const VarMap& vars) + { + Test::Result result(kdf_name); + std::unique_ptr<Botan::KDF> kdf(Botan::get_kdf(kdf_name)); + + if(!kdf) + { + result.note_missing(kdf_name); + return result; + } + + const size_t outlen = get_req_sz(vars, "OutputLen"); + 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> expected = get_req_bin(vars, "Output"); - const size_t outlen = to_u32bit(vec["OutputLen"]); - const auto salt = hex_decode(vec["Salt"]); - const auto secret = hex_decode(vec["Secret"]); + result.test_eq("derived key", kdf->derive_key(outlen, secret, salt), expected); - const auto key = kdf->derive_key(outlen, secret, salt); + return result; + } - return hex_encode(key); - }); - }; + }; - return run_tests_in_dir(TEST_DATA_DIR "/kdf", test); - } +BOTAN_REGISTER_TEST("kdf", KDF_KAT_Tests); -#else +#endif -SKIP_TEST(kdf); +} -#endif // BOTAN_HAS_KDF_BASE +} |