From 9a960217066e2659bf9473220c977c9246bcf6fa Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 24 Jun 2022 15:33:04 +0200 Subject: util.hashes: Return OpenSSL error messages on failure With luck, might contain more details than just "failed" --- util-src/hashes.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/util-src/hashes.c b/util-src/hashes.c index 1b3e157d..de802db0 100644 --- a/util-src/hashes.c +++ b/util-src/hashes.c @@ -28,6 +28,7 @@ typedef unsigned __int32 uint32_t; #include #include #include +#include #if (LUA_VERSION_NUM == 501) #define luaL_setfuncs(L, R, N) luaL_register(L, NULL, R) @@ -85,7 +86,7 @@ static int Levp_hash(lua_State *L, const EVP_MD *evp) { fail: EVP_MD_CTX_free(ctx); - return luaL_error(L, "hash function failed"); + return luaL_error(L, ERR_error_string(ERR_get_error(), NULL)); } static int Lsha1(lua_State *L) { @@ -178,7 +179,7 @@ static int Levp_hmac(lua_State *L, const EVP_MD *evp) { fail: EVP_MD_CTX_free(ctx); EVP_PKEY_free(pkey); - return luaL_error(L, "hash function failed"); + return luaL_error(L, ERR_error_string(ERR_get_error(), NULL)); } static int Lhmac_sha1(lua_State *L) { @@ -231,7 +232,7 @@ static int Levp_pbkdf2(lua_State *L, const EVP_MD *evp, size_t out_len) { const int iter = luaL_checkinteger(L, 3); if(PKCS5_PBKDF2_HMAC(pass, pass_len, salt, salt_len, iter, evp, out_len, out) == 0) { - return luaL_error(L, "PKCS5_PBKDF2_HMAC() failed"); + return luaL_error(L, ERR_error_string(ERR_get_error(), NULL)); } lua_pushlstring(L, (char *)out, out_len); -- cgit v1.2.3