From ac2053b1032a4413e77de11ac94fe747f1415b93 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Fri, 15 Jan 2016 14:17:16 +0200 Subject: [PATCH] OpenSSL: Clean up openssl_digest_vector() to use a single implementation Use compatibility wrapper functions to allow a single implementation based on the latest OpenSSL API to be used to implement these functions instead of having to maintain two conditional implementation based on the library version. Signed-off-by: Jouni Malinen --- src/crypto/crypto_openssl.c | 48 +++++++++++++------------------------ 1 file changed, 17 insertions(+), 31 deletions(-) diff --git a/src/crypto/crypto_openssl.c b/src/crypto/crypto_openssl.c index 963d9bc7b..071a4dcc9 100644 --- a/src/crypto/crypto_openssl.c +++ b/src/crypto/crypto_openssl.c @@ -56,6 +56,23 @@ static void HMAC_CTX_free(HMAC_CTX *ctx) bin_clear_free(ctx, sizeof(*ctx)); } + +static EVP_MD_CTX * EVP_MD_CTX_new(void) +{ + EVP_MD_CTX *ctx; + + ctx = os_zalloc(sizeof(*ctx)); + if (ctx) + EVP_MD_CTX_init(ctx); + return ctx; +} + + +static void EVP_MD_CTX_free(EVP_MD_CTX *ctx) +{ + bin_clear_free(ctx, sizeof(*ctx)); +} + #endif /* OpenSSL version < 1.1.0 */ static BIGNUM * get_group5_prime(void) @@ -92,7 +109,6 @@ static BIGNUM * get_group5_prime(void) static int openssl_digest_vector(const EVP_MD *type, size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac) { -#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER) EVP_MD_CTX *ctx; size_t i; unsigned int mac_len; @@ -127,36 +143,6 @@ static int openssl_digest_vector(const EVP_MD *type, size_t num_elem, EVP_MD_CTX_free(ctx); return 0; -#else - EVP_MD_CTX ctx; - size_t i; - unsigned int mac_len; - - if (TEST_FAIL()) - return -1; - - EVP_MD_CTX_init(&ctx); - if (!EVP_DigestInit_ex(&ctx, type, NULL)) { - wpa_printf(MSG_ERROR, "OpenSSL: EVP_DigestInit_ex failed: %s", - ERR_error_string(ERR_get_error(), NULL)); - return -1; - } - for (i = 0; i < num_elem; i++) { - if (!EVP_DigestUpdate(&ctx, addr[i], len[i])) { - wpa_printf(MSG_ERROR, "OpenSSL: EVP_DigestUpdate " - "failed: %s", - ERR_error_string(ERR_get_error(), NULL)); - return -1; - } - } - if (!EVP_DigestFinal(&ctx, mac, &mac_len)) { - wpa_printf(MSG_ERROR, "OpenSSL: EVP_DigestFinal failed: %s", - ERR_error_string(ERR_get_error(), NULL)); - return -1; - } - - return 0; -#endif }