Software /
code /
prosody
Comparison
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 |
comparison
equal
deleted
inserted
replaced
11538:30feeb4d9d0b | 11560:3bbb1af92514 |
---|---|
21 #include <inttypes.h> | 21 #include <inttypes.h> |
22 #endif | 22 #endif |
23 | 23 |
24 #include "lua.h" | 24 #include "lua.h" |
25 #include "lauxlib.h" | 25 #include "lauxlib.h" |
26 #include <openssl/crypto.h> | |
26 #include <openssl/sha.h> | 27 #include <openssl/sha.h> |
27 #include <openssl/md5.h> | 28 #include <openssl/md5.h> |
28 #include <openssl/hmac.h> | 29 #include <openssl/hmac.h> |
29 #include <openssl/evp.h> | 30 #include <openssl/evp.h> |
30 | 31 |
131 | 132 |
132 lua_pushlstring(L, (char *)out, SHA256_DIGEST_LENGTH); | 133 lua_pushlstring(L, (char *)out, SHA256_DIGEST_LENGTH); |
133 return 1; | 134 return 1; |
134 } | 135 } |
135 | 136 |
137 static int Lhash_equals(lua_State *L) { | |
138 size_t len1, len2; | |
139 const char *s1 = luaL_checklstring(L, 1, &len1); | |
140 const char *s2 = luaL_checklstring(L, 2, &len2); | |
141 if(len1 == len2) { | |
142 lua_pushboolean(L, CRYPTO_memcmp(s1, s2, len1) == 0); | |
143 } else { | |
144 lua_pushboolean(L, 0); | |
145 } | |
146 return 1; | |
147 } | |
148 | |
136 static const luaL_Reg Reg[] = { | 149 static const luaL_Reg Reg[] = { |
137 { "sha1", Lsha1 }, | 150 { "sha1", Lsha1 }, |
138 { "sha224", Lsha224 }, | 151 { "sha224", Lsha224 }, |
139 { "sha256", Lsha256 }, | 152 { "sha256", Lsha256 }, |
140 { "sha384", Lsha384 }, | 153 { "sha384", Lsha384 }, |
145 { "hmac_sha512", Lhmac_sha512 }, | 158 { "hmac_sha512", Lhmac_sha512 }, |
146 { "hmac_md5", Lhmac_md5 }, | 159 { "hmac_md5", Lhmac_md5 }, |
147 { "scram_Hi_sha1", Lpbkdf2_sha1 }, /* COMPAT */ | 160 { "scram_Hi_sha1", Lpbkdf2_sha1 }, /* COMPAT */ |
148 { "pbkdf2_hmac_sha1", Lpbkdf2_sha1 }, | 161 { "pbkdf2_hmac_sha1", Lpbkdf2_sha1 }, |
149 { "pbkdf2_hmac_sha256", Lpbkdf2_sha256 }, | 162 { "pbkdf2_hmac_sha256", Lpbkdf2_sha256 }, |
163 { "equals", Lhash_equals }, | |
150 { NULL, NULL } | 164 { NULL, NULL } |
151 }; | 165 }; |
152 | 166 |
153 LUALIB_API int luaopen_util_hashes(lua_State *L) { | 167 LUALIB_API int luaopen_util_hashes(lua_State *L) { |
154 #if (LUA_VERSION_NUM > 501) | 168 #if (LUA_VERSION_NUM > 501) |