Commit 925cda0d58 for openssl.org
commit 925cda0d58c143773ba1f54d1fb33e99b1e330b7
Author: Matt Caswell <matt@openssl.foundation>
Date: Wed Aug 19 16:43:21 2026 +0100
Use the SSL_CTX cached HMAC for DTLS listener cookies
dtls_listener_cookie_hmac() fetched an EVP_MAC for "HMAC" on every call.
It runs once per cookie generation and once per verification, so a DTLS
listener paid a provider fetch for every ClientHello it answered.
SSL_CTX already holds a pre-fetched EVP_MAC for exactly this purpose.
SSL_CTX_new() fetches it up front and fails if it cannot, so ctx->hmac
is always usable, and ssl_hmac_init() in ssl/t1_lib.c uses it the same
way. Take the MAC from there instead, which also removes the local
fetch and free.
Assisted-by: Claude Code:claude-opus-5
Reviewed-by: Ryan Hooper <ryanh@openssl.foundation>
Reviewed-by: Tomas Mraz <tomas@openssl.foundation>
Merge-date: Fri Aug 21 18:10:40 2026
Merged-from: https://github.com/openssl/openssl/pull/32441
diff --git a/ssl/d1_lib.c b/ssl/d1_lib.c
index 8cbc339c81..ca3c09aca8 100644
--- a/ssl/d1_lib.c
+++ b/ssl/d1_lib.c
@@ -1581,7 +1581,6 @@ static int dtls_listener_cookie_hmac(SSL *ssl, uint64_t timestamp,
{
SSL_CONNECTION *sc = SSL_CONNECTION_FROM_SSL_ONLY(ssl);
SSL_CTX *ctx;
- EVP_MAC *mac = NULL;
EVP_MAC_CTX *mctx = NULL;
OSSL_PARAM params[2];
/* 8 (timestamp) + 2 (port) + max address size */
@@ -1618,12 +1617,7 @@ static int dtls_listener_cookie_hmac(SSL *ssl, uint64_t timestamp,
return 0;
}
- mac = EVP_MAC_fetch(ctx->libctx, "HMAC", ctx->propq);
- if (mac == NULL)
- goto err;
-
- /* TODO: DTLS1.3 after rebase use ctx's hmac */
- mctx = EVP_MAC_CTX_new(mac);
+ mctx = EVP_MAC_CTX_new(ctx->hmac);
if (mctx == NULL)
goto err;
@@ -1645,7 +1639,6 @@ static int dtls_listener_cookie_hmac(SSL *ssl, uint64_t timestamp,
err:
EVP_MAC_CTX_free(mctx);
- EVP_MAC_free(mac);
return ret;
}