diff options
author | Kim Alvefur <zash@zash.se> | 2020-04-22 21:38:36 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2020-04-22 21:38:36 +0200 |
commit | 701c5f48110cb004925ba659b7221b18713ad2c7 (patch) | |
tree | 0265866d671b88b235c1f5c6d4c0d8444e8bc99e | |
parent | 16c54b170580328dd57bb35a68281d5e385b82dc (diff) | |
download | prosody-701c5f48110cb004925ba659b7221b18713ad2c7.tar.gz prosody-701c5f48110cb004925ba659b7221b18713ad2c7.zip |
util.hashes: Fix output length of PBKDF2-HMAC-SHA256
Somehow it got SHA1's 20 byte output instead of the proper 32 = 256/8
-rw-r--r-- | spec/util_hashes_spec.lua | 18 | ||||
-rw-r--r-- | util-src/hashes.c | 2 |
2 files changed, 19 insertions, 1 deletions
diff --git a/spec/util_hashes_spec.lua b/spec/util_hashes_spec.lua index 5c616a8d..3639dd4e 100644 --- a/spec/util_hashes_spec.lua +++ b/spec/util_hashes_spec.lua @@ -35,3 +35,21 @@ describe("PBKDF2-HMAC-SHA1", function () 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 --git a/util-src/hashes.c b/util-src/hashes.c index 51c7611c..84a604ef 100644 --- a/util-src/hashes.c +++ b/util-src/hashes.c @@ -129,7 +129,7 @@ static int Lpbkdf2_sha256(lua_State *L) { 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; } |