# HG changeset patch # User Kim Alvefur # Date 1656077584 -7200 # Node ID 2e0c7f5cd8f8c54c536d71ce2ac2eccb352ee5c5 # Parent 36e769c640540282aee30b907169281a7f85c62c util.hashes: Return OpenSSL error messages on failure With luck, might contain more details than just "failed" diff -r 36e769c64054 -r 2e0c7f5cd8f8 util-src/hashes.c --- a/util-src/hashes.c Thu Sep 10 21:58:24 2020 +0200 +++ b/util-src/hashes.c Fri Jun 24 15:33:04 2022 +0200 @@ -28,6 +28,7 @@ #include #include #include +#include #if (LUA_VERSION_NUM == 501) #define luaL_setfuncs(L, R, N) luaL_register(L, NULL, R) @@ -85,7 +86,7 @@ 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 @@ 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 @@ 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);