summaryrefslogtreecommitdiffstats
path: root/crypto/hmac
diff options
context:
space:
mode:
authorDr. David von Oheimb <David.von.Oheimb@siemens.com>2021-03-29 19:42:33 +0200
committerDr. David von Oheimb <David.von.Oheimb@siemens.com>2021-05-08 14:35:03 +0200
commit0a8a6afdfb71e42962921980b51942cea8632697 (patch)
tree745f3e64cca2a9993fc2548f0a80a20dca231bcb /crypto/hmac
parentbea31afef013aaf5638e96e9bed1b633c510d50d (diff)
Add quick one-shot EVP_Q_mac() and deprecation compensation decls for MAC functions
This helps compensating for deprecated functions such as HMAC() and reduces clutter in the crypto lib, apps, and tests. Also fixes memory leaks in generate_cookie_callback() of apps/lib/s_cb.c. and replaces 'B<...>' by 'I<...>' where appropriate in HMAC.pod Partially fixes #14628. Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/14664)
Diffstat (limited to 'crypto/hmac')
-rw-r--r--crypto/hmac/hmac.c42
1 files changed, 11 insertions, 31 deletions
diff --git a/crypto/hmac/hmac.c b/crypto/hmac/hmac.c
index 6c1a70e4bd..6d142f2cbb 100644
--- a/crypto/hmac/hmac.c
+++ b/crypto/hmac/hmac.c
@@ -17,8 +17,9 @@
#include <stdlib.h>
#include <string.h>
#include "internal/cryptlib.h"
-#include <openssl/hmac.h>
#include <openssl/opensslconf.h>
+#include <openssl/hmac.h>
+#include <openssl/core_names.h>
#include "hmac_local.h"
int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len,
@@ -34,13 +35,12 @@ int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len,
if (md != NULL && md != ctx->md && (key == NULL || len < 0))
return 0;
- if (md != NULL) {
+ if (md != NULL)
ctx->md = md;
- } else if (ctx->md) {
+ else if (ctx->md != NULL)
md = ctx->md;
- } else {
+ else
return 0;
- }
/*
* The HMAC construction is not allowed to be used with the
@@ -217,34 +217,14 @@ int HMAC_CTX_copy(HMAC_CTX *dctx, HMAC_CTX *sctx)
}
unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len,
- const unsigned char *d, size_t n, unsigned char *md,
- unsigned int *md_len)
+ const unsigned char *data, size_t data_len,
+ unsigned char *md, unsigned int *md_len)
{
- HMAC_CTX *c = NULL;
- static unsigned char m[EVP_MAX_MD_SIZE];
- static const unsigned char dummy_key[1] = {'\0'};
+ static unsigned char static_md[EVP_MAX_MD_SIZE];
- if (md == NULL)
- md = m;
- if ((c = HMAC_CTX_new()) == NULL)
- goto err;
-
- /* For HMAC_Init_ex, NULL key signals reuse. */
- if (key == NULL && key_len == 0) {
- key = dummy_key;
- }
-
- if (!HMAC_Init_ex(c, key, key_len, evp_md, NULL))
- goto err;
- if (!HMAC_Update(c, d, n))
- goto err;
- if (!HMAC_Final(c, md, md_len))
- goto err;
- HMAC_CTX_free(c);
- return md;
- err:
- HMAC_CTX_free(c);
- return NULL;
+ return EVP_Q_mac(NULL, "HMAC", NULL, EVP_MD_name(evp_md), NULL,
+ key, key_len, data, data_len,
+ md == NULL ? static_md : md, EVP_MD_size(evp_md), md_len);
}
void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags)