# HG changeset patch # User Kim Alvefur # Date 1587584316 -7200 # Node ID 93293891709b178e330c407d8c95632c91c84714 # Parent 63a89b876407162dd20c058bc7b19944677c51de util.hashes: Fix output length of PBKDF2-HMAC-SHA256 Somehow it got SHA1's 20 byte output instead of the proper 32 = 256/8 diff -r 63a89b876407 -r 93293891709b spec/util_hashes_spec.lua --- a/spec/util_hashes_spec.lua Wed Apr 22 21:35:33 2020 +0200 +++ b/spec/util_hashes_spec.lua Wed Apr 22 21:38:36 2020 +0200 @@ -35,3 +35,21 @@ end); end); +describe("PBKDF2-HMAC-SHA256", function () + it("test vector 1", function () + local P = "password"; + local S = "salt"; + local c = 1 + local DK = "120fb6cffcf8b32c43e7225256c4f837a86548c92ccc35480805987cb70be17b"; + assert.equal(DK, hex.to(hashes.pbkdf2_hmac_sha256(P, S, c))); + end); + it("test vector 2", function () + local P = "password"; + local S = "salt"; + local c = 2 + local DK = "ae4d0c95af6b46d32d0adff928f06dd02a303f8ef3c251dfd6e2d85a95474c43"; + assert.equal(DK, hex.to(hashes.pbkdf2_hmac_sha256(P, S, c))); + end); +end); + + diff -r 63a89b876407 -r 93293891709b util-src/hashes.c --- a/util-src/hashes.c Wed Apr 22 21:35:33 2020 +0200 +++ b/util-src/hashes.c Wed Apr 22 21:38:36 2020 +0200 @@ -129,7 +129,7 @@ return luaL_error(L, "PKCS5_PBKDF2_HMAC() failed"); } - lua_pushlstring(L, (char *)out, SHA_DIGEST_LENGTH); + lua_pushlstring(L, (char *)out, SHA256_DIGEST_LENGTH); return 1; }