diff options
author | lloyd <[email protected]> | 2014-01-10 00:08:13 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2014-01-10 00:08:13 +0000 |
commit | 57789bdfc55061002b2727d0b32587612829a37c (patch) | |
tree | 99f36631b4ec50c5187a1b0a7c256b99182373ad /src/tests/kat_pbkdf.cpp | |
parent | 94968c917407a63d888fd3eb4d02491f60de6ebc (diff) |
Split up test vectors into per-algo files and app into botan-test for
the tests and botan for everything else.
Diffstat (limited to 'src/tests/kat_pbkdf.cpp')
-rw-r--r-- | src/tests/kat_pbkdf.cpp | 52 |
1 files changed, 18 insertions, 34 deletions
diff --git a/src/tests/kat_pbkdf.cpp b/src/tests/kat_pbkdf.cpp index 2bbd98769..5d97bf0e9 100644 --- a/src/tests/kat_pbkdf.cpp +++ b/src/tests/kat_pbkdf.cpp @@ -7,42 +7,26 @@ using namespace Botan; -namespace { - -secure_vector<byte> pbkdf(const std::string& algo, - const std::string& pass, - const secure_vector<byte>& salt, - size_t iterations, size_t outlen) - { - std::unique_ptr<PBKDF> pbkdf(get_pbkdf(algo)); - return pbkdf->derive_key(outlen, pass, - &salt[0], salt.size(), - iterations).bits_of(); - } - -std::string pbkdf_test(const std::string& algo, - const std::string& pass, - const std::string& salt, - size_t iterations, - size_t outlen) - { - return hex_encode(pbkdf(algo, - pass, - hex_decode_locked(salt), - iterations, - outlen)); - } - -} - size_t test_pbkdf() { - std::ifstream vec(TEST_DATA_DIR "/pbkdf.vec"); - - return run_tests(vec, "PBKDF", "Output", true, - [](std::map<std::string, std::string> m) + auto test = [](const std::string& input) + { + return run_tests(input, "PBKDF", "Output", true, + [](std::map<std::string, std::string> vec) { - return pbkdf_test(m["PBKDF"], m["Passphrase"], m["Salt"], - to_u32bit(m["Iterations"]), to_u32bit(m["OutputLen"])); + std::unique_ptr<PBKDF> pbkdf(get_pbkdf(vec["PBKDF"])); + + const size_t iterations = to_u32bit(vec["Iterations"]); + const size_t outlen = to_u32bit(vec["OutputLen"]); + const auto salt = hex_decode(vec["Salt"]); + const std::string pass = vec["Passphrase"]; + + const auto key = pbkdf->derive_key(outlen, pass, + &salt[0], salt.size(), + iterations).bits_of(); + return hex_encode(key); }); + }; + + return run_tests_in_dir(TEST_DATA_DIR "pbkdf", test); } |