Skip to content

Commit a4cd2f5

Browse files
committed
Zeroize preMasterSecret in hybrid PQ/T error cases
Fixes zd#21310, reported by YUE LI (Peking University)
1 parent b3f08f3 commit a4cd2f5

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

src/tls.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9985,6 +9985,17 @@ static int TLSX_KeyShare_ProcessPqcHybridClient(WOLFSSL* ssl,
99859985

99869986
ssl->arrays->preMasterSz = ssSzEcc + ssSzPqc;
99879987
}
9988+
else
9989+
#ifdef WOLFSSL_ASYNC_CRYPT
9990+
if (ret != WC_NO_ERR_TRACE(WC_PENDING_E))
9991+
#endif
9992+
{
9993+
/* Clear the pre master secret buffer to prevent leaking any
9994+
* intermediate keys in the error case. Do not use preMasterSz
9995+
* here as it may already been set to the ECC shared secret size,
9996+
* which would be too small due to the PQC offset case. */
9997+
ForceZero(ssl->arrays->preMasterSecret, ENCRYPT_LEN);
9998+
}
99889999

998910000
TLSX_KeyShare_FreeAll(ecc_kse, ssl->heap);
999010001
TLSX_KeyShare_FreeAll(pqc_kse, ssl->heap);
@@ -10721,6 +10732,17 @@ static int TLSX_KeyShare_HandlePqcHybridKeyServer(WOLFSSL* ssl,
1072110732
* the server side. */
1072210733
ssl->namedGroup = keyShareEntry->group;
1072310734
}
10735+
else
10736+
#ifdef WOLFSSL_ASYNC_CRYPT
10737+
if (ret != WC_NO_ERR_TRACE(WC_PENDING_E))
10738+
#endif
10739+
{
10740+
/* Clear the pre master secret buffer to prevent leaking any
10741+
* intermediate keys in the error case. Do not use preMasterSz
10742+
* here as it may already been set to the ECC shared secret size,
10743+
* which would be too small due to the PQC offset case. */
10744+
ForceZero(ssl->arrays->preMasterSecret, ENCRYPT_LEN);
10745+
}
1072410746

1072510747
TLSX_KeyShare_FreeAll(ecc_kse, ssl->heap);
1072610748
TLSX_KeyShare_FreeAll(pqc_kse, ssl->heap);

0 commit comments

Comments
 (0)