aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/test_passhash.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/test_passhash.cpp')
-rw-r--r--src/tests/test_passhash.cpp94
1 files changed, 94 insertions, 0 deletions
diff --git a/src/tests/test_passhash.cpp b/src/tests/test_passhash.cpp
new file mode 100644
index 000000000..6f66743c5
--- /dev/null
+++ b/src/tests/test_passhash.cpp
@@ -0,0 +1,94 @@
+#include "tests.h"
+
+#include <botan/auto_rng.h>
+#include <iostream>
+
+#if defined(BOTAN_HAS_PASSHASH9)
+ #include <botan/passhash9.h>
+#endif
+
+#if defined(BOTAN_HAS_BCRYPT)
+ #include <botan/bcrypt.h>
+#endif
+
+using namespace Botan;
+
+size_t test_bcrypt()
+ {
+ size_t fails = 0;
+
+#if defined(BOTAN_HAS_BCRYPT)
+
+ // Generated by jBCrypt 0.3
+ if(!check_bcrypt("abc", "$2a$05$DfPyLs.G6.To9fXEFgUL1O6HpYw3jIXgPcl/L3Qt3jESuWmhxtmpS"))
+ {
+ std::cout << "Bcrypt test 1 failed\n";
+ fails++;
+ }
+
+ // http://www.openwall.com/lists/john-dev/2011/06/19/2
+ if(!check_bcrypt("\xA3",
+ "$2a$05$/OK.fbVrR/bpIqNJ5ianF.Sa7shbm4.OzKpvFnX1pQLmQW96oUlCq"))
+ {
+ std::cout << "Bcrypt test 2 failed\n";
+ fails++;
+ }
+
+ AutoSeeded_RNG rng;
+
+ for(u16bit level = 1; level != 5; ++level)
+ {
+ const std::string input = "some test passphrase 123";
+ const std::string gen_hash = generate_bcrypt(input, rng, level);
+
+ if(!check_bcrypt(input, gen_hash))
+ {
+ std::cout << "Gen and check for bcrypt failed: " << gen_hash << " not valid\n";
+ ++fails;
+ }
+ }
+
+ test_report("Bcrypt", 6, fails);
+
+#endif
+
+ return fails;
+ }
+
+size_t test_passhash9()
+ {
+ size_t fails = 0;
+
+#if defined(BOTAN_HAS_PASSHASH9)
+ const std::string input = "secret";
+ const std::string fixed_hash =
+ "$9$AAAKhiHXTIUhNhbegwBXJvk03XXJdzFMy+i3GFMIBYKtthTTmXZA";
+
+ size_t ran = 0;
+
+ ++ran;
+ if(!check_passhash9(input, fixed_hash))
+ {
+ std::cout << "Passhash9 fixed input test failed\n";
+ fails++;
+ }
+
+ AutoSeeded_RNG rng;
+
+ for(byte alg_id = 0; alg_id <= 4; ++alg_id)
+ {
+ std::string gen_hash = generate_passhash9(input, rng, 2, alg_id);
+
+ ++ran;
+ if(!check_passhash9(input, gen_hash))
+ {
+ std::cout << "Passhash9 gen and check " << static_cast<int>(alg_id) << " failed\n";
+ ++fails;
+ }
+ }
+
+ test_report("Passhash9", ran, fails);
+#endif
+
+ return fails;
+ }