aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--util-src/hashes.c24
1 files changed, 2 insertions, 22 deletions
diff --git a/util-src/hashes.c b/util-src/hashes.c
index 4ad786ae..fbc86081 100644
--- a/util-src/hashes.c
+++ b/util-src/hashes.c
@@ -129,33 +129,15 @@ static int Lsha3_512(lua_State *L) {
static int Levp_hmac(lua_State *L, const EVP_MD *evp) {
unsigned char hash[EVP_MAX_MD_SIZE], result[EVP_MAX_MD_SIZE * 2];
size_t key_len, msg_len;
- size_t out_len = EVP_MAX_MD_SIZE;
+ unsigned int out_len = EVP_MAX_MD_SIZE;
const char *key = luaL_checklstring(L, 1, &key_len);
const char *msg = luaL_checklstring(L, 2, &msg_len);
const int hex_out = lua_toboolean(L, 3);
- EVP_PKEY *pkey = EVP_PKEY_new_raw_private_key(EVP_PKEY_HMAC, NULL, (unsigned char *)key, key_len);
- EVP_MD_CTX *ctx = EVP_MD_CTX_new();
-
- if(ctx == NULL || pkey == NULL) {
- goto fail;
- }
-
- if(!EVP_DigestSignInit(ctx, NULL, evp, NULL, pkey)) {
- goto fail;
- }
-
- if(!EVP_DigestSignUpdate(ctx, msg, msg_len)) {
- goto fail;
- }
-
- if(!EVP_DigestSignFinal(ctx, hash, &out_len)) {
+ if(HMAC(evp, key, key_len, (const unsigned char*)msg, msg_len, (unsigned char*)hash, &out_len) == NULL) {
goto fail;
}
- EVP_MD_CTX_free(ctx);
- EVP_PKEY_free(pkey);
-
if(hex_out) {
toHex(hash, out_len, result);
lua_pushlstring(L, (char *)result, out_len * 2);
@@ -166,8 +148,6 @@ static int Levp_hmac(lua_State *L, const EVP_MD *evp) {
return 1;
fail:
- EVP_MD_CTX_free(ctx);
- EVP_PKEY_free(pkey);
return luaL_error(L, ERR_error_string(ERR_get_error(), NULL));
}