#include "tests.h" #include #if defined(BOTAN_HAS_PASSHASH9) #include #endif #if defined(BOTAN_HAS_BCRYPT) #include #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++; } auto& rng = test_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++; } auto& rng = test_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(alg_id) << " failed\n"; ++fails; } } test_report("Passhash9", ran, fails); #endif return fails; }