diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/passhash/passhash9/passhash9.cpp | 4 | ||||
-rw-r--r-- | src/tests/test_passhash.cpp | 19 |
2 files changed, 20 insertions, 3 deletions
diff --git a/src/lib/passhash/passhash9/passhash9.cpp b/src/lib/passhash/passhash9/passhash9.cpp index 47c7d0342..9b4a31370 100644 --- a/src/lib/passhash/passhash9/passhash9.cpp +++ b/src/lib/passhash/passhash9/passhash9.cpp @@ -105,8 +105,8 @@ bool check_passhash9(const std::string& pass, const std::string& hash) return false; if(work_factor > 512) - throw Invalid_Argument("Requested Bcrypt work factor " + - std::to_string(work_factor) + " too large"); + throw Invalid_Argument("Requested passhash9 work factor " + + std::to_string(work_factor) + " is too large"); const size_t kdf_iterations = WORK_FACTOR_SCALE * work_factor; diff --git a/src/tests/test_passhash.cpp b/src/tests/test_passhash.cpp index 7f42bce4a..be194b553 100644 --- a/src/tests/test_passhash.cpp +++ b/src/tests/test_passhash.cpp @@ -98,7 +98,7 @@ class Passhash9_Tests final : public Text_Based_Test for(uint8_t alg_id = 0; alg_id <= 4; ++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)) @@ -125,6 +125,23 @@ class Passhash9_Tests final : public Text_Based_Test return result; } + + std::vector<Test::Result> run_final_tests() override + { + Test::Result result("passhash9"); + + result.confirm("Unknown algorithm is unknown", + Botan::is_passhash9_alg_supported(255) == false); + + result.test_throws("Throws if algorithm not supported", + "Invalid argument Passhash9: Algorithm id 255 is not defined", + []() { Botan::generate_passhash9("pass", Test::rng(), 3, 255); }); + + result.test_throws("Throws if iterations is too high", + "Invalid argument Requested passhash9 work factor 513 is too large", + []() { Botan::check_passhash9("floof", "$9$AgIB3c5J3kvAuML84sZ5hWT9WzJtiYRPLCEARaujS7I6IKbNCwp0"); }); + return {result}; + } }; BOTAN_REGISTER_TEST("passhash9", Passhash9_Tests); |