aboutsummaryrefslogtreecommitdiffstats
path: root/checks/test_kdf.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2014-01-01 00:46:02 +0000
committerlloyd <[email protected]>2014-01-01 00:46:02 +0000
commit22062aa7636e844621243d582ae4e2938d5a1f93 (patch)
treeb15536fc1922f5136e01e84042a0f83551af35b4 /checks/test_kdf.cpp
parent0b11408316f7df4901535bb665631172d2d42fb0 (diff)
Testier
Diffstat (limited to 'checks/test_kdf.cpp')
-rw-r--r--checks/test_kdf.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/checks/test_kdf.cpp b/checks/test_kdf.cpp
new file mode 100644
index 000000000..60c4eb25f
--- /dev/null
+++ b/checks/test_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("checks/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"]);
+ });
+ }