File 0667-crypto-hmac_low_level-only-call-HMAC-once-not-twice.patch of Package erlang
From 289fa8314a865695af31aa6a44dd0e42f7a034ec Mon Sep 17 00:00:00 2001
From: Mikael Pettersson <mikael.pettersson@klarna.com>
Date: Thu, 19 Nov 2020 13:07:12 +0100
Subject: [PATCH 3/4] crypto: hmac_low_level(): only call HMAC() once, not
twice
This reinstates logic from the removed hmac_nif().
---
lib/crypto/c_src/hmac.c | 17 +++++------------
1 file changed, 5 insertions(+), 12 deletions(-)
diff --git a/lib/crypto/c_src/hmac.c b/lib/crypto/c_src/hmac.c
index 193902c481..3ea7c1f5dc 100644
--- a/lib/crypto/c_src/hmac.c
+++ b/lib/crypto/c_src/hmac.c
@@ -233,18 +233,19 @@ int hmac_low_level(ErlNifEnv* env, const EVP_MD *md,
{
unsigned int size_int;
size_t size;
+ unsigned char buff[EVP_MAX_MD_SIZE];
- /* Find the needed space */
if (HMAC(md,
key_bin.data, (int)key_bin.size,
text.data, text.size,
- NULL, &size_int) == NULL)
+ buff, &size_int) == NULL)
{
- *return_term = EXCP_ERROR(env, "Get HMAC size failed");
+ *return_term = EXCP_ERROR(env, "HMAC sign failed");
return 0;
}
size = (size_t)size_int; /* Otherwise "size" is unused in 0.9.8.... */
+ ASSERT(0 < size && size <= EVP_MAX_MD_SIZE);
if (!enif_alloc_binary(size, ret_bin))
{
*return_term = EXCP_ERROR(env, "Alloc binary");
@@ -252,15 +253,7 @@ int hmac_low_level(ErlNifEnv* env, const EVP_MD *md,
}
*ret_bin_alloc = 1;
- /* And do the real HMAC calc */
- if (HMAC(md,
- key_bin.data, (int)key_bin.size,
- text.data, text.size,
- ret_bin->data, &size_int) == NULL)
- {
- *return_term = EXCP_ERROR(env, "HMAC sign failed");
- return 0;
- }
+ memcpy(ret_bin->data, buff, size);
return 1;
}
--
2.26.2