aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/kat_pbkdf.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_pbkdf.cpp
parenta7e3abf95fd1bc3df45be6fc9cb82e28e0a727ea (diff)
Rename test sources
Diffstat (limited to 'src/tests/kat_pbkdf.cpp')
-rw-r--r--src/tests/kat_pbkdf.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/tests/kat_pbkdf.cpp b/src/tests/kat_pbkdf.cpp
new file mode 100644
index 000000000..2bbd98769
--- /dev/null
+++ b/src/tests/kat_pbkdf.cpp
@@ -0,0 +1,48 @@
+#include "tests.h"
+
+#include <botan/lookup.h>
+#include <botan/hex.h>
+#include <iostream>
+#include <fstream>
+
+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)
+ {
+ return pbkdf_test(m["PBKDF"], m["Passphrase"], m["Salt"],
+ to_u32bit(m["Iterations"]), to_u32bit(m["OutputLen"]));
+ });
+ }