@@ -7658,6 +7658,13 @@ static int TLSX_KeyShare_GenPqcKey(WOLFSSL *ssl, KeyShareEntry* kse)
76587658 word32 privSz = 0 ;
76597659 word32 pubSz = 0 ;
76607660
7661+ /* This gets called twice. Once during parsing of the key share and once
7662+ * during the population of the extension. No need to do work the second
7663+ * time. Just return success if its already been done. */
7664+ if (kse -> pubKey != NULL ) {
7665+ return ret ;
7666+ }
7667+
76617668 findEccPqc (& ecc_group , & oqs_group , kse -> group );
76627669 ret = kyber_id2type (oqs_group , & type );
76637670 if (ret == NOT_COMPILED_IN ) {
@@ -7735,10 +7742,11 @@ static int TLSX_KeyShare_GenPqcKey(WOLFSSL *ssl, KeyShareEntry* kse)
77357742
77367743 /* Note we are saving the OQS private key and ECC private key
77377744 * separately. That's because the ECC private key is not simply a
7738- * buffer. Its is an ecc_key struct.
7739- */
7745+ * buffer. Its is an ecc_key struct. Typically do not need the private
7746+ * key size, but will need to zero it out upon freeing. * /
77407747 kse -> privKey = privKey ;
77417748 privKey = NULL ;
7749+ kse -> privKeyLen = privSz ;
77427750
77437751 kse -> key = ecc_kse -> key ;
77447752 ecc_kse -> key = NULL ;
@@ -7814,9 +7822,19 @@ static void TLSX_KeyShare_FreeAll(KeyShareEntry* list, void* heap)
78147822#endif
78157823 }
78167824#ifdef HAVE_PQC
7817- else if (WOLFSSL_NAMED_GROUP_IS_PQC (current -> group ) &&
7818- current -> key != NULL) {
7819- ForceZero ((byte * )current -> key , current -> keyLen );
7825+ else if (WOLFSSL_NAMED_GROUP_IS_PQC (current -> group )) {
7826+ if (current -> key != NULL ) {
7827+ ForceZero ((byte * )current -> key , current -> keyLen );
7828+ }
7829+ if (current -> pubKey != NULL ) {
7830+ XFREE (current -> pubKey , heap , DYNAMIC_TYPE_PUBLIC_KEY );
7831+ current -> pubKey = NULL ;
7832+ }
7833+ if (current -> privKey != NULL ) {
7834+ ForceZero (current -> privKey , current -> privKeyLen );
7835+ XFREE (current -> privKey , heap , DYNAMIC_TYPE_PRIVATE_KEY );
7836+ current -> privKey = NULL ;
7837+ }
78207838 }
78217839#endif
78227840 else {
0 commit comments