aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/kat_kdf.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2014-01-07 11:03:55 +0000
committerlloyd <[email protected]>2014-01-07 11:03:55 +0000
commitc109c7f84fcef6ba895c6293508b2deae0e803c1 (patch)
tree35ba7b55914023a77ecfbcf5dee2befcc4e275d1 /src/tests/kat_kdf.cpp
parenta7e3abf95fd1bc3df45be6fc9cb82e28e0a727ea (diff)
Rename test sources
Diffstat (limited to 'src/tests/kat_kdf.cpp')
-rw-r--r--src/tests/kat_kdf.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/tests/kat_kdf.cpp b/src/tests/kat_kdf.cpp
new file mode 100644
index 000000000..86b3ea5c4
--- /dev/null
+++ b/src/tests/kat_kdf.cpp
@@ -0,0 +1,43 @@
+#include "tests.h"
+
+#include <botan/lookup.h>
+#include <botan/hex.h>
+#include <iostream>
+#include <fstream>
+
+using namespace Botan;
+
+namespace {
+
+secure_vector<byte> kdf(const std::string& algo,
+ size_t outlen,
+ const secure_vector<byte>& secret,
+ const secure_vector<byte>& salt)
+ {
+ std::unique_ptr<KDF> kdf(get_kdf(algo));
+ return kdf->derive_key(outlen, secret, salt);
+ }
+
+std::string kdf_test(const std::string& algo,
+ size_t outlen,
+ const std::string& secret,
+ const std::string& salt)
+ {
+ return hex_encode(kdf(algo, outlen,
+ hex_decode_locked(secret),
+ hex_decode_locked(salt)));
+ }
+
+}
+
+size_t test_kdf()
+ {
+ std::ifstream vec(TEST_DATA_DIR "/kdf.vec");
+
+ return run_tests(vec, "KDF", "Output", true,
+ [](std::map<std::string, std::string> m)
+ {
+ return kdf_test(m["KDF"], to_u32bit(m["OutputLen"]),
+ m["Secret"], m["Salt"]);
+ });
+ }