diff options
author | Matthew Wild <mwild1@gmail.com> | 2021-05-13 11:17:13 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2021-05-13 11:17:13 +0100 |
commit | 5bc8b2a379e21901429e4d7f5e10e424ca85e403 (patch) | |
tree | dc46f3423a4319e09fe85402fa76f15568ad89d1 /util-src/hashes.c | |
parent | 37ad3b8fb2039684273b3cb63b5b573e879b04d7 (diff) | |
parent | a95576d485eda2a273b4d66c4c2b363f88c5c43a (diff) | |
download | prosody-5bc8b2a379e21901429e4d7f5e10e424ca85e403.tar.gz prosody-5bc8b2a379e21901429e4d7f5e10e424ca85e403.zip |
Merge 0.11->trunk
Diffstat (limited to 'util-src/hashes.c')
-rw-r--r-- | util-src/hashes.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/util-src/hashes.c b/util-src/hashes.c index 84a604ef..31b52f40 100644 --- a/util-src/hashes.c +++ b/util-src/hashes.c @@ -23,6 +23,7 @@ typedef unsigned __int32 uint32_t; #include "lua.h" #include "lauxlib.h" +#include <openssl/crypto.h> #include <openssl/sha.h> #include <openssl/md5.h> #include <openssl/hmac.h> @@ -133,6 +134,18 @@ static int Lpbkdf2_sha256(lua_State *L) { return 1; } +static int Lhash_equals(lua_State *L) { + size_t len1, len2; + const char *s1 = luaL_checklstring(L, 1, &len1); + const char *s2 = luaL_checklstring(L, 2, &len2); + if(len1 == len2) { + lua_pushboolean(L, CRYPTO_memcmp(s1, s2, len1) == 0); + } else { + lua_pushboolean(L, 0); + } + return 1; +} + static const luaL_Reg Reg[] = { { "sha1", Lsha1 }, { "sha224", Lsha224 }, @@ -147,6 +160,7 @@ static const luaL_Reg Reg[] = { { "scram_Hi_sha1", Lpbkdf2_sha1 }, /* COMPAT */ { "pbkdf2_hmac_sha1", Lpbkdf2_sha1 }, { "pbkdf2_hmac_sha256", Lpbkdf2_sha256 }, + { "equals", Lhash_equals }, { NULL, NULL } }; |