Software /
code /
prosody
Diff
util-src/hashes.c @ 11560:3bbb1af92514
Merge 0.11->trunk
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 13 May 2021 11:17:13 +0100 |
parent | 10748:93293891709b |
parent | 11541:13b84682518e |
child | 11562:0becc168f4f9 |
line wrap: on
line diff
--- a/util-src/hashes.c Fri May 07 16:47:58 2021 +0200 +++ b/util-src/hashes.c Thu May 13 11:17:13 2021 +0100 @@ -23,6 +23,7 @@ #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 @@ 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 @@ { "scram_Hi_sha1", Lpbkdf2_sha1 }, /* COMPAT */ { "pbkdf2_hmac_sha1", Lpbkdf2_sha1 }, { "pbkdf2_hmac_sha256", Lpbkdf2_sha256 }, + { "equals", Lhash_equals }, { NULL, NULL } };