[PATCH 01/55] crypto: Free the digest context in crypto_hash_finish()

Ilan Peer ilan.peer at intel.com
Thu Dec 3 02:44:00 PST 2026


The EVP_MD_CTX of a plain (non-HMAC) hash was only freed on the error
path, leaking it on every successful PQC authentication transcript.

Signed-off-by: Ilan Peer <ilan.peer at intel.com>
---
 src/crypto/crypto_openssl.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/crypto/crypto_openssl.c b/src/crypto/crypto_openssl.c
index 2f89a3071613..a83ca256bd7d 100644
--- a/src/crypto/crypto_openssl.c
+++ b/src/crypto/crypto_openssl.c
@@ -1578,11 +1578,12 @@ int crypto_hash_finish(struct crypto_hash *ctx, u8 *mac, size_t *len)
 		unsigned int hlen;
 
 		res = EVP_DigestFinal(ctx->md_ctx, mac, &hlen);
+		EVP_MD_CTX_free(ctx->md_ctx);
 		if (res != 1) {
-			EVP_MD_CTX_free(ctx->md_ctx);
 			bin_clear_free(ctx, sizeof(*ctx));
 			return -1;
 		}
+
 		mdlen = hlen;
 		goto done;
 	}
-- 
2.55.0




More information about the Hostap mailing list