From a4cd2f5f8838fff1e164d96a82e10326b37afa16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Frauenschl=C3=A4ger?= Date: Mon, 9 Mar 2026 10:31:14 +0100 Subject: [PATCH] Zeroize preMasterSecret in hybrid PQ/T error cases Fixes zd#21310, reported by YUE LI (Peking University) --- src/tls.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/tls.c b/src/tls.c index 5ddb1ca40c..ad07167dc6 100644 --- a/src/tls.c +++ b/src/tls.c @@ -9985,6 +9985,17 @@ static int TLSX_KeyShare_ProcessPqcHybridClient(WOLFSSL* ssl, ssl->arrays->preMasterSz = ssSzEcc + ssSzPqc; } + else +#ifdef WOLFSSL_ASYNC_CRYPT + if (ret != WC_NO_ERR_TRACE(WC_PENDING_E)) +#endif + { + /* Clear the pre master secret buffer to prevent leaking any + * intermediate keys in the error case. Do not use preMasterSz + * here as it may already been set to the ECC shared secret size, + * which would be too small due to the PQC offset case. */ + ForceZero(ssl->arrays->preMasterSecret, ENCRYPT_LEN); + } TLSX_KeyShare_FreeAll(ecc_kse, ssl->heap); TLSX_KeyShare_FreeAll(pqc_kse, ssl->heap); @@ -10721,6 +10732,17 @@ static int TLSX_KeyShare_HandlePqcHybridKeyServer(WOLFSSL* ssl, * the server side. */ ssl->namedGroup = keyShareEntry->group; } + else +#ifdef WOLFSSL_ASYNC_CRYPT + if (ret != WC_NO_ERR_TRACE(WC_PENDING_E)) +#endif + { + /* Clear the pre master secret buffer to prevent leaking any + * intermediate keys in the error case. Do not use preMasterSz + * here as it may already been set to the ECC shared secret size, + * which would be too small due to the PQC offset case. */ + ForceZero(ssl->arrays->preMasterSecret, ENCRYPT_LEN); + } TLSX_KeyShare_FreeAll(ecc_kse, ssl->heap); TLSX_KeyShare_FreeAll(pqc_kse, ssl->heap);