]> git.ipfire.org Git - thirdparty/haproxy.git/commit
MEDIUM: quic: optimize HKDF operations by reusing per-thread contexts
authorFrederic Lecaille <flecaille@haproxy.com>
Thu, 28 May 2026 12:49:07 +0000 (14:49 +0200)
committerFrederic Lecaille <flecaille@haproxy.com>
Thu, 28 May 2026 15:47:31 +0000 (17:47 +0200)
commit4e0af590e8384ec5ede80ae725d25bc7178927f2
tree7151dbf07f7d00a9bdd382619988101a6f0a4d7d
parent52ce3167866d7f29ebe773d6a6a5b21774ee29d4
MEDIUM: quic: optimize HKDF operations by reusing per-thread contexts

Allocating and freeing an OpenSSL EVP_PKEY_CTX context via
EVP_PKEY_CTX_new_id() and EVP_PKEY_CTX_free() on every HKDF cryptographic
operation (such as during stateless reset token generation) induces
unnecessary memory allocation overhead.

Optimize this by introducing a global per-thread context array
'quic_tls_hkdf_ctxs'. These contexts are allocated and initialized once
at startup via a POST_CHECK hook (quic_tls_alloc_hkdf_ctxs) and are
properly freed at exit via a POST_DEINIT hook (quic_tls_dealloc_hkdf_ctxs).

The functions quic_hkdf_extract(), quic_hkdf_expand(), and
quic_hkdf_extract_and_expand() now reuse the pre-allocated context
corresponding to the current thread ID ('tid'), removing dynamic
allocations from these frequent execution paths.

As a cleanup, quic_hkdf_expand() is now static and unexported from the
header file.

Should be easily backported to all versions for optimization purposes.
include/haproxy/quic_tls.h
src/quic_tls.c