diff options
Diffstat (limited to 'src/tests/test_passhash.cpp')
-rw-r--r-- | src/tests/test_passhash.cpp | 45 |
1 files changed, 21 insertions, 24 deletions
diff --git a/src/tests/test_passhash.cpp b/src/tests/test_passhash.cpp index a8877ab3e..7805eb7eb 100644 --- a/src/tests/test_passhash.cpp +++ b/src/tests/test_passhash.cpp @@ -76,7 +76,7 @@ BOTAN_REGISTER_TEST("bcrypt", Bcrypt_Tests); class Passhash9_Tests : public Text_Based_Test { public: - Passhash9_Tests() : Text_Based_Test("passhash9.vec", "Password,Passhash") {} + Passhash9_Tests() : Text_Based_Test("passhash9.vec", "Password,Passhash,PRF") {} Test::Result run_one_test(const std::string&, const VarMap& vars) override { @@ -86,32 +86,25 @@ class Passhash9_Tests : public Text_Based_Test password_vec.size()); const std::string passhash = get_req_str(vars, "Passhash"); + const std::size_t prf = get_req_sz(vars, "PRF"); Test::Result result("passhash9"); - result.test_eq("correct hash accepted", Botan::check_passhash9(password, passhash), true); - std::vector<uint8_t> alg_ids; -#if defined(BOTAN_HAS_HMAC) && defined(BOTAN_HAS_SHA1) - alg_ids.push_back(0); -#endif -#if defined(BOTAN_HAS_HMAC) && defined(BOTAN_HAS_SHA2_32) - alg_ids.push_back(1); -#endif -#if defined(BOTAN_HAS_CMAC) && defined(BOTAN_HAS_BLOWFISH) - alg_ids.push_back(2); -#endif -#if defined(BOTAN_HAS_HMAC) && defined(BOTAN_HAS_SHA2_64) - alg_ids.push_back(3); - alg_ids.push_back(4); -#endif + if(Botan::is_passhash9_alg_supported(uint8_t(prf))) + { + result.test_eq("correct hash accepted", Botan::check_passhash9(password, passhash), true); + } - for(const auto& alg_id : alg_ids) + for(uint8_t alg_id = 0; alg_id <= 4; ++alg_id) { - const std::string gen_hash = Botan::generate_passhash9(password, Test::rng(), 2, alg_id); + if(Botan::is_passhash9_alg_supported(alg_id)) + { + const std::string gen_hash = Botan::generate_passhash9(password, Test::rng(), 2, alg_id); - if(!result.test_eq("generated hash accepted", Botan::check_passhash9(password, gen_hash), true)) - { - result.test_note("hash was " + gen_hash); + if(!result.test_eq("generated hash accepted", Botan::check_passhash9(password, gen_hash), true)) + { + result.test_note("hash was " + gen_hash); + } } } @@ -119,10 +112,14 @@ class Passhash9_Tests : public Text_Based_Test for(size_t level = 1; level <= max_level; ++level) { - const std::string gen_hash = Botan::generate_passhash9(password, Test::rng(), level); - if(!result.test_eq("generated hash accepted", Botan::check_passhash9(password, gen_hash), true)) + const uint8_t alg_id = 1; // default used by generate_passhash9() + if(Botan::is_passhash9_alg_supported(alg_id)) { - result.test_note("hash was " + gen_hash); + const std::string gen_hash = Botan::generate_passhash9(password, Test::rng(), level, alg_id); + if(!result.test_eq("generated hash accepted", Botan::check_passhash9(password, gen_hash), true)) + { + result.test_note("hash was " + gen_hash); + } } } |