]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
OpenSSL: More debug prints on EVP digest/cipher failures
authorJouni Malinen <j@w1.fi>
Sat, 1 Mar 2025 10:05:48 +0000 (12:05 +0200)
committerJouni Malinen <j@w1.fi>
Sat, 1 Mar 2025 10:05:48 +0000 (12:05 +0200)
The EVP operations may fail if OpenSSL is configured to reject
deprecated algorithms or parameters (e.g., key sizes). Make such errors
easier to understand in debug log.

Signed-off-by: Jouni Malinen <j@w1.fi>
src/crypto/crypto_openssl.c

index 3a4d07175c3def60b52822a4b6752a0299bf14bd..3333f727ab2341c6d5e61718536a88d2d8ba0ccb 100644 (file)
@@ -1371,6 +1371,9 @@ struct crypto_hash * crypto_hash_init(enum crypto_hash_alg alg, const u8 *key,
        }
 
        if (EVP_MAC_init(ctx->ctx, key, key_len, params) != 1) {
+               wpa_printf(MSG_INFO,
+                          "OpenSSL: EVP_MAC_init(hmac,digest=%s) failed: %s",
+                          a, ERR_error_string(ERR_get_error(), NULL));
                EVP_MAC_CTX_free(ctx->ctx);
                bin_clear_free(ctx, sizeof(*ctx));
                ctx = NULL;
@@ -1532,8 +1535,11 @@ static int openssl_hmac_vector(char *digest, const u8 *key,
                return -1;
 
        hmac = EVP_MAC_fetch(NULL, "HMAC", NULL);
-       if (!hmac)
+       if (!hmac) {
+               wpa_printf(MSG_INFO, "OpenSSL: EVP_MAC_fetch(HMAC) failed: %s",
+                          ERR_error_string(ERR_get_error(), NULL));
                return -1;
+       }
 
        params[0] = OSSL_PARAM_construct_utf8_string("digest", digest, 0);
        params[1] = OSSL_PARAM_construct_end();
@@ -1543,8 +1549,13 @@ static int openssl_hmac_vector(char *digest, const u8 *key,
        if (!ctx)
                return -1;
 
-       if (EVP_MAC_init(ctx, key, key_len, params) != 1)
+       if (EVP_MAC_init(ctx, key, key_len, params) != 1) {
+               wpa_printf(MSG_INFO,
+                          "OpenSSL: EVP_MAC_init(hmac,digest=%s,key_len=%zu) failed: %s",
+                          digest, key_len,
+                          ERR_error_string(ERR_get_error(), NULL));
                goto fail;
+       }
 
        for (i = 0; i < num_elem; i++) {
                if (EVP_MAC_update(ctx, addr[i], len[i]) != 1)
@@ -1822,8 +1833,12 @@ int omac1_aes_vector(const u8 *key, size_t key_len, size_t num_elem,
 
        if (!emac || !cipher ||
            !(ctx = EVP_MAC_CTX_new(emac)) ||
-           EVP_MAC_init(ctx, key, key_len, params) != 1)
+           EVP_MAC_init(ctx, key, key_len, params) != 1) {
+               wpa_printf(MSG_INFO,
+                          "OpenSSL: EVP_MAC_init(cmac,cipher=%s) failed: %s",
+                          cipher, ERR_error_string(ERR_get_error(), NULL));
                goto fail;
+       }
 
        for (i = 0; i < num_elem; i++) {
                if (!EVP_MAC_update(ctx, addr[i], len[i]))
@@ -4793,8 +4808,12 @@ static int hpke_labeled_extract(struct hpke_context *ctx, bool kem,
        if (!hctx)
                return -1;
 
-       if (EVP_MAC_init(hctx, salt, salt_len, params) != 1)
+       if (EVP_MAC_init(hctx, salt, salt_len, params) != 1) {
+               wpa_printf(MSG_INFO,
+                          "OpenSSL: EVP_MAC_init(hmac,digest/HPKE) failed: %s",
+                          ERR_error_string(ERR_get_error(), NULL));
                goto fail;
+       }
 
        if (EVP_MAC_update(hctx, (const unsigned char *) "HPKE-v1", 7) != 1 ||
            EVP_MAC_update(hctx, suite_id, suite_id_len) != 1 ||
@@ -4902,8 +4921,12 @@ hpke_labeled_expand(struct hpke_context *ctx, bool kem, const u8 *prk,
                if (!hctx)
                        goto fail;
 
-               if (EVP_MAC_init(hctx, prk, mdlen, params) != 1)
+               if (EVP_MAC_init(hctx, prk, mdlen, params) != 1) {
+                       wpa_printf(MSG_INFO,
+                                  "OpenSSL: EVP_MAC_init(hmac,digest/HPKE) failed: %s",
+                                  ERR_error_string(ERR_get_error(), NULL));
                        goto fail;
+               }
 
                if (iter > 0 && EVP_MAC_update(hctx, hash, mdlen) != 1)
                        goto fail;