From 4dc59629106890354e0a1ecec5ee3b8e6846f324 Mon Sep 17 00:00:00 2001 From: Martin Matuska Date: Fri, 9 Dec 2022 14:23:14 +0100 Subject: archive_hmac: use EVP_MAC_*() in OpenSSL 3.0 HMAC_*() functions have been deprecated since OpenSSL 3.0 --- libarchive/archive_hmac.c | 29 +++++++++++++++++++++++++++++ libarchive/archive_hmac_private.h | 7 +++++++ 2 files changed, 36 insertions(+) diff --git a/libarchive/archive_hmac.c b/libarchive/archive_hmac.c index 2a9d04c8..012fe159 100644 --- a/libarchive/archive_hmac.c +++ b/libarchive/archive_hmac.c @@ -230,10 +230,23 @@ __hmac_sha1_cleanup(archive_hmac_sha1_ctx *ctx) static int __hmac_sha1_init(archive_hmac_sha1_ctx *ctx, const uint8_t *key, size_t key_len) { +#if OPENSSL_VERSION_NUMBER >= 0x30000000L + OSSL_PARAM params[2]; + + EVP_MAC *mac = EVP_MAC_fetch(NULL, "HMAC", NULL); + *ctx = EVP_MAC_CTX_new(mac); + if (*ctx == NULL) + return -1; + EVP_MAC_free(mac); + params[0] = OSSL_PARAM_construct_utf8_string("digest", "SHA1", 0); + params[1] = OSSL_PARAM_construct_end(); + EVP_MAC_init(*ctx, key, key_len, params); +#else *ctx = HMAC_CTX_new(); if (*ctx == NULL) return -1; HMAC_Init_ex(*ctx, key, key_len, EVP_sha1(), NULL); +#endif return 0; } @@ -241,22 +254,38 @@ static void __hmac_sha1_update(archive_hmac_sha1_ctx *ctx, const uint8_t *data, size_t data_len) { +#if OPENSSL_VERSION_NUMBER >= 0x30000000L + EVP_MAC_update(*ctx, data, data_len); +#else HMAC_Update(*ctx, data, data_len); +#endif } static void __hmac_sha1_final(archive_hmac_sha1_ctx *ctx, uint8_t *out, size_t *out_len) { +#if OPENSSL_VERSION_NUMBER >= 0x30000000L + size_t len = *out_len; +#else unsigned int len = (unsigned int)*out_len; +#endif +#if OPENSSL_VERSION_NUMBER >= 0x30000000L + EVP_MAC_final(*ctx, out, &len, *out_len); +#else HMAC_Final(*ctx, out, &len); +#endif *out_len = len; } static void __hmac_sha1_cleanup(archive_hmac_sha1_ctx *ctx) { +#if OPENSSL_VERSION_NUMBER >= 0x30000000L + EVP_MAC_CTX_free(*ctx); +#else HMAC_CTX_free(*ctx); +#endif *ctx = NULL; } diff --git a/libarchive/archive_hmac_private.h b/libarchive/archive_hmac_private.h index 13a67d49..50044a04 100644 --- a/libarchive/archive_hmac_private.h +++ b/libarchive/archive_hmac_private.h @@ -74,9 +74,16 @@ typedef mbedtls_md_context_t archive_hmac_sha1_ctx; typedef struct hmac_sha1_ctx archive_hmac_sha1_ctx; #elif defined(HAVE_LIBCRYPTO) +#include +#include +#if OPENSSL_VERSION_NUMBER >= 0x30000000L +typedef EVP_MAC_CTX *archive_hmac_sha1_ctx; + +#else #include "archive_openssl_hmac_private.h" typedef HMAC_CTX* archive_hmac_sha1_ctx; +#endif #else -- cgit v1.2.1