diff options
author | Jack Lloyd <[email protected]> | 2018-07-18 16:45:17 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2019-05-31 21:32:19 -0400 |
commit | 184a7825a8cc449476951de0d2019d8014667c8f (patch) | |
tree | 329d69bfd71d53b126c02864d779887b42ce13dd /src/tests | |
parent | dbf4b8d7418587d4d30c048e1ff13f418944ffc4 (diff) |
Add Bcrypt-PBKDF
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/data/bcrypt_pbkdf.vec | 184 | ||||
-rw-r--r-- | src/tests/test_pbkdf.cpp | 50 |
2 files changed, 232 insertions, 2 deletions
diff --git a/src/tests/data/bcrypt_pbkdf.vec b/src/tests/data/bcrypt_pbkdf.vec new file mode 100644 index 000000000..e56745265 --- /dev/null +++ b/src/tests/data/bcrypt_pbkdf.vec @@ -0,0 +1,184 @@ + +# From https://github.com/dchest/bcrypt_pbkdf/blob/master/bcrypt_pbkdf_test.go +Passphrase = password +Salt = 73616C74 +Iterations = 12 +Output = 1AE42C05D487BC02F64921A4EBE4EA93BCACFE135FDA99974C06B7B01FAE149A + +# Generated by OpenBSD bcrypt_pbkdf +Passphrase = A +Salt = 0001020304050607 +Iterations = 10 +Output = 3C705DA7E10C61C2523B + +Passphrase = A +Salt = 0001020304050607 +Iterations = 10 +Output = 3CF670095D5FA753E1430C6D6177C299521B3B614D9E53FA89C7F893F33289F677DDD72EE1AA29CBF5574A948DE4623C71996FFD16C8806FDD7ACBE02992DEAC + +# Generated by https://github.com/dchest/bcrypt_pbkdf/ +Passphrase = password +Salt = 73616C74 +Iterations = 3 +Output = CCB508027535A962F591D4A7EEA08FE15EE0B68044B1A7B209605FDFBFB41228 + +Passphrase = password +Salt = 73616C74 +Iterations = 4 +Output = 5BBF0CC293587F1C3635555C27796598 + +Passphrase = password +Salt = 73616C74 +Iterations = 4 +Output = 5BBF0CC293587F1C3635555C27796598D47E579071BF427E9D8FBE842ABA34D9 + +Passphrase = password +Salt = 73616C74 +Iterations = 4 +Output = 5BA4BFC60C7AC272931458407F4C1C4936EA356C55125C5A279B791D65BF9842D49D7E1B572A9052715EBFA9421E7E94 + +Passphrase = password +Salt = 73616C74 +Iterations = 4 +Output = 5BA4BFC60C7AC272931458407F4C1C4936EA356C55125C5A279B791D65BF9842D49D7E1B572A9052715EBFA9421E7E949D8F8F19BE3284732AF1BA28341DD9BF + +Passphrase = password +Salt = 73616C74 +Iterations = 5 +Output = 4137FF05DC28382925690E6FD53B8EA1 + +Passphrase = password +Salt = 73616C74 +Iterations = 5 +Output = 4137FF05DC28382925690E6FD53B8EA112DA02D8F79B787E48ADBE77B1CE5B30 + +Passphrase = password +Salt = 73616C74 +Iterations = 5 +Output = 41CF37FCFF41055CDC5C280D389829D625DD69490E3B6F6BD5EB3B4C8E51A19E12A2DAFB02E8D82EF7F69B4A78717E51 + +Passphrase = password +Salt = 73616C74 +Iterations = 5 +Output = 41CF37FCFF41055CDC5C280D389829D625DD69490E3B6F6BD5EB3B4C8E51A19E12A2DAFB02E8D82EF7F69B4A78717E514812AD4CBE5877D3B1D0CEB35BA3308E + +Passphrase = password +Salt = 73616C74 +Iterations = 6 +Output = 1E6CF2445415961A1FC9FCEDA40DF381 + +Passphrase = password +Salt = 73616C74 +Iterations = 6 +Output = 1E6CF2445415961A1FC9FCEDA40DF381A86F5B327864A3CEA627EA8CFB081969 + +Passphrase = password +Salt = 73616C74 +Iterations = 6 +Output = 1E906CE9F245442B5418153196301AFE1F5DC9FAFC06ED55A4160DBBF3BC81FFA8A16FD95B15326C78B3644CA356CE28 + +Passphrase = password +Salt = 73616C74 +Iterations = 6 +Output = 1E906CE9F245442B5418153196301AFE1F5DC9FAFC06ED55A4160DBBF3BC81FFA8A16FD95B15326C78B3644CA356CE28A6162741EAE68C2AFB5E08A81921697C + +Passphrase = password +Salt = 73616C74 +Iterations = 7 +Output = 2BF6125E9A0532A025B1E777FD5F9540 + +Passphrase = password +Salt = 73616C74 +Iterations = 7 +Output = 2BF6125E9A0532A025B1E777FD5F9540C95408393ADEA4241A5AACFEC17A74FC + +Passphrase = password +Salt = 73616C74 +Iterations = 7 +Output = 2BC7F6A012985EF39A6B05343202A0972507B1DFE7F97703FD9D5FF7951F40E3C92854FE087739603ADDDE00A4722471 + +Passphrase = password +Salt = 73616C74 +Iterations = 7 +Output = 2BC7F6A012985EF39A6B05343202A0972507B1DFE7F97703FD9D5FF7951F40E3C92854FE087739603ADDDE00A47224711A8F5A40ACBFFE3DC1A87A8174FAFC9E + +Passphrase = password +Salt = 73616C74 +Iterations = 8 +Output = E17E1533ACC14423155493C99B9C3BBE + +Passphrase = password +Salt = 73616C74 +Iterations = 8 +Output = E17E1533ACC14423155493C99B9C3BBE62EA0884207A7802E7BA72EFF94D085E + +Passphrase = password +Salt = 73616C74 +Iterations = 8 +Output = E1367EC5151A33FAAC4CC1C144CD23FA15D5548493ECC99B9B5D9C0D3B27BEC76227EA66088B849B20AB7AA478010246 + +Passphrase = password +Salt = 73616C74 +Iterations = 8 +Output = E1367EC5151A33FAAC4CC1C144CD23FA15D5548493ECC99B9B5D9C0D3B27BEC76227EA66088B849B20AB7AA478010246E74BBA51723FEFA9F9474D6508845E8D + +Passphrase = password +Salt = 73616C74 +Iterations = 9 +Output = 5871A1FE827AC417E5B17BC90E0CF8EB + +Passphrase = password +Salt = 73616C74 +Iterations = 9 +Output = 5871A1FE827AC417E5B17BC90E0CF8EBC59384735EF44F0A4A79FFC70629D39B + +Passphrase = password +Salt = 73616C74 +Iterations = 9 +Output = 586571F0A1F9FE2982337A42C478174BE58EB17C7B90C9B40E800CBAF82DEB7BC54D936784A973FC5E01F4484F120AD3 + +Passphrase = password +Salt = 73616C74 +Iterations = 9 +Output = 586571F0A1F9FE2982337A42C478174BE58EB17C7B90C9B40E800CBAF82DEB7BC54D936784A973FC5E01F4484F120AD34A7179E4FF1EC7D406922935D3809B86 + +Passphrase = password +Salt = 73616C74 +Iterations = 10 +Output = ABC7DCFB41032D844AF67A1D1EF8A5E6 + +Passphrase = password +Salt = 73616C74 +Iterations = 10 +Output = ABC7DCFB41032D844AF67A1D1EF8A5E6A04AA3073D4F2777BFA5FE07A54CFF9D + +Passphrase = password +Salt = 73616C74 +Iterations = 10 +Output = ABFBC7DBDCB6FBC9414703BF2D0584994A9DF60A7AA71DC51EC7F8E1A55BE673A01D4AB9A3BA070E3DD74F92270177F9 + +Passphrase = password +Salt = 73616C74 +Iterations = 10 +Output = ABFBC7DBDCB6FBC9414703BF2D0584994A9DF60A7AA71DC51EC7F8E1A55BE673A01D4AB9A3BA070E3DD74F92270177F9BFCFA5A9FEA107DCA59F4C5EFFC09D96 + +Passphrase = password +Salt = 73616C74 +Iterations = 11 +Output = 07B2C9848D4535A9E96EDB0AB4783841 + +Passphrase = password +Salt = 73616C74 +Iterations = 11 +Output = 07B2C9848D4535A9E96EDB0AB4783841A2A4571BE59CB3D14742218AA72A89D5 + +Passphrase = password +Salt = 73616C74 +Iterations = 11 +Output = 0726B275C9CD84B18DD245DB35F4A944E9A46E7FDBB50A14B4C4789E38AF41C8A228A4FC57601B32E5409C5DB3C6D194 + +Passphrase = password +Salt = 73616C74 +Iterations = 11 +Output = 0726B275C9CD84B18DD245DB35F4A944E9A46E7FDBB50A14B4C4789E38AF41C8A228A4FC57601B32E5409C5DB3C6D194475D424421568AEBA7732ABF89C6D56D + diff --git a/src/tests/test_pbkdf.cpp b/src/tests/test_pbkdf.cpp index 0e780437b..f10b721e2 100644 --- a/src/tests/test_pbkdf.cpp +++ b/src/tests/test_pbkdf.cpp @@ -1,5 +1,5 @@ /* -* (C) 2014,2015 Jack Lloyd +* (C) 2014,2015,2019 Jack Lloyd * (C) 2018 Ribose Inc * * Botan is released under the Simplified BSD License (see license.txt) @@ -24,6 +24,10 @@ #include <botan/argon2.h> #endif +#if defined(BOTAN_HAS_PBKDF_BCRYPT) + #include <botan/bcrypt_pbkdf.h> +#endif + namespace Botan_Tests { namespace { @@ -88,7 +92,17 @@ class Pwdhash_Tests : public Test { std::vector<Test::Result> results; - for(std::string pwdhash : { "Scrypt", "PBKDF2(SHA-256)", "OpenPGP-S2K(SHA-384)", "Argon2d", "Argon2i", "Argon2id" }) + const std::vector<std::string> all_pwdhash = { + "Scrypt", + "PBKDF2(SHA-256)", + "OpenPGP-S2K(SHA-384)", + "Argon2d", + "Argon2i", + "Argon2id", + "Bcrypt-PBKDF" + }; + + for(std::string pwdhash : all_pwdhash) { Test::Result result("Pwdhash " + pwdhash); auto pwdhash_fam = Botan::PasswordHashFamily::create(pwdhash); @@ -150,6 +164,38 @@ BOTAN_REGISTER_TEST("pwdhash", Pwdhash_Tests); #endif +#if defined(BOTAN_HAS_PBKDF_BCRYPT) + +class Bcrypt_PBKDF_KAT_Tests final : public Text_Based_Test + { + public: + Bcrypt_PBKDF_KAT_Tests() : Text_Based_Test("bcrypt_pbkdf.vec", "Passphrase,Salt,Iterations,Output") {} + + Test::Result run_one_test(const std::string&, const VarMap& vars) override + { + const size_t rounds = vars.get_req_sz("Iterations"); + const std::vector<uint8_t> salt = vars.get_req_bin("Salt"); + const std::string passphrase = vars.get_req_str("Passphrase"); + const std::vector<uint8_t> expected = vars.get_req_bin("Output"); + + Test::Result result("bcrypt PBKDF"); + + std::vector<uint8_t> output(expected.size()); + Botan::bcrypt_pbkdf(output.data(), output.size(), + passphrase.data(), passphrase.size(), + salt.data(), salt.size(), + rounds); + + result.test_eq("derived key", output, expected); + + return result; + } + }; + +BOTAN_REGISTER_TEST("bcrypt_pbkdf", Bcrypt_PBKDF_KAT_Tests); + +#endif + #if defined(BOTAN_HAS_SCRYPT) class Scrypt_KAT_Tests final : public Text_Based_Test |