From b6bf5bfd15a1f6559aad554ce169c9238ca45e52 Mon Sep 17 00:00:00 2001 From: Dirkjan Bussink Date: Sat, 12 Dec 2020 17:25:09 +0100 Subject: [PATCH] Improve cleanup logic for HMAC Older OpenSSL version have a cleanup function that can be used here. This removes a whole bunch of now no longer needed logic and custom conditionals. These functions have existed since 0.9.8 and can be used here. Signed-off-by: Dirkjan Bussink Reviewed-by: Jakub Jelen --- src/libcrypto-compat.c | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/src/libcrypto-compat.c b/src/libcrypto-compat.c index a42b3073..1d1bb10d 100644 --- a/src/libcrypto-compat.c +++ b/src/libcrypto-compat.c @@ -291,25 +291,10 @@ HMAC_CTX *HMAC_CTX_new(void) return ctx; } -static void hmac_ctx_cleanup(HMAC_CTX *ctx) -{ - EVP_MD_CTX_reset(&ctx->i_ctx); - EVP_MD_CTX_reset(&ctx->o_ctx); - EVP_MD_CTX_reset(&ctx->md_ctx); - ctx->md = NULL; - ctx->key_length = 0; - OPENSSL_cleanse(ctx->key, sizeof(ctx->key)); -} - void HMAC_CTX_free(HMAC_CTX *ctx) { if (ctx != NULL) { - hmac_ctx_cleanup(ctx); -#if OPENSSL_VERSION_NUMBER > 0x10100000L - EVP_MD_CTX_free(&ctx->i_ctx); - EVP_MD_CTX_free(&ctx->o_ctx); - EVP_MD_CTX_free(&ctx->md_ctx); -#endif + HMAC_CTX_cleanup(ctx); OPENSSL_free(ctx); } }