mirror of
https://github.com/bjc/prosody.git
synced 2025-04-04 13:47:41 +03:00
util.hashes: Add constant-time string comparison (binding to CRYPTO_memcmp)
This commit is contained in:
parent
4c4e764e23
commit
f5460a5037
1 changed files with 14 additions and 0 deletions
|
@ -23,6 +23,7 @@ typedef unsigned __int32 uint32_t;
|
||||||
|
|
||||||
#include "lua.h"
|
#include "lua.h"
|
||||||
#include "lauxlib.h"
|
#include "lauxlib.h"
|
||||||
|
#include <openssl/crypto.h>
|
||||||
#include <openssl/sha.h>
|
#include <openssl/sha.h>
|
||||||
#include <openssl/md5.h>
|
#include <openssl/md5.h>
|
||||||
#include <openssl/hmac.h>
|
#include <openssl/hmac.h>
|
||||||
|
@ -189,6 +190,18 @@ static int LscramHi(lua_State *L) {
|
||||||
return 1;
|
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[] = {
|
static const luaL_Reg Reg[] = {
|
||||||
{ "sha1", Lsha1 },
|
{ "sha1", Lsha1 },
|
||||||
{ "sha224", Lsha224 },
|
{ "sha224", Lsha224 },
|
||||||
|
@ -201,6 +214,7 @@ static const luaL_Reg Reg[] = {
|
||||||
{ "hmac_sha512", Lhmac_sha512 },
|
{ "hmac_sha512", Lhmac_sha512 },
|
||||||
{ "hmac_md5", Lhmac_md5 },
|
{ "hmac_md5", Lhmac_md5 },
|
||||||
{ "scram_Hi_sha1", LscramHi },
|
{ "scram_Hi_sha1", LscramHi },
|
||||||
|
{ "equals", Lhash_equals },
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue