Software /
code /
prosody
Comparison
util-src/hashes.c @ 12565:2e0c7f5cd8f8
util.hashes: Return OpenSSL error messages on failure
With luck, might contain more details than just "failed"
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 24 Jun 2022 15:33:04 +0200 |
parent | 12564:36e769c64054 |
child | 12566:91e5cb295ba3 |
comparison
equal
deleted
inserted
replaced
12564:36e769c64054 | 12565:2e0c7f5cd8f8 |
---|---|
26 #include <openssl/crypto.h> | 26 #include <openssl/crypto.h> |
27 #include <openssl/sha.h> | 27 #include <openssl/sha.h> |
28 #include <openssl/md5.h> | 28 #include <openssl/md5.h> |
29 #include <openssl/hmac.h> | 29 #include <openssl/hmac.h> |
30 #include <openssl/evp.h> | 30 #include <openssl/evp.h> |
31 #include <openssl/err.h> | |
31 | 32 |
32 #if (LUA_VERSION_NUM == 501) | 33 #if (LUA_VERSION_NUM == 501) |
33 #define luaL_setfuncs(L, R, N) luaL_register(L, NULL, R) | 34 #define luaL_setfuncs(L, R, N) luaL_register(L, NULL, R) |
34 #endif | 35 #endif |
35 | 36 |
83 | 84 |
84 return 1; | 85 return 1; |
85 | 86 |
86 fail: | 87 fail: |
87 EVP_MD_CTX_free(ctx); | 88 EVP_MD_CTX_free(ctx); |
88 return luaL_error(L, "hash function failed"); | 89 return luaL_error(L, ERR_error_string(ERR_get_error(), NULL)); |
89 } | 90 } |
90 | 91 |
91 static int Lsha1(lua_State *L) { | 92 static int Lsha1(lua_State *L) { |
92 return Levp_hash(L, EVP_sha1()); | 93 return Levp_hash(L, EVP_sha1()); |
93 } | 94 } |
176 return 1; | 177 return 1; |
177 | 178 |
178 fail: | 179 fail: |
179 EVP_MD_CTX_free(ctx); | 180 EVP_MD_CTX_free(ctx); |
180 EVP_PKEY_free(pkey); | 181 EVP_PKEY_free(pkey); |
181 return luaL_error(L, "hash function failed"); | 182 return luaL_error(L, ERR_error_string(ERR_get_error(), NULL)); |
182 } | 183 } |
183 | 184 |
184 static int Lhmac_sha1(lua_State *L) { | 185 static int Lhmac_sha1(lua_State *L) { |
185 return Levp_hmac(L, EVP_sha1()); | 186 return Levp_hmac(L, EVP_sha1()); |
186 } | 187 } |
229 const char *pass = luaL_checklstring(L, 1, &pass_len); | 230 const char *pass = luaL_checklstring(L, 1, &pass_len); |
230 const unsigned char *salt = (unsigned char *)luaL_checklstring(L, 2, &salt_len); | 231 const unsigned char *salt = (unsigned char *)luaL_checklstring(L, 2, &salt_len); |
231 const int iter = luaL_checkinteger(L, 3); | 232 const int iter = luaL_checkinteger(L, 3); |
232 | 233 |
233 if(PKCS5_PBKDF2_HMAC(pass, pass_len, salt, salt_len, iter, evp, out_len, out) == 0) { | 234 if(PKCS5_PBKDF2_HMAC(pass, pass_len, salt, salt_len, iter, evp, out_len, out) == 0) { |
234 return luaL_error(L, "PKCS5_PBKDF2_HMAC() failed"); | 235 return luaL_error(L, ERR_error_string(ERR_get_error(), NULL)); |
235 } | 236 } |
236 | 237 |
237 lua_pushlstring(L, (char *)out, out_len); | 238 lua_pushlstring(L, (char *)out, out_len); |
238 | 239 |
239 return 1; | 240 return 1; |