diff options
author | Jack Lloyd <[email protected]> | 2019-05-29 11:41:20 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2019-05-29 11:41:20 -0400 |
commit | 72655f4b237edebec557998669af676475fb721b (patch) | |
tree | 44ad79f9cd9e78afd98451da94daa72ee9f71bc4 /src/tests/test_pbkdf.cpp | |
parent | eec722c5945f910ac9a9515cce322e08e98d72a9 (diff) |
Improve test coverage. Fix Argon2 default params
Diffstat (limited to 'src/tests/test_pbkdf.cpp')
-rw-r--r-- | src/tests/test_pbkdf.cpp | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/src/tests/test_pbkdf.cpp b/src/tests/test_pbkdf.cpp index 9ddb1e171..113d1bc2c 100644 --- a/src/tests/test_pbkdf.cpp +++ b/src/tests/test_pbkdf.cpp @@ -88,48 +88,56 @@ class Pwdhash_Tests : public Test { std::vector<Test::Result> results; - for(std::string pwdhash : { "Scrypt", "PBKDF2(SHA-256)", "OpenPGP-S2K(SHA-384)"}) + for(std::string pwdhash : { "Scrypt", "PBKDF2(SHA-256)", "OpenPGP-S2K(SHA-384)", "Argon2d", "Argon2i", "Argon2id" }) { Test::Result result("Pwdhash " + pwdhash); auto pwdhash_fam = Botan::PasswordHashFamily::create(pwdhash); if(pwdhash_fam) { + result.start_timer(); + const std::vector<uint8_t> salt(8); const std::string password = "test"; - auto pwdhash_tune = pwdhash_fam->tune(32, std::chrono::milliseconds(50)); + auto tuned_pwhash = pwdhash_fam->tune(32, std::chrono::milliseconds(10)); std::vector<uint8_t> output1(32); - pwdhash_tune->derive_key(output1.data(), output1.size(), + tuned_pwhash->derive_key(output1.data(), output1.size(), password.c_str(), password.size(), salt.data(), salt.size()); std::unique_ptr<Botan::PasswordHash> pwhash; - if(pwdhash_fam->name() == "Scrypt") + if(pwdhash_fam->name() == "Scrypt" || pwdhash_fam->name().find("Argon2") == 0) { - pwhash = pwdhash_fam->from_params(pwdhash_tune->memory_param(), - pwdhash_tune->iterations(), - pwdhash_tune->parallelism()); + pwhash = pwdhash_fam->from_params(tuned_pwhash->memory_param(), + tuned_pwhash->iterations(), + tuned_pwhash->parallelism()); } else { - pwhash = pwdhash_fam->from_params(pwdhash_tune->iterations()); + pwhash = pwdhash_fam->from_params(tuned_pwhash->iterations()); } std::vector<uint8_t> output2(32); - pwdhash_tune->derive_key(output2.data(), output2.size(), - password.c_str(), password.size(), - salt.data(), salt.size()); + pwhash->derive_key(output2.data(), output2.size(), + password.c_str(), password.size(), + salt.data(), salt.size()); result.test_eq("PasswordHash produced same output when run with same params", output1, output2); + auto default_pwhash = pwdhash_fam->default_params(); + std::vector<uint8_t> output3(32); + default_pwhash->derive_key(output3.data(), output3.size(), + password.c_str(), password.size(), + salt.data(), salt.size()); - //auto pwdhash_tuned = pwdhash_fam->tune(32, std::chrono::milliseconds(150)); - + result.end_timer(); } + else + result.test_failure("No such algo " + pwdhash); results.push_back(result); } |