diff options
author | lloyd <[email protected]> | 2014-01-10 23:07:16 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2014-01-10 23:07:16 +0000 |
commit | ad6555f522ae16f6284e8dafa02f630b88bcf289 (patch) | |
tree | bd63c51dbeab75eb0f90c72589bc922141237056 /src/tests/test_passhash.cpp | |
parent | 6894dca64c04936d07048c0e8cbf7e25858548c3 (diff) |
Split up docs into the reference manual, the website, and everything else.
Add `website` target to makefile.
Some progress towards fixing minimized builds.
TLS now hard requires ECDSA and GCM since otherwise a minimized build
has only insecure options.
Remove boost_thread dependency in command line tool
Diffstat (limited to 'src/tests/test_passhash.cpp')
-rw-r--r-- | src/tests/test_passhash.cpp | 94 |
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; + } |