aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2020-09-10 21:58:24 +0200
committerKim Alvefur <zash@zash.se>2020-09-10 21:58:24 +0200
commitf3d61e394501472062f359e02ce5d3bb10bc4bc8 (patch)
tree48fbb663f22408cb4d966e30e01b0ad3fedc42a2
parent9f932f75595640510f3d36ab6bfe10e673235d9f (diff)
downloadprosody-f3d61e394501472062f359e02ce5d3bb10bc4bc8.tar.gz
prosody-f3d61e394501472062f359e02ce5d3bb10bc4bc8.zip
util.hashes: Bind BLAKE2 algoritms supported by OpenSSL
-rw-r--r--teal-src/util/hashes.d.tl2
-rw-r--r--util-src/hashes.c21
-rw-r--r--util/hmac.lua2
3 files changed, 25 insertions, 0 deletions
diff --git a/teal-src/util/hashes.d.tl b/teal-src/util/hashes.d.tl
index 2784a59b..6932ab72 100644
--- a/teal-src/util/hashes.d.tl
+++ b/teal-src/util/hashes.d.tl
@@ -9,6 +9,8 @@ local record lib
sha384 : hash
sha512 : hash
md5 : hash
+ blake2s256 : hash
+ blake2b512 : hash
hmac_sha1 : hmac
hmac_sha256 : hmac
hmac_sha224 : hmac
diff --git a/util-src/hashes.c b/util-src/hashes.c
index 80740866..2696f177 100644
--- a/util-src/hashes.c
+++ b/util-src/hashes.c
@@ -112,6 +112,15 @@ static int Lmd5(lua_State *L) {
return Levp_hash(L, EVP_md5());
}
+static int Lblake2s256(lua_State *L) {
+ return Levp_hash(L, EVP_blake2s256());
+}
+
+static int Lblake2b512(lua_State *L) {
+ return Levp_hash(L, EVP_blake2b512());
+}
+
+
struct hash_desc {
int (*Init)(void *);
int (*Update)(void *, const void *, size_t);
@@ -189,6 +198,14 @@ static int Lhmac_md5(lua_State *L) {
return Levp_hmac(L, EVP_md5());
}
+static int Lhmac_blake2s256(lua_State *L) {
+ return Levp_hmac(L, EVP_blake2s256());
+}
+
+static int Lhmac_blake2b512(lua_State *L) {
+ return Levp_hmac(L, EVP_blake2b512());
+}
+
static int Levp_pbkdf2(lua_State *L, const EVP_MD *evp, size_t out_len) {
unsigned char out[EVP_MAX_MD_SIZE];
@@ -234,12 +251,16 @@ static const luaL_Reg Reg[] = {
{ "sha384", Lsha384 },
{ "sha512", Lsha512 },
{ "md5", Lmd5 },
+ { "blake2s256", Lblake2s256 },
+ { "blake2b512", Lblake2b512 },
{ "hmac_sha1", Lhmac_sha1 },
{ "hmac_sha224", Lhmac_sha224 },
{ "hmac_sha256", Lhmac_sha256 },
{ "hmac_sha384", Lhmac_sha384 },
{ "hmac_sha512", Lhmac_sha512 },
{ "hmac_md5", Lhmac_md5 },
+ { "hmac_blake2s256", Lhmac_blake2s256 },
+ { "hmac_blake2b512", Lhmac_blake2b512 },
{ "scram_Hi_sha1", Lpbkdf2_sha1 }, /* COMPAT */
{ "pbkdf2_hmac_sha1", Lpbkdf2_sha1 },
{ "pbkdf2_hmac_sha256", Lpbkdf2_sha256 },
diff --git a/util/hmac.lua b/util/hmac.lua
index 994ea93b..ca030259 100644
--- a/util/hmac.lua
+++ b/util/hmac.lua
@@ -17,4 +17,6 @@ return {
sha256 = hashes.hmac_sha256,
sha384 = hashes.hmac_sha384,
sha512 = hashes.hmac_sha512,
+ blake2s256 = hashes.hmac_blake2s256,
+ blake2b512 = hashes.hmac_blake2b512,
};