aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/test_pbkdf.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2014-01-01 21:20:55 +0000
committerlloyd <[email protected]>2014-01-01 21:20:55 +0000
commit197dc467dec28a04c3b2f30da7cef122dfbb13e9 (patch)
treecdbd3ddaec051c72f0a757db461973d90c37b97a /src/tests/test_pbkdf.cpp
parent62faac373c07cfe10bc8c309e89ebdd30d8e5eaa (diff)
Shuffle things around. Add NIST X.509 test to build.
Diffstat (limited to 'src/tests/test_pbkdf.cpp')
-rw-r--r--src/tests/test_pbkdf.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/tests/test_pbkdf.cpp b/src/tests/test_pbkdf.cpp
new file mode 100644
index 000000000..140190b13
--- /dev/null
+++ b/src/tests/test_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(CHECKS_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"]));
+ });
+ }