aboutsummaryrefslogtreecommitdiffstats
path: root/util-src/hashes.c
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2019-04-19 13:21:00 +0200
committerKim Alvefur <zash@zash.se>2019-04-19 13:21:00 +0200
commit70bbc77e68d75584b50be3c950ab4c5aed163374 (patch)
tree85cfa9ce102802f9c714781b7a61d2f9c869b2cc /util-src/hashes.c
parent53f4351d9a70341bfa9083be3552b7f0d1f7ffbe (diff)
parent7ef028d8d49684247dfcb0ae276426684bf2d778 (diff)
downloadprosody-70bbc77e68d75584b50be3c950ab4c5aed163374.tar.gz
prosody-70bbc77e68d75584b50be3c950ab4c5aed163374.zip
Merge 0.11->trunk
Diffstat (limited to 'util-src/hashes.c')
-rw-r--r--util-src/hashes.c28
1 files changed, 11 insertions, 17 deletions
diff --git a/util-src/hashes.c b/util-src/hashes.c
index 5cf8b5e7..8de4ef5b 100644
--- a/util-src/hashes.c
+++ b/util-src/hashes.c
@@ -25,6 +25,7 @@ typedef unsigned __int32 uint32_t;
#include "lauxlib.h"
#include <openssl/sha.h>
#include <openssl/md5.h>
+#include <openssl/hmac.h>
#if (LUA_VERSION_NUM == 501)
#define luaL_setfuncs(L, R, N) luaL_register(L, NULL, R)
@@ -112,35 +113,28 @@ static void hmac(struct hash_desc *desc, const char *key, size_t key_len,
desc->Final(result, desc->ctxo);
}
-#define MAKE_HMAC_FUNCTION(myFunc, func, size, type) \
+#define MAKE_HMAC_FUNCTION(myFunc, evp, size, type) \
static int myFunc(lua_State *L) { \
- type ctx, ctxo; \
unsigned char hash[size], result[2*size]; \
size_t key_len, msg_len; \
+ unsigned int out_len; \
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); \
- struct hash_desc desc; \
- desc.Init = (int (*)(void*))func##_Init; \
- desc.Update = (int (*)(void*, const void *, size_t))func##_Update; \
- desc.Final = (int (*)(unsigned char*, void*))func##_Final; \
- desc.digestLength = size; \
- desc.ctx = &ctx; \
- desc.ctxo = &ctxo; \
- hmac(&desc, key, key_len, msg, msg_len, hash); \
+ HMAC(evp(), key, key_len, (const unsigned char*)msg, msg_len, (unsigned char*)hash, &out_len); \
if (hex_out) { \
- toHex(hash, size, result); \
- lua_pushlstring(L, (char*)result, size*2); \
+ toHex(hash, out_len, result); \
+ lua_pushlstring(L, (char*)result, out_len*2); \
} else { \
- lua_pushlstring(L, (char*)hash, size); \
+ lua_pushlstring(L, (char*)hash, out_len); \
} \
return 1; \
}
-MAKE_HMAC_FUNCTION(Lhmac_sha1, SHA1, SHA_DIGEST_LENGTH, SHA_CTX)
-MAKE_HMAC_FUNCTION(Lhmac_sha256, SHA256, SHA256_DIGEST_LENGTH, SHA256_CTX)
-MAKE_HMAC_FUNCTION(Lhmac_sha512, SHA512, SHA512_DIGEST_LENGTH, SHA512_CTX)
-MAKE_HMAC_FUNCTION(Lhmac_md5, MD5, MD5_DIGEST_LENGTH, MD5_CTX)
+MAKE_HMAC_FUNCTION(Lhmac_sha1, EVP_sha1, SHA_DIGEST_LENGTH, SHA_CTX)
+MAKE_HMAC_FUNCTION(Lhmac_sha256, EVP_sha256, SHA256_DIGEST_LENGTH, SHA256_CTX)
+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 LscramHi(lua_State *L) {
union xory {