Changeset

12563:d9a4e28689eb

util.hashes: Bind BLAKE2 algoritms supported by OpenSSL
author Kim Alvefur <zash@zash.se>
date Thu, 10 Sep 2020 21:58:24 +0200
parents 12562:4f4d096a14cb
children 12564:36e769c64054
files teal-src/util/hashes.d.tl util-src/hashes.c util/hmac.lua
diffstat 3 files changed, 25 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/teal-src/util/hashes.d.tl	Thu Sep 10 21:58:25 2020 +0200
+++ b/teal-src/util/hashes.d.tl	Thu Sep 10 21:58:24 2020 +0200
@@ -9,6 +9,8 @@
 	sha384 : hash
 	sha512 : hash
 	md5 : hash
+	blake2s256 : hash
+	blake2b512 : hash
 	hmac_sha1 : hmac
 	hmac_sha256 : hmac
 	hmac_sha224 : hmac
--- a/util-src/hashes.c	Thu Sep 10 21:58:25 2020 +0200
+++ b/util-src/hashes.c	Thu Sep 10 21:58:24 2020 +0200
@@ -112,6 +112,15 @@
 	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 @@
 	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 @@
 	{ "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	},
--- a/util/hmac.lua	Thu Sep 10 21:58:25 2020 +0200
+++ b/util/hmac.lua	Thu Sep 10 21:58:24 2020 +0200
@@ -17,4 +17,6 @@
 	sha256 = hashes.hmac_sha256,
 	sha384 = hashes.hmac_sha384,
 	sha512 = hashes.hmac_sha512,
+	blake2s256 = hashes.hmac_blake2s256,
+	blake2b512 = hashes.hmac_blake2b512,
 };