255678
diff -up dovecot-2.3.14/src/auth/auth-token.c.opensslhmac dovecot-2.3.14/src/auth/auth-token.c
255678
--- dovecot-2.3.14/src/auth/auth-token.c.opensslhmac	2021-03-04 09:38:06.000000000 +0100
255678
+++ dovecot-2.3.14/src/auth/auth-token.c	2021-03-22 20:44:13.022912242 +0100
6e3858
@@ -161,17 +161,17 @@ void auth_token_deinit(void)
ae961a
 const char *auth_token_get(const char *service, const char *session_pid,
ae961a
 			   const char *username, const char *session_id)
ae961a
 {
ae961a
-	struct hmac_context ctx;
ae961a
+	struct openssl_hmac_context ctx;
ae961a
 	unsigned char result[SHA1_RESULTLEN];
ae961a
 
ae961a
-	hmac_init(&ctx, (const unsigned char*)username, strlen(username),
ae961a
+	openssl_hmac_init(&ctx, (const unsigned char*)username, strlen(username),
ae961a
 		  &hash_method_sha1);
ae961a
-	hmac_update(&ctx, session_pid, strlen(session_pid));
ae961a
+	openssl_hmac_update(&ctx, session_pid, strlen(session_pid));
ae961a
 	if (session_id != NULL && *session_id != '\0')
ae961a
-		hmac_update(&ctx, session_id, strlen(session_id));
ae961a
-	hmac_update(&ctx, service, strlen(service));
ae961a
-	hmac_update(&ctx, auth_token_secret, sizeof(auth_token_secret));
ae961a
-	hmac_final(&ctx, result);
ae961a
+		openssl_hmac_update(&ctx, session_id, strlen(session_id));
ae961a
+	openssl_hmac_update(&ctx, service, strlen(service));
ae961a
+	openssl_hmac_update(&ctx, auth_token_secret, sizeof(auth_token_secret));
ae961a
+	openssl_hmac_final(&ctx, result);
ae961a
 
ae961a
 	return binary_to_hex(result, sizeof(result));
ae961a
 }
255678
diff -up dovecot-2.3.14/src/auth/mech-cram-md5.c.opensslhmac dovecot-2.3.14/src/auth/mech-cram-md5.c
255678
--- dovecot-2.3.14/src/auth/mech-cram-md5.c.opensslhmac	2021-03-04 09:38:06.000000000 +0100
255678
+++ dovecot-2.3.14/src/auth/mech-cram-md5.c	2021-03-22 20:44:13.022912242 +0100
ae961a
@@ -51,7 +51,7 @@ static bool verify_credentials(struct cr
ae961a
 {
ae961a
 	
ae961a
 	unsigned char digest[MD5_RESULTLEN];
ae961a
-        struct hmac_context ctx;
ae961a
+        struct orig_hmac_context ctx;
ae961a
 	const char *response_hex;
ae961a
 
ae961a
 	if (size != CRAM_MD5_CONTEXTLEN) {
ae961a
@@ -60,10 +60,10 @@ static bool verify_credentials(struct cr
ae961a
 		return FALSE;
ae961a
 	}
ae961a
 
ae961a
-	hmac_init(&ctx, NULL, 0, &hash_method_md5);
ae961a
+	orig_hmac_init(&ctx, NULL, 0, &hash_method_md5);
ae961a
 	hmac_md5_set_cram_context(&ctx, credentials);
ae961a
-	hmac_update(&ctx, request->challenge, strlen(request->challenge));
ae961a
-	hmac_final(&ctx, digest);
ae961a
+	orig_hmac_update(&ctx, request->challenge, strlen(request->challenge));
ae961a
+	orig_hmac_final(&ctx, digest);
ae961a
 
ae961a
 	response_hex = binary_to_hex(digest, sizeof(digest));
ae961a
 
255678
diff -up dovecot-2.3.14/src/auth/mech-scram.c.opensslhmac dovecot-2.3.14/src/auth/mech-scram.c
255678
--- dovecot-2.3.14/src/auth/mech-scram.c.opensslhmac	2021-03-04 09:38:06.000000000 +0100
255678
+++ dovecot-2.3.14/src/auth/mech-scram.c	2021-03-22 20:44:13.022912242 +0100
255678
@@ -78,7 +78,7 @@ static const char *get_scram_server_firs
ae961a
 static const char *get_scram_server_final(struct scram_auth_request *request)
ae961a
 {
255678
 	const struct hash_method *hmethod = request->hash_method;
ae961a
-	struct hmac_context ctx;
ae961a
+	struct openssl_hmac_context ctx;
ae961a
 	const char *auth_message;
255678
 	unsigned char server_signature[hmethod->digest_size];
ae961a
 	string_t *str;
255678
@@ -87,9 +87,9 @@ static const char *get_scram_server_fina
ae961a
 			request->server_first_message, ",",
ae961a
 			request->client_final_message_without_proof, NULL);
ae961a
 
255678
-	hmac_init(&ctx, request->server_key, hmethod->digest_size, hmethod);
ae961a
-	hmac_update(&ctx, auth_message, strlen(auth_message));
ae961a
-	hmac_final(&ctx, server_signature);
255678
+	openssl_hmac_init(&ctx, request->server_key, hmethod->digest_size, hmethod);
ae961a
+	openssl_hmac_update(&ctx, auth_message, strlen(auth_message));
ae961a
+	openssl_hmac_final(&ctx, server_signature);
ae961a
 
ae961a
 	str = t_str_new(MAX_BASE64_ENCODED_SIZE(sizeof(server_signature)));
ae961a
 	str_append(str, "v=");
255678
@@ -228,7 +228,7 @@ static bool parse_scram_client_first(str
ae961a
 static bool verify_credentials(struct scram_auth_request *request)
ae961a
 {
255678
 	const struct hash_method *hmethod = request->hash_method;
ae961a
-	struct hmac_context ctx;
ae961a
+	struct openssl_hmac_context ctx;
ae961a
 	const char *auth_message;
255678
 	unsigned char client_key[hmethod->digest_size];
255678
 	unsigned char client_signature[hmethod->digest_size];
255678
@@ -239,9 +239,9 @@ static bool verify_credentials(struct sc
ae961a
 			request->server_first_message, ",",
ae961a
 			request->client_final_message_without_proof, NULL);
ae961a
 
255678
-	hmac_init(&ctx, request->stored_key, hmethod->digest_size, hmethod);
ae961a
-	hmac_update(&ctx, auth_message, strlen(auth_message));
ae961a
-	hmac_final(&ctx, client_signature);
255678
+	openssl_hmac_init(&ctx, request->stored_key, hmethod->digest_size, hmethod);
ae961a
+	openssl_hmac_update(&ctx, auth_message, strlen(auth_message));
ae961a
+	openssl_hmac_final(&ctx, client_signature);
ae961a
 
255678
 	const unsigned char *proof_data = request->proof->data;
ae961a
 	for (i = 0; i < sizeof(client_signature); i++)
255678
diff -up dovecot-2.3.14/src/auth/password-scheme.c.opensslhmac dovecot-2.3.14/src/auth/password-scheme.c
255678
--- dovecot-2.3.14/src/auth/password-scheme.c.opensslhmac	2021-03-04 09:38:06.000000000 +0100
255678
+++ dovecot-2.3.14/src/auth/password-scheme.c	2021-03-22 20:44:13.022912242 +0100
255678
@@ -639,11 +639,11 @@ static void
6e3858
 cram_md5_generate(const char *plaintext, const struct password_generate_params *params ATTR_UNUSED,
ae961a
 		  const unsigned char **raw_password_r, size_t *size_r)
ae961a
 {
ae961a
-	struct hmac_context ctx;
ae961a
+	struct orig_hmac_context ctx;
ae961a
 	unsigned char *context_digest;
ae961a
 
6e3858
 	context_digest = t_malloc_no0(CRAM_MD5_CONTEXTLEN);
ae961a
-	hmac_init(&ctx, (const unsigned char *)plaintext,
ae961a
+	orig_hmac_init(&ctx, (const unsigned char *)plaintext,
ae961a
 		  strlen(plaintext), &hash_method_md5);
ae961a
 	hmac_md5_get_cram_context(&ctx, context_digest);
ae961a
 
255678
diff -up dovecot-2.3.14/src/auth/password-scheme-scram.c.opensslhmac dovecot-2.3.14/src/auth/password-scheme-scram.c
255678
--- dovecot-2.3.14/src/auth/password-scheme-scram.c.opensslhmac	2021-03-04 09:38:06.000000000 +0100
255678
+++ dovecot-2.3.14/src/auth/password-scheme-scram.c	2021-03-22 20:44:13.023912229 +0100
255678
@@ -30,23 +30,23 @@ Hi(const struct hash_method *hmethod, co
255678
    const unsigned char *salt, size_t salt_size, unsigned int i,
255678
    unsigned char *result)
ae961a
 {
ae961a
-	struct hmac_context ctx;
ae961a
+	struct openssl_hmac_context ctx;
255678
 	unsigned char U[hmethod->digest_size];
ae961a
 	unsigned int j, k;
ae961a
 
ae961a
 	/* Calculate U1 */
255678
-	hmac_init(&ctx, str, str_size, hmethod);
ae961a
-	hmac_update(&ctx, salt, salt_size);
ae961a
-	hmac_update(&ctx, "\0\0\0\1", 4);
ae961a
-	hmac_final(&ctx, U);
255678
+	openssl_hmac_init(&ctx, str, str_size, hmethod);
ae961a
+	openssl_hmac_update(&ctx, salt, salt_size);
ae961a
+	openssl_hmac_update(&ctx, "\0\0\0\1", 4);
ae961a
+	openssl_hmac_final(&ctx, U);
ae961a
 
255678
 	memcpy(result, U, hmethod->digest_size);
ae961a
 
ae961a
 	/* Calculate U2 to Ui and Hi */
ae961a
 	for (j = 2; j <= i; j++) {
255678
-		hmac_init(&ctx, str, str_size, hmethod);
ae961a
-		hmac_update(&ctx, U, sizeof(U));
ae961a
-		hmac_final(&ctx, U);
255678
+		openssl_hmac_init(&ctx, str, str_size, hmethod);
ae961a
+		openssl_hmac_update(&ctx, U, sizeof(U));
ae961a
+		openssl_hmac_final(&ctx, U);
255678
 		for (k = 0; k < hmethod->digest_size; k++)
ae961a
 			result[k] ^= U[k];
ae961a
 	}
255678
@@ -102,7 +102,7 @@ int scram_verify(const struct hash_metho
255678
 		 const char *plaintext, const unsigned char *raw_password,
255678
 		 size_t size, const char **error_r)
ae961a
 {
ae961a
-	struct hmac_context ctx;
ae961a
+	struct openssl_hmac_context ctx;
ae961a
 	const char *salt_base64;
ae961a
 	unsigned int iter_count;
ae961a
 	const unsigned char *salt;
255678
@@ -126,9 +126,9 @@ int scram_verify(const struct hash_metho
255678
 	   salt, salt_len, iter_count, salted_password);
ae961a
 
ae961a
 	/* Calculate ClientKey */
255678
-	hmac_init(&ctx, salted_password, sizeof(salted_password), hmethod);
ae961a
-	hmac_update(&ctx, "Client Key", 10);
ae961a
-	hmac_final(&ctx, client_key);
255678
+	openssl_hmac_init(&ctx, salted_password, sizeof(salted_password), hmethod);
ae961a
+	openssl_hmac_update(&ctx, "Client Key", 10);
ae961a
+	openssl_hmac_final(&ctx, client_key);
ae961a
 
ae961a
 	/* Calculate StoredKey */
255678
 	hash_method_get_digest(hmethod, client_key, sizeof(client_key),
255678
@@ -147,7 +147,7 @@ void scram_generate(const struct hash_me
255678
 		    const unsigned char **raw_password_r, size_t *size_r)
ae961a
 {
ae961a
 	string_t *str;
ae961a
-	struct hmac_context ctx;
ae961a
+	struct openssl_hmac_context ctx;
ae961a
 	unsigned char salt[16];
255678
 	unsigned char salted_password[hmethod->digest_size];
255678
 	unsigned char client_key[hmethod->digest_size];
255678
@@ -165,9 +165,9 @@ void scram_generate(const struct hash_me
ae961a
 	   sizeof(salt), SCRAM_DEFAULT_ITERATE_COUNT, salted_password);
ae961a
 
ae961a
 	/* Calculate ClientKey */
255678
-	hmac_init(&ctx, salted_password, sizeof(salted_password), hmethod);
ae961a
-	hmac_update(&ctx, "Client Key", 10);
ae961a
-	hmac_final(&ctx, client_key);
255678
+	openssl_hmac_init(&ctx, salted_password, sizeof(salted_password), hmethod);
ae961a
+	openssl_hmac_update(&ctx, "Client Key", 10);
ae961a
+	openssl_hmac_final(&ctx, client_key);
ae961a
 
ae961a
 	/* Calculate StoredKey */
255678
 	hash_method_get_digest(hmethod, client_key, sizeof(client_key),
255678
@@ -176,9 +176,9 @@ void scram_generate(const struct hash_me
ae961a
 	base64_encode(stored_key, sizeof(stored_key), str);
ae961a
 
ae961a
 	/* Calculate ServerKey */
255678
-	hmac_init(&ctx, salted_password, sizeof(salted_password), hmethod);
ae961a
-	hmac_update(&ctx, "Server Key", 10);
ae961a
-	hmac_final(&ctx, server_key);
255678
+	openssl_hmac_init(&ctx, salted_password, sizeof(salted_password), hmethod);
ae961a
+	openssl_hmac_update(&ctx, "Server Key", 10);
ae961a
+	openssl_hmac_final(&ctx, server_key);
ae961a
 	str_append_c(str, ',');
ae961a
 	base64_encode(server_key, sizeof(server_key), str);
ae961a
 
255678
diff -up dovecot-2.3.14/src/lib/hmac.c.opensslhmac dovecot-2.3.14/src/lib/hmac.c
255678
--- dovecot-2.3.14/src/lib/hmac.c.opensslhmac	2021-03-04 09:38:06.000000000 +0100
255678
+++ dovecot-2.3.14/src/lib/hmac.c	2021-03-22 20:44:13.023912229 +0100
6e3858
@@ -7,6 +7,10 @@
ae961a
  * This software is released under the MIT license.
ae961a
  */
ae961a
 
ae961a
+#include <sys/types.h>
ae961a
+#include <sys/stat.h>
ae961a
+#include <fcntl.h>
ae961a
+#include <unistd.h>
ae961a
 #include "lib.h"
ae961a
 #include "hmac.h"
ae961a
 #include "safe-memset.h"
6e3858
@@ -14,10 +18,65 @@
6e3858
 
6e3858
 #include "hex-binary.h"
ae961a
 
ae961a
-void hmac_init(struct hmac_context *_ctx, const unsigned char *key,
ae961a
+#ifndef HAVE_HMAC_CTX_NEW
ae961a
+#  define HMAC_Init_ex(ctx, key, key_len, md, impl) \
ae961a
+	HMAC_Init_ex(&(ctx), key, key_len, md, impl)
ae961a
+#  define HMAC_Update(ctx, data, len) HMAC_Update(&(ctx), data, len)
ae961a
+#  define HMAC_Final(ctx, md, len) HMAC_Final(&(ctx), md, len)
ae961a
+#  define HMAC_CTX_free(ctx) HMAC_cleanup(&(ctx))
ae961a
+#else
ae961a
+#  define HMAC_CTX_free(ctx) \
ae961a
+	STMT_START { HMAC_CTX_free(ctx); (ctx) = NULL; } STMT_END
ae961a
+#endif
ae961a
+
ae961a
+
ae961a
+void openssl_hmac_init(struct openssl_hmac_context *_ctx, const unsigned char *key,
6e3858
 		size_t key_len, const struct hash_method *meth)
6e3858
 {
6e3858
-	struct hmac_context_priv *ctx = &_ctx->u.priv;
ae961a
+ 	struct openssl_hmac_context_priv *ctx = &_ctx->u.priv;
ae961a
+
ae961a
+	const EVP_MD *md;
6e3858
+	const char *ebuf = NULL;
6e3858
+	const char **error_r = &ebuf;
ae961a
+
ae961a
+	md = EVP_get_digestbyname(meth->name);
ae961a
+	if(md == NULL) {
ae961a
+		if (error_r != NULL) {
ae961a
+			*error_r = t_strdup_printf("Invalid digest %s",
ae961a
+						   meth->name);
ae961a
+		}
ae961a
+		//return FALSE;
ae961a
+	}
ae961a
+
ae961a
+// 	int ec;
ae961a
+
ae961a
+	i_assert(md != NULL);
ae961a
+#ifdef HAVE_HMAC_CTX_NEW
ae961a
+	ctx->ctx = HMAC_CTX_new();
ae961a
+/*	if (ctx->ctx == NULL)
ae961a
+		dcrypt_openssl_error(error_r);*/
ae961a
+#endif
ae961a
+	/*ec = */HMAC_Init_ex(ctx->ctx, key, key_len, md, NULL);
ae961a
+}
ae961a
+
ae961a
+void orig_hmac_init(struct orig_hmac_context *_ctx, const unsigned char *key,
6e3858
+		size_t key_len, const struct hash_method *meth)
6e3858
+{
ae961a
+    static int no_fips = -1;
ae961a
+    if (no_fips == -1) {
ae961a
+        int fd = open("/proc/sys/crypto/fips_enabled", O_RDONLY);
ae961a
+        if (fd != -1)
ae961a
+        {
ae961a
+            char buf[4];
ae961a
+            if (read(fd, buf, 4) > 0)
ae961a
+            {
ae961a
+                no_fips = buf[0] == '0';   
ae961a
+            }
ae961a
+            close(fd);   
ae961a
+        }
ae961a
+    }
ae961a
+    i_assert(no_fips);
ae961a
+	struct orig_hmac_context_priv *ctx = &_ctx->u.priv;
255678
 	unsigned int i;
255678
 	unsigned char k_ipad[meth->block_size];
255678
 	unsigned char k_opad[meth->block_size];
6e3858
@@ -53,9 +112,27 @@ void hmac_init(struct hmac_context *_ctx
255678
 	safe_memset(k_opad, 0, meth->block_size);
ae961a
 }
ae961a
 
ae961a
-void hmac_final(struct hmac_context *_ctx, unsigned char *digest)
ae961a
+void openssl_hmac_final(struct openssl_hmac_context *_ctx, unsigned char *digest)
ae961a
+{
ae961a
+	int ec;
ae961a
+	unsigned char buf[HMAC_MAX_MD_CBLOCK];
ae961a
+	unsigned int outl;
ae961a
+//     const char *ebuf = NULL;
ae961a
+//     const char **error_r = &ebuf;
ae961a
+
ae961a
+    struct openssl_hmac_context_priv *ctx = &_ctx->u.priv;
ae961a
+	ec = HMAC_Final(ctx->ctx, buf, &outl);
ae961a
+	HMAC_CTX_free(ctx->ctx);
ae961a
+	if (ec == 1)
ae961a
+		memcpy(digest, buf, outl);
ae961a
+//	else
ae961a
+//		dcrypt_openssl_error(error_r);
ae961a
+
ae961a
+}
ae961a
+
ae961a
+void orig_hmac_final(struct orig_hmac_context *_ctx, unsigned char *digest)
ae961a
 {
ae961a
-	struct hmac_context_priv *ctx = &_ctx->u.priv;
ae961a
+	struct orig_hmac_context_priv *ctx = &_ctx->u.priv;
ae961a
 
ae961a
 	ctx->hash->result(ctx->ctx, digest);
ae961a
 
6e3858
@@ -63,53 +140,50 @@ void hmac_final(struct hmac_context *_ct
ae961a
 	ctx->hash->result(ctx->ctxo, digest);
ae961a
 }
ae961a
 
ae961a
-buffer_t *t_hmac_data(const struct hash_method *meth,
ae961a
+buffer_t *openssl_t_hmac_data(const struct hash_method *meth,
ae961a
 		      const unsigned char *key, size_t key_len,
ae961a
 		      const void *data, size_t data_len)
ae961a
 {
ae961a
-	struct hmac_context ctx;
ae961a
+	struct openssl_hmac_context ctx;
ae961a
 	i_assert(meth != NULL);
ae961a
 	i_assert(key != NULL && key_len > 0);
ae961a
 	i_assert(data != NULL || data_len == 0);
ae961a
 
6e3858
 	buffer_t *res = t_buffer_create(meth->digest_size);
ae961a
-	hmac_init(&ctx, key, key_len, meth);
ae961a
+	openssl_hmac_init(&ctx, key, key_len, meth);
ae961a
 	if (data_len > 0)
ae961a
-		hmac_update(&ctx, data, data_len);
ae961a
+		openssl_hmac_update(&ctx, data, data_len);
ae961a
 	unsigned char *buf = buffer_get_space_unsafe(res, 0, meth->digest_size);
ae961a
-	hmac_final(&ctx, buf);
ae961a
+	openssl_hmac_final(&ctx, buf);
ae961a
 	return res;
ae961a
 }
ae961a
 
ae961a
-buffer_t *t_hmac_buffer(const struct hash_method *meth,
ae961a
+buffer_t *openssl_t_hmac_buffer(const struct hash_method *meth,
ae961a
 			const unsigned char *key, size_t key_len,
ae961a
 			const buffer_t *data)
ae961a
 {
ae961a
-	return t_hmac_data(meth, key, key_len, data->data, data->used);
ae961a
+	return openssl_t_hmac_data(meth, key, key_len, data->data, data->used);
ae961a
 }
ae961a
 
ae961a
-buffer_t *t_hmac_str(const struct hash_method *meth,
ae961a
+buffer_t *openssl_t_hmac_str(const struct hash_method *meth,
ae961a
 		     const unsigned char *key, size_t key_len,
ae961a
 		     const char *data)
ae961a
 {
ae961a
-	return t_hmac_data(meth, key, key_len, data, strlen(data));
ae961a
+	return openssl_t_hmac_data(meth, key, key_len, data, strlen(data));
ae961a
 }
ae961a
 
6e3858
-void hmac_hkdf(const struct hash_method *method,
6e3858
+void openssl_hmac_hkdf(const struct hash_method *method,
6e3858
 	       const unsigned char *salt, size_t salt_len,
6e3858
 	       const unsigned char *ikm, size_t ikm_len,
6e3858
 	       const unsigned char *info, size_t info_len,
6e3858
 	       buffer_t *okm_r, size_t okm_len)
6e3858
 {
6e3858
+	const EVP_MD *md;
6e3858
+	EVP_PKEY_CTX *pctx;
6e3858
+	int r = 1;
6e3858
+
6e3858
 	i_assert(method != NULL);
6e3858
 	i_assert(okm_len < 255*method->digest_size);
6e3858
-	struct hmac_context key_mac;
6e3858
-	struct hmac_context info_mac;
6e3858
-	size_t remain = okm_len;
6e3858
-	unsigned char prk[method->digest_size];
6e3858
-	unsigned char okm[method->digest_size];
6e3858
-	/* N = ceil(L/HashLen) */
6e3858
-	unsigned int rounds = (okm_len + method->digest_size - 1)/method->digest_size;
6e3858
 
6e3858
 	/* salt and info can be NULL */
6e3858
 	i_assert(salt != NULL || salt_len == 0);
6e3858
@@ -118,35 +192,30 @@ void hmac_hkdf(const struct hash_method
6e3858
 	i_assert(ikm != NULL && ikm_len > 0);
6e3858
 	i_assert(okm_r != NULL && okm_len > 0);
6e3858
 
6e3858
-	/* but they still need valid pointer, reduces
6e3858
-	   complains from static analysers */
6e3858
-	if (salt == NULL)
6e3858
-		salt = &uchar_nul;
6e3858
-	if (info == NULL)
6e3858
-		info = &uchar_nul;
6e3858
-
6e3858
-	/* extract */
6e3858
-	hmac_init(&key_mac, salt, salt_len, method);
6e3858
-	hmac_update(&key_mac, ikm, ikm_len);
6e3858
-	hmac_final(&key_mac, prk);
6e3858
-
6e3858
-	/* expand */
6e3858
-	for (unsigned int i = 0; remain > 0 && i < rounds; i++) {
6e3858
-		unsigned char round = (i+1);
6e3858
-		size_t amt = remain;
6e3858
-		if (amt > method->digest_size)
6e3858
-			amt = method->digest_size;
6e3858
-		hmac_init(&info_mac, prk, method->digest_size, method);
6e3858
-		if (i > 0)
6e3858
-			hmac_update(&info_mac, okm, method->digest_size);
6e3858
-		hmac_update(&info_mac, info, info_len);
6e3858
-		hmac_update(&info_mac, &round, 1);
6e3858
-		memset(okm, 0, method->digest_size);
6e3858
-		hmac_final(&info_mac, okm);
6e3858
-		buffer_append(okm_r, okm, amt);
6e3858
-		remain -= amt;
6e3858
+
6e3858
+	md = EVP_get_digestbyname(method->name);
6e3858
+	pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_HKDF, NULL);
6e3858
+	unsigned char *okm_buf = buffer_get_space_unsafe(okm_r, 0, okm_len);
6e3858
+
6e3858
+	if ((r=EVP_PKEY_derive_init(pctx)) <= 0)
6e3858
+		goto out;
6e3858
+	if ((r=EVP_PKEY_CTX_set_hkdf_md(pctx, md)) <= 0)
6e3858
+		goto out;
6e3858
+	if ((r=EVP_PKEY_CTX_set1_hkdf_salt(pctx, salt, salt_len)) <= 0)
6e3858
+		goto out;
6e3858
+	if ((r=EVP_PKEY_CTX_set1_hkdf_key(pctx, ikm, ikm_len)) <= 0)
6e3858
+		goto out;
6e3858
+	if ((r=EVP_PKEY_CTX_add1_hkdf_info(pctx, info, info_len)) <= 0)
6e3858
+		goto out;
6e3858
+	if ((r=EVP_PKEY_derive(pctx, okm_buf, &okm_len)) <= 0)
6e3858
+		goto out;
6e3858
+
6e3858
+     out:
6e3858
+	EVP_PKEY_CTX_free(pctx);
6e3858
+	if (r <= 0) {
6e3858
+		unsigned long ec = ERR_get_error();
6e3858
+		unsigned char *error = t_strdup_printf("%s", ERR_error_string(ec, NULL));
6e3858
+		i_error("%s", error);
6e3858
 	}
6e3858
 
6e3858
-	safe_memset(prk, 0, sizeof(prk));
6e3858
-	safe_memset(okm, 0, sizeof(okm));
6e3858
 }
255678
diff -up dovecot-2.3.14/src/lib/hmac-cram-md5.c.opensslhmac dovecot-2.3.14/src/lib/hmac-cram-md5.c
255678
--- dovecot-2.3.14/src/lib/hmac-cram-md5.c.opensslhmac	2021-03-04 09:38:06.000000000 +0100
255678
+++ dovecot-2.3.14/src/lib/hmac-cram-md5.c	2021-03-22 20:44:13.023912229 +0100
ae961a
@@ -9,10 +9,10 @@
ae961a
 #include "md5.h"
ae961a
 #include "hmac-cram-md5.h"
ae961a
 
ae961a
-void hmac_md5_get_cram_context(struct hmac_context *_hmac_ctx,
ae961a
+void hmac_md5_get_cram_context(struct orig_hmac_context *_hmac_ctx,
ae961a
 			unsigned char context_digest[CRAM_MD5_CONTEXTLEN])
ae961a
 {
ae961a
-	struct hmac_context_priv *hmac_ctx = &_hmac_ctx->u.priv;
ae961a
+	struct orig_hmac_context_priv *hmac_ctx = &_hmac_ctx->u.priv;
ae961a
 	unsigned char *cdp;
ae961a
 
ae961a
 	struct md5_context *ctx = (void*)hmac_ctx->ctx;
ae961a
@@ -35,10 +35,10 @@ void hmac_md5_get_cram_context(struct hm
ae961a
 	CDPUT(cdp, ctx->d);
ae961a
 }
ae961a
 
ae961a
-void hmac_md5_set_cram_context(struct hmac_context *_hmac_ctx,
ae961a
+void hmac_md5_set_cram_context(struct orig_hmac_context *_hmac_ctx,
ae961a
 			const unsigned char context_digest[CRAM_MD5_CONTEXTLEN])
ae961a
 {
ae961a
-	struct hmac_context_priv *hmac_ctx = &_hmac_ctx->u.priv;
ae961a
+	struct orig_hmac_context_priv *hmac_ctx = &_hmac_ctx->u.priv;
ae961a
 	const unsigned char *cdp;
ae961a
 
ae961a
 	struct md5_context *ctx = (void*)hmac_ctx->ctx;
255678
diff -up dovecot-2.3.14/src/lib/hmac-cram-md5.h.opensslhmac dovecot-2.3.14/src/lib/hmac-cram-md5.h
255678
--- dovecot-2.3.14/src/lib/hmac-cram-md5.h.opensslhmac	2021-03-04 09:38:06.000000000 +0100
255678
+++ dovecot-2.3.14/src/lib/hmac-cram-md5.h	2021-03-22 20:44:13.023912229 +0100
ae961a
@@ -5,9 +5,9 @@
ae961a
 
ae961a
 #define CRAM_MD5_CONTEXTLEN 32
ae961a
 
ae961a
-void hmac_md5_get_cram_context(struct hmac_context *ctx,
ae961a
+void hmac_md5_get_cram_context(struct orig_hmac_context *ctx,
ae961a
 		unsigned char context_digest[CRAM_MD5_CONTEXTLEN]);
ae961a
-void hmac_md5_set_cram_context(struct hmac_context *ctx,
ae961a
+void hmac_md5_set_cram_context(struct orig_hmac_context *ctx,
ae961a
 		const unsigned char context_digest[CRAM_MD5_CONTEXTLEN]);
ae961a
 
ae961a
 
255678
diff -up dovecot-2.3.14/src/lib/hmac.h.opensslhmac dovecot-2.3.14/src/lib/hmac.h
255678
--- dovecot-2.3.14/src/lib/hmac.h.opensslhmac	2021-03-04 09:38:06.000000000 +0100
255678
+++ dovecot-2.3.14/src/lib/hmac.h	2021-03-22 20:44:13.023912229 +0100
255678
@@ -4,60 +4,97 @@
ae961a
 #include "hash-method.h"
ae961a
 #include "sha1.h"
255678
 #include "sha2.h"
ae961a
+#include <openssl/objects.h>
ae961a
+#include <openssl/hmac.h>
6e3858
+#include <openssl/kdf.h>
ae961a
+#include <openssl/err.h>
ae961a
 
255678
 #define HMAC_MAX_CONTEXT_SIZE sizeof(struct sha512_ctx)
ae961a
 
ae961a
-struct hmac_context_priv {
ae961a
+struct openssl_hmac_context_priv {
ae961a
+#ifdef HAVE_HMAC_CTX_NEW
ae961a
+	HMAC_CTX *ctx;
ae961a
+#else
ae961a
+	HMAC_CTX ctx;
ae961a
+#endif
ae961a
+	const struct hash_method *hash;
ae961a
+};
ae961a
+
ae961a
+struct orig_hmac_context_priv {
ae961a
 	char ctx[HMAC_MAX_CONTEXT_SIZE];
ae961a
 	char ctxo[HMAC_MAX_CONTEXT_SIZE];
ae961a
 	const struct hash_method *hash;
ae961a
 };
ae961a
 
ae961a
-struct hmac_context {
ae961a
+struct openssl_hmac_context {
ae961a
+	union {
ae961a
+		struct openssl_hmac_context_priv priv;
ae961a
+		uint64_t padding_requirement;
ae961a
+	} u;
ae961a
+};
ae961a
+
ae961a
+struct orig_hmac_context {
ae961a
 	union {
ae961a
-		struct hmac_context_priv priv;
ae961a
+		struct orig_hmac_context_priv priv;
ae961a
 		uint64_t padding_requirement;
ae961a
 	} u;
ae961a
 };
ae961a
 
ae961a
-void hmac_init(struct hmac_context *ctx, const unsigned char *key,
ae961a
+void openssl_hmac_init(struct openssl_hmac_context *ctx, const unsigned char *key,
6e3858
+		size_t key_len, const struct hash_method *meth);
ae961a
+void openssl_hmac_final(struct openssl_hmac_context *ctx, unsigned char *digest);
ae961a
+
ae961a
+static inline void
ae961a
+openssl_hmac_update(struct openssl_hmac_context *_ctx, const void *data, size_t size)
ae961a
+{
ae961a
+	struct openssl_hmac_context_priv *ctx = &_ctx->u.priv;
ae961a
+	HMAC_Update(ctx->ctx, data, size);
ae961a
+/*	if (ec != 1)
ae961a
+    {
ae961a
+        const char *ebuf = NULL;
ae961a
+        const char **error_r = &ebuf;
ae961a
+		dcrypt_openssl_error(error_r);
ae961a
+    }*/
ae961a
+}
ae961a
+
ae961a
+void orig_hmac_init(struct orig_hmac_context *ctx, const unsigned char *key,
6e3858
 		size_t key_len, const struct hash_method *meth);
6e3858
-void hmac_final(struct hmac_context *ctx, unsigned char *digest);
ae961a
+void orig_hmac_final(struct orig_hmac_context *ctx, unsigned char *digest);
ae961a
 
ae961a
 
ae961a
 static inline void
ae961a
-hmac_update(struct hmac_context *_ctx, const void *data, size_t size)
ae961a
+orig_hmac_update(struct orig_hmac_context *_ctx, const void *data, size_t size)
ae961a
 {
ae961a
-	struct hmac_context_priv *ctx = &_ctx->u.priv;
ae961a
+	struct orig_hmac_context_priv *ctx = &_ctx->u.priv;
ae961a
 
ae961a
 	ctx->hash->loop(ctx->ctx, data, size);
ae961a
 }
ae961a
 
ae961a
-buffer_t *t_hmac_data(const struct hash_method *meth,
ae961a
+buffer_t *openssl_t_hmac_data(const struct hash_method *meth,
ae961a
 		      const unsigned char *key, size_t key_len,
ae961a
 		      const void *data, size_t data_len);
ae961a
-buffer_t *t_hmac_buffer(const struct hash_method *meth,
ae961a
+buffer_t *openssl_t_hmac_buffer(const struct hash_method *meth,
ae961a
 			const unsigned char *key, size_t key_len,
ae961a
 			const buffer_t *data);
ae961a
-buffer_t *t_hmac_str(const struct hash_method *meth,
ae961a
+buffer_t *openssl_t_hmac_str(const struct hash_method *meth,
ae961a
 		     const unsigned char *key, size_t key_len,
ae961a
 		     const char *data);
ae961a
 
6e3858
-void hmac_hkdf(const struct hash_method *method,
6e3858
+void openssl_hmac_hkdf(const struct hash_method *method,
6e3858
 	       const unsigned char *salt, size_t salt_len,
6e3858
 	       const unsigned char *ikm, size_t ikm_len,
6e3858
 	       const unsigned char *info, size_t info_len,
6e3858
 	       buffer_t *okm_r, size_t okm_len);
6e3858
 
6e3858
 static inline buffer_t *
6e3858
-t_hmac_hkdf(const struct hash_method *method,
6e3858
+openssl_t_hmac_hkdf(const struct hash_method *method,
6e3858
 	    const unsigned char *salt, size_t salt_len,
6e3858
 	    const unsigned char *ikm, size_t ikm_len,
6e3858
 	    const unsigned char *info, size_t info_len,
6e3858
 	    size_t okm_len)
6e3858
 {
6e3858
 	buffer_t *okm_buffer = t_buffer_create(okm_len);
6e3858
-	hmac_hkdf(method, salt, salt_len, ikm, ikm_len, info, info_len,
6e3858
+	openssl_hmac_hkdf(method, salt, salt_len, ikm, ikm_len, info, info_len,
6e3858
 		  okm_buffer, okm_len);
6e3858
 	return okm_buffer;
6e3858
 }
255678
diff -up dovecot-2.3.14/src/lib-imap-urlauth/imap-urlauth.c.opensslhmac dovecot-2.3.14/src/lib-imap-urlauth/imap-urlauth.c
255678
--- dovecot-2.3.14/src/lib-imap-urlauth/imap-urlauth.c.opensslhmac	2021-03-04 09:38:06.000000000 +0100
255678
+++ dovecot-2.3.14/src/lib-imap-urlauth/imap-urlauth.c	2021-03-22 20:44:13.023912229 +0100
6e3858
@@ -85,15 +85,15 @@ imap_urlauth_internal_generate(const cha
ae961a
 			       const unsigned char mailbox_key[IMAP_URLAUTH_KEY_LEN],
ae961a
 			       size_t *token_len_r)
ae961a
 {
ae961a
-	struct hmac_context hmac;
ae961a
+	struct openssl_hmac_context hmac;
ae961a
 	unsigned char *token;
ae961a
 
ae961a
 	token = t_new(unsigned char, SHA1_RESULTLEN + 1);
ae961a
 	token[0] = IMAP_URLAUTH_MECH_INTERNAL_VERSION;
ae961a
 
ae961a
-	hmac_init(&hmac, mailbox_key, IMAP_URLAUTH_KEY_LEN, &hash_method_sha1);
ae961a
-	hmac_update(&hmac, rumpurl, strlen(rumpurl));
ae961a
-	hmac_final(&hmac, token+1);
ae961a
+	openssl_hmac_init(&hmac, mailbox_key, IMAP_URLAUTH_KEY_LEN, &hash_method_sha1);
ae961a
+	openssl_hmac_update(&hmac, rumpurl, strlen(rumpurl));
ae961a
+	openssl_hmac_final(&hmac, token+1);
ae961a
 
ae961a
 	*token_len_r = SHA1_RESULTLEN + 1;
ae961a
 	return token;
255678
diff -up dovecot-2.3.14/src/lib/Makefile.am.opensslhmac dovecot-2.3.14/src/lib/Makefile.am
255678
--- dovecot-2.3.14/src/lib/Makefile.am.opensslhmac	2021-03-04 09:38:06.000000000 +0100
255678
+++ dovecot-2.3.14/src/lib/Makefile.am	2021-03-22 20:44:13.023912229 +0100
255678
@@ -352,6 +352,9 @@ headers = \
ae961a
 	wildcard-match.h \
ae961a
 	write-full.h
ae961a
 
ae961a
+liblib_la_LIBADD = $(SSL_LIBS)
ae961a
+liblib_la_CFLAGS = $(SSL_CFLAGS)
ae961a
+
ae961a
 test_programs = test-lib
ae961a
 noinst_PROGRAMS = $(test_programs)
ae961a
 
255678
diff -up dovecot-2.3.14/src/lib-oauth2/oauth2-jwt.c.opensslhmac dovecot-2.3.14/src/lib-oauth2/oauth2-jwt.c
255678
--- dovecot-2.3.14/src/lib-oauth2/oauth2-jwt.c.opensslhmac	2021-03-04 09:38:06.000000000 +0100
255678
+++ dovecot-2.3.14/src/lib-oauth2/oauth2-jwt.c	2021-03-22 20:44:13.024912217 +0100
255678
@@ -106,14 +106,14 @@ oauth2_validate_hmac(const struct oauth2
255678
 	if (oauth2_lookup_hmac_key(set, azp, alg, key_id, &key, error_r) < 0)
255678
 		return -1;
ae961a
 
ae961a
-	struct hmac_context ctx;
255678
-	hmac_init(&ctx, key->data, key->used, method);
255678
-	hmac_update(&ctx, blobs[0], strlen(blobs[0]));
255678
-	hmac_update(&ctx, ".", 1);
255678
-	hmac_update(&ctx, blobs[1], strlen(blobs[1]));
ae961a
+	struct openssl_hmac_context ctx;
255678
+	openssl_hmac_init(&ctx, key->data, key->used, method);
255678
+	openssl_hmac_update(&ctx, blobs[0], strlen(blobs[0]));
255678
+	openssl_hmac_update(&ctx, ".", 1);
255678
+	openssl_hmac_update(&ctx, blobs[1], strlen(blobs[1]));
255678
 	unsigned char digest[method->digest_size];
ae961a
 
255678
-	hmac_final(&ctx, digest);
255678
+	openssl_hmac_final(&ctx, digest);
255678
 
255678
 	buffer_t *their_digest =
255678
 		t_base64url_decode_str(BASE64_DECODE_FLAG_NO_PADDING, blobs[2]);
255678
diff -up dovecot-2.3.14/src/lib-oauth2/test-oauth2-jwt.c.opensslhmac dovecot-2.3.14/src/lib-oauth2/test-oauth2-jwt.c
255678
--- dovecot-2.3.14/src/lib-oauth2/test-oauth2-jwt.c.opensslhmac	2021-03-04 09:38:06.000000000 +0100
255678
+++ dovecot-2.3.14/src/lib-oauth2/test-oauth2-jwt.c	2021-03-22 20:46:09.524440794 +0100
255678
@@ -236,7 +236,7 @@ static void save_key_to(const char *algo
255678
 static void sign_jwt_token_hs256(buffer_t *tokenbuf, buffer_t *key)
ae961a
 {
255678
 	i_assert(key != NULL);
255678
-	buffer_t *sig = t_hmac_buffer(&hash_method_sha256, key->data, key->used,
255678
+	buffer_t *sig = openssl_t_hmac_buffer(&hash_method_sha256, key->data, key->used,
255678
 				      tokenbuf);
255678
 	buffer_append(tokenbuf, ".", 1);
255678
 	base64url_encode(BASE64_ENCODE_FLAG_NO_PADDING, SIZE_MAX,
255678
@@ -246,7 +246,7 @@ static void sign_jwt_token_hs256(buffer_
255678
 static void sign_jwt_token_hs384(buffer_t *tokenbuf, buffer_t *key)
255678
 {
255678
 	i_assert(key != NULL);
255678
-	buffer_t *sig = t_hmac_buffer(&hash_method_sha384, key->data, key->used,
255678
+	buffer_t *sig = openssl_t_hmac_buffer(&hash_method_sha384, key->data, key->used,
255678
 				      tokenbuf);
255678
 	buffer_append(tokenbuf, ".", 1);
255678
 	base64url_encode(BASE64_ENCODE_FLAG_NO_PADDING, SIZE_MAX,
255678
@@ -256,7 +256,7 @@ static void sign_jwt_token_hs384(buffer_
255678
 static void sign_jwt_token_hs512(buffer_t *tokenbuf, buffer_t *key)
255678
 {
255678
 	i_assert(key != NULL);
255678
-	buffer_t *sig = t_hmac_buffer(&hash_method_sha512, key->data, key->used,
255678
+	buffer_t *sig = openssl_t_hmac_buffer(&hash_method_sha512, key->data, key->used,
255678
 				      tokenbuf);
255678
 	buffer_append(tokenbuf, ".", 1);
255678
 	base64url_encode(BASE64_ENCODE_FLAG_NO_PADDING, SIZE_MAX,
255678
diff -up dovecot-2.3.14/src/lib/pkcs5.c.opensslhmac dovecot-2.3.14/src/lib/pkcs5.c
255678
--- dovecot-2.3.14/src/lib/pkcs5.c.opensslhmac	2021-03-04 09:38:06.000000000 +0100
255678
+++ dovecot-2.3.14/src/lib/pkcs5.c	2021-03-22 20:44:13.024912217 +0100
ae961a
@@ -52,7 +52,7 @@ int pkcs5_pbkdf2(const struct hash_metho
ae961a
 	size_t l = (length + hash->digest_size - 1)/hash->digest_size; /* same as ceil(length/hash->digest_size) */
ae961a
 	unsigned char dk[l * hash->digest_size];
ae961a
 	unsigned char *block;
ae961a
-	struct hmac_context hctx;
ae961a
+	struct openssl_hmac_context hctx;
ae961a
 	unsigned int c,i,t;
ae961a
 	unsigned char U_c[hash->digest_size];
ae961a
 
ae961a
@@ -60,17 +60,17 @@ int pkcs5_pbkdf2(const struct hash_metho
ae961a
 		block = &(dk[t*hash->digest_size]);
ae961a
 		/* U_1 = PRF(Password, Salt|| INT_BE32(Block_Number)) */
ae961a
 		c = htonl(t+1);
ae961a
-		hmac_init(&hctx, password, password_len, hash);
ae961a
-		hmac_update(&hctx, salt, salt_len);
ae961a
-		hmac_update(&hctx, &c, sizeof(c));
ae961a
-		hmac_final(&hctx, U_c);
ae961a
+		openssl_hmac_init(&hctx, password, password_len, hash);
ae961a
+		openssl_hmac_update(&hctx, salt, salt_len);
ae961a
+		openssl_hmac_update(&hctx, &c, sizeof(c));
ae961a
+		openssl_hmac_final(&hctx, U_c);
ae961a
 		/* block = U_1 ^ .. ^ U_iter */
ae961a
 		memcpy(block, U_c, hash->digest_size);
ae961a
 		/* U_c = PRF(Password, U_c-1) */
ae961a
 		for(c = 1; c < iter; c++) {
ae961a
-			hmac_init(&hctx, password, password_len, hash);
ae961a
-			hmac_update(&hctx, U_c, hash->digest_size);
ae961a
-			hmac_final(&hctx, U_c);
ae961a
+			openssl_hmac_init(&hctx, password, password_len, hash);
ae961a
+			openssl_hmac_update(&hctx, U_c, hash->digest_size);
ae961a
+			openssl_hmac_final(&hctx, U_c);
ae961a
 			for(i = 0; i < hash->digest_size; i++)
ae961a
 				block[i] ^= U_c[i];
ae961a
 		}
255678
diff -up dovecot-2.3.14/src/lib/test-hmac.c.opensslhmac dovecot-2.3.14/src/lib/test-hmac.c
255678
--- dovecot-2.3.14/src/lib/test-hmac.c.opensslhmac	2021-03-04 09:38:06.000000000 +0100
255678
+++ dovecot-2.3.14/src/lib/test-hmac.c	2021-03-22 20:44:13.024912217 +0100
255678
@@ -206,11 +206,11 @@ static void test_hmac_rfc(void)
6e3858
 	test_begin("hmac sha256 rfc4231 vectors");
6e3858
 	for(size_t i = 0; i < N_ELEMENTS(test_vectors); i++) {
6e3858
 		const struct test_vector *vec = &(test_vectors[i]);
6e3858
-		struct hmac_context ctx;
6e3858
-		hmac_init(&ctx, vec->key, vec->key_len, hash_method_lookup(vec->prf));
6e3858
-		hmac_update(&ctx, vec->data, vec->data_len);
ae961a
+		struct openssl_hmac_context ctx;
ae961a
+		openssl_hmac_init(&ctx, vec->key, vec->key_len, hash_method_lookup(vec->prf));
ae961a
+		openssl_hmac_update(&ctx, vec->data, vec->data_len);
6e3858
 		unsigned char res[SHA256_RESULTLEN];
6e3858
-		hmac_final(&ctx, res);
ae961a
+		openssl_hmac_final(&ctx, res);
6e3858
 		test_assert_idx(memcmp(res, vec->res, vec->res_len) == 0, i);
6e3858
 	}
6e3858
 	test_end();
255678
@@ -221,11 +221,11 @@ static void test_hmac384_rfc(void)
255678
 	test_begin("hmac sha384 rfc4231 vectors");
255678
 	for (size_t i = 0; i < N_ELEMENTS(test_vectors_hmac384); i++) {
255678
 		const struct test_vector *vec = &(test_vectors_hmac384[i]);
255678
-		struct hmac_context ctx;
255678
-		hmac_init(&ctx, vec->key, vec->key_len, hash_method_lookup(vec->prf));
255678
-		hmac_update(&ctx, vec->data, vec->data_len);
255678
+		struct openssl_hmac_context ctx;
255678
+		openssl_hmac_init(&ctx, vec->key, vec->key_len, hash_method_lookup(vec->prf));
255678
+		openssl_hmac_update(&ctx, vec->data, vec->data_len);
255678
 		unsigned char res[SHA384_RESULTLEN];
255678
-		hmac_final(&ctx, res);
255678
+		openssl_hmac_final(&ctx, res);
255678
 		test_assert_idx(memcmp(res, vec->res, vec->res_len) == 0, i);
255678
 	}
255678
 	test_end();
255678
@@ -236,11 +236,11 @@ static void test_hmac512_rfc(void)
255678
 	test_begin("hmac sha512 rfc4231 vectors");
255678
 	for (size_t i = 0; i < N_ELEMENTS(test_vectors_hmac512); i++) {
255678
 		const struct test_vector *vec = &(test_vectors_hmac512[i]);
255678
-		struct hmac_context ctx;
255678
-		hmac_init(&ctx, vec->key, vec->key_len, hash_method_lookup(vec->prf));
255678
-		hmac_update(&ctx, vec->data, vec->data_len);
255678
+		struct openssl_hmac_context ctx;
255678
+		openssl_hmac_init(&ctx, vec->key, vec->key_len, hash_method_lookup(vec->prf));
255678
+		openssl_hmac_update(&ctx, vec->data, vec->data_len);
255678
 		unsigned char res[SHA512_RESULTLEN];
255678
-		hmac_final(&ctx, res);
255678
+		openssl_hmac_final(&ctx, res);
255678
 		test_assert_idx(memcmp(res, vec->res, vec->res_len) == 0, i);
255678
 	}
255678
 	test_end();
255678
@@ -253,7 +253,7 @@ static void test_hmac_buffer(void)
6e3858
 
6e3858
 	buffer_t *tmp;
6e3858
 
6e3858
-	tmp = t_hmac_data(hash_method_lookup(vec->prf), vec->key, vec->key_len,
ae961a
+	tmp = openssl_t_hmac_data(hash_method_lookup(vec->prf), vec->key, vec->key_len,
6e3858
 			  vec->data, vec->data_len);
6e3858
 
6e3858
 	test_assert(tmp->used == vec->res_len &&
255678
@@ -270,7 +270,7 @@ static void test_hkdf_rfc(void)
6e3858
 		buffer_set_used_size(res, 0);
6e3858
 		const struct test_vector_5869 *vec = &(test_vectors_5869[i]);
6e3858
 		const struct hash_method *m = hash_method_lookup(vec->prf);
6e3858
-		hmac_hkdf(m, vec->salt, vec->salt_len, vec->ikm, vec->ikm_len,
6e3858
+		openssl_hmac_hkdf(m, vec->salt, vec->salt_len, vec->ikm, vec->ikm_len,
6e3858
 			  vec->info, vec->info_len, res, vec->okm_len);
6e3858
 		test_assert_idx(memcmp(res->data, vec->okm, vec->okm_len) == 0, i);
6e3858
 	}
255678
@@ -283,7 +283,7 @@ static void test_hkdf_buffer(void)
6e3858
 	test_begin("hkdf temporary buffer");
6e3858
 	const struct test_vector_5869 *vec = &(test_vectors_5869[0]);
6e3858
 	const struct hash_method *m = hash_method_lookup(vec->prf);
6e3858
-	buffer_t *tmp = t_hmac_hkdf(m, vec->salt, vec->salt_len, vec->ikm,
6e3858
+	buffer_t *tmp = openssl_t_hmac_hkdf(m, vec->salt, vec->salt_len, vec->ikm,
6e3858
 				    vec->ikm_len, vec->info, vec->info_len,
6e3858
 				    vec->okm_len);
6e3858
 	test_assert(tmp->used == vec->okm_len &&