diff options
author | Kim Alvefur <zash@zash.se> | 2019-01-13 13:59:26 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2019-01-13 13:59:26 +0100 |
commit | ffc422e2f6d8806dee551491feaac71f54adf0d7 (patch) | |
tree | 99984ba46b2b92a4ed36214f2301497961a62d1f /util-src | |
parent | 5a6c7ae67300e26d483c9956f36b3a29d47e6502 (diff) | |
download | prosody-ffc422e2f6d8806dee551491feaac71f54adf0d7.tar.gz prosody-ffc422e2f6d8806dee551491feaac71f54adf0d7.zip |
util.hashes: Add PBKDF2-HMAC-SHA256
Diffstat (limited to 'util-src')
-rw-r--r-- | util-src/hashes.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/util-src/hashes.c b/util-src/hashes.c index 7e790e9f..4c48b26f 100644 --- a/util-src/hashes.c +++ b/util-src/hashes.c @@ -116,6 +116,23 @@ static int Lpbkdf2_sha1(lua_State *L) { return 1; } + +static int Lpbkdf2_sha256(lua_State *L) { + unsigned char out[SHA256_DIGEST_LENGTH]; + + size_t pass_len, salt_len; + const char *pass = luaL_checklstring(L, 1, &pass_len); + const unsigned char *salt = (unsigned char *)luaL_checklstring(L, 2, &salt_len); + const int iter = luaL_checkinteger(L, 3); + + if(PKCS5_PBKDF2_HMAC(pass, pass_len, salt, salt_len, iter, EVP_sha256(), SHA256_DIGEST_LENGTH, out) == 0) { + return luaL_error(L, "PKCS5_PBKDF2_HMAC() failed"); + } + + lua_pushlstring(L, (char *)out, SHA_DIGEST_LENGTH); + return 1; +} + static const luaL_Reg Reg[] = { { "sha1", Lsha1 }, { "sha224", Lsha224 }, @@ -129,6 +146,7 @@ static const luaL_Reg Reg[] = { { "hmac_md5", Lhmac_md5 }, { "scram_Hi_sha1", Lpbkdf2_sha1 }, /* COMPAT */ { "pbkdf2_hmac_sha1", Lpbkdf2_sha1 }, + { "pbkdf2_hmac_sha256", Lpbkdf2_sha256 }, { NULL, NULL } }; |