aboutsummaryrefslogtreecommitdiffstats
path: root/util-src/hashes.c
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2019-04-21 00:59:36 +0200
committerKim Alvefur <zash@zash.se>2019-04-21 00:59:36 +0200
commit90d4d6bda8161d7fdc730f822db13a1a8639aee4 (patch)
tree99984ba46b2b92a4ed36214f2301497961a62d1f /util-src/hashes.c
parent165ee3a5ef1247468e98d0d4cba6fc43e15f92d7 (diff)
downloadprosody-90d4d6bda8161d7fdc730f822db13a1a8639aee4.tar.gz
prosody-90d4d6bda8161d7fdc730f822db13a1a8639aee4.zip
Backed out changeset 61bc5c52c941
luaL_buffinitsize is only available in Lua 5.2+
Diffstat (limited to 'util-src/hashes.c')
-rw-r--r--util-src/hashes.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/util-src/hashes.c b/util-src/hashes.c
index 3fb849b9..4c48b26f 100644
--- a/util-src/hashes.c
+++ b/util-src/hashes.c
@@ -100,39 +100,36 @@ MAKE_HMAC_FUNCTION(Lhmac_sha512, EVP_sha512, SHA512_DIGEST_LENGTH, SHA512_CTX)
MAKE_HMAC_FUNCTION(Lhmac_md5, EVP_md5, MD5_DIGEST_LENGTH, MD5_CTX)
static int Lpbkdf2_sha1(lua_State *L) {
+ unsigned char out[SHA_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);
- const size_t len = luaL_optinteger(L, 4, SHA_DIGEST_LENGTH);
-
- luaL_Buffer b;
- unsigned char *out = (unsigned char *)luaL_buffinitsize(L, &b, len);
- if(PKCS5_PBKDF2_HMAC(pass, pass_len, salt, salt_len, iter, EVP_sha1(), len, out) == 0) {
+ if(PKCS5_PBKDF2_HMAC(pass, pass_len, salt, salt_len, iter, EVP_sha1(), SHA_DIGEST_LENGTH, out) == 0) {
return luaL_error(L, "PKCS5_PBKDF2_HMAC() failed");
}
- luaL_pushresultsize(&b, len);
+ lua_pushlstring(L, (char *)out, SHA_DIGEST_LENGTH);
+
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);
- const int len = luaL_optinteger(L, 4, SHA256_DIGEST_LENGTH);
-
- luaL_Buffer b;
- unsigned char *out = (unsigned char *)luaL_buffinitsize(L, &b, len);
- if(PKCS5_PBKDF2_HMAC(pass, pass_len, salt, salt_len, iter, EVP_sha256(), len, out) == 0) {
+ 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");
}
- luaL_pushresultsize(&b, len);
+ lua_pushlstring(L, (char *)out, SHA_DIGEST_LENGTH);
return 1;
}