]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
OpenSSL: Clean up openssl_digest_vector() to use a single implementation
authorJouni Malinen <jouni@qca.qualcomm.com>
Fri, 15 Jan 2016 12:17:16 +0000 (14:17 +0200)
committerJouni Malinen <j@w1.fi>
Fri, 15 Jan 2016 12:17:16 +0000 (14:17 +0200)
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 <jouni@qca.qualcomm.com>
src/crypto/crypto_openssl.c

index 963d9bc7be528f19f90d4a9180b1b58ca5dc48ec..071a4dcc92262fcdb0b839bd28e6da86a1eff090 100644 (file)
@@ -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
 }