@@ -7462,43 +7462,49 @@ int InitHandshakeHashes(WOLFSSL* ssl)
74627462 return ret;
74637463}
74647464
7465- void FreeHandshakeHashes(WOLFSSL* ssl )
7465+ void Free_HS_Hashes(HS_Hashes* hsHashes, void* heap )
74667466{
7467- if (ssl-> hsHashes) {
7467+ if (hsHashes) {
74687468 #if !defined(NO_MD5) && !defined(NO_OLD_TLS)
7469- wc_Md5Free(&ssl-> hsHashes->hashMd5);
7469+ wc_Md5Free(&hsHashes->hashMd5);
74707470 #endif
74717471 #if !defined(NO_SHA) && (!defined(NO_OLD_TLS) || \
74727472 defined(WOLFSSL_ALLOW_TLS_SHA1))
7473- wc_ShaFree(&ssl-> hsHashes->hashSha);
7473+ wc_ShaFree(&hsHashes->hashSha);
74747474 #endif
74757475 #ifndef NO_SHA256
7476- wc_Sha256Free(&ssl-> hsHashes->hashSha256);
7476+ wc_Sha256Free(&hsHashes->hashSha256);
74777477 #endif
74787478 #ifdef WOLFSSL_SHA384
7479- wc_Sha384Free(&ssl-> hsHashes->hashSha384);
7479+ wc_Sha384Free(&hsHashes->hashSha384);
74807480 #endif
74817481 #ifdef WOLFSSL_SHA512
7482- wc_Sha512Free(&ssl-> hsHashes->hashSha512);
7482+ wc_Sha512Free(&hsHashes->hashSha512);
74837483 #endif
74847484 #ifdef WOLFSSL_SM3
7485- wc_Sm3Free(&ssl-> hsHashes->hashSm3);
7485+ wc_Sm3Free(&hsHashes->hashSm3);
74867486 #endif
74877487 #if (defined(HAVE_ED25519) || defined(HAVE_ED448) || \
74887488 (defined(WOLFSSL_SM2) && defined(WOLFSSL_SM3))) && \
74897489 !defined(WOLFSSL_NO_CLIENT_AUTH)
7490- if (ssl-> hsHashes->messages != NULL) {
7491- ForceZero(ssl-> hsHashes->messages, (word32)ssl-> hsHashes->length);
7492- XFREE(ssl-> hsHashes->messages, ssl-> heap, DYNAMIC_TYPE_HASHES);
7493- ssl-> hsHashes->messages = NULL;
7490+ if (hsHashes->messages != NULL) {
7491+ ForceZero(hsHashes->messages, (word32)hsHashes->length);
7492+ XFREE(hsHashes->messages, heap, DYNAMIC_TYPE_HASHES);
7493+ hsHashes->messages = NULL;
74947494 }
74957495 #endif
74967496
7497- XFREE(ssl-> hsHashes, ssl-> heap, DYNAMIC_TYPE_HASHES);
7498- ssl-> hsHashes = NULL;
7497+ XFREE(hsHashes, heap, DYNAMIC_TYPE_HASHES);
7498+ hsHashes = NULL;
74997499 }
75007500}
75017501
7502+ void FreeHandshakeHashes(WOLFSSL* ssl)
7503+ {
7504+ Free_HS_Hashes(ssl->hsHashes, ssl->heap);
7505+ ssl->hsHashes = NULL;
7506+ }
7507+
75027508/* copy the hashes from source to a newly made destination return status */
75037509int InitHandshakeHashesAndCopy(WOLFSSL* ssl, HS_Hashes* source,
75047510 HS_Hashes** destination)
@@ -7509,15 +7515,8 @@ int InitHandshakeHashesAndCopy(WOLFSSL* ssl, HS_Hashes* source,
75097515 return BAD_FUNC_ARG;
75107516
75117517 /* If *destination is already allocated, its constituent hashes need to be
7512- * freed, else they would leak. To keep things simple, we reuse
7513- * FreeHandshakeHashes(), which deallocates *destination.
7514- */
7515- if (*destination != NULL) {
7516- HS_Hashes* tmp = ssl->hsHashes;
7517- ssl->hsHashes = *destination;
7518- FreeHandshakeHashes(ssl);
7519- ssl->hsHashes = tmp;
7520- }
7518+ * freed, else they would leak. */
7519+ Free_HS_Hashes(*destination, ssl->heap);
75217520
75227521 /* allocate handshake hashes */
75237522 *destination = (HS_Hashes*)XMALLOC(sizeof(HS_Hashes), ssl->heap,
@@ -8065,6 +8064,24 @@ int InitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup)
80658064 }
80668065 ssl->options.dtls = ssl->version.major == DTLS_MAJOR;
80678066
8067+
8068+ #ifdef WOLFSSL_DTLS13
8069+ /* setup 0 (un-protected) epoch */
8070+ ssl->dtls13Epochs[0].isValid = 1;
8071+ ssl->dtls13Epochs[0].side = ENCRYPT_AND_DECRYPT_SIDE;
8072+ ssl->dtls13EncryptEpoch = &ssl->dtls13Epochs[0];
8073+ ssl->dtls13DecryptEpoch = &ssl->dtls13Epochs[0];
8074+ ssl->options.dtls13SendMoreAcks = WOLFSSL_DTLS13_SEND_MOREACK_DEFAULT;
8075+ ssl->dtls13Rtx.rtxRecordTailPtr = &ssl->dtls13Rtx.rtxRecords;
8076+
8077+ #ifdef WOLFSSL_RW_THREADED
8078+ ret = wc_InitMutex(&ssl->dtls13Rtx.mutex);
8079+ if (ret < 0) {
8080+ return ret;
8081+ }
8082+ #endif
8083+ #endif /* WOLFSSL_DTLS13 */
8084+
80688085#ifdef HAVE_WRITE_DUP
80698086 if (writeDup) {
80708087 /* all done */
@@ -8176,24 +8193,6 @@ int InitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup)
81768193 }
81778194#endif /* HAVE_SECURE_RENEGOTIATION */
81788195
8179-
8180- #ifdef WOLFSSL_DTLS13
8181- /* setup 0 (un-protected) epoch */
8182- ssl->dtls13Epochs[0].isValid = 1;
8183- ssl->dtls13Epochs[0].side = ENCRYPT_AND_DECRYPT_SIDE;
8184- ssl->dtls13EncryptEpoch = &ssl->dtls13Epochs[0];
8185- ssl->dtls13DecryptEpoch = &ssl->dtls13Epochs[0];
8186- ssl->options.dtls13SendMoreAcks = WOLFSSL_DTLS13_SEND_MOREACK_DEFAULT;
8187- ssl->dtls13Rtx.rtxRecordTailPtr = &ssl->dtls13Rtx.rtxRecords;
8188-
8189- #ifdef WOLFSSL_RW_THREADED
8190- ret = wc_InitMutex(&ssl->dtls13Rtx.mutex);
8191- if (ret < 0) {
8192- return ret;
8193- }
8194- #endif
8195- #endif /* WOLFSSL_DTLS13 */
8196-
81978196#ifdef WOLFSSL_QUIC
81988197 if (ctx->quic.method) {
81998198 ret = wolfSSL_set_quic_method(ssl, ctx->quic.method);
@@ -26094,6 +26093,10 @@ static int CheckTLS13AEADSendLimit(WOLFSSL* ssl)
2609426093 }
2609526094#ifdef WOLFSSL_DTLS13
2609626095 if (ssl->options.dtls) {
26096+ if (ssl->dtls13EncryptEpoch == NULL) {
26097+ WOLFSSL_MSG("DTLS 1.3 encrypt epoch not set");
26098+ return BAD_STATE_E;
26099+ }
2609726100 seq = ssl->dtls13EncryptEpoch->nextSeqNumber;
2609826101 }
2609926102 else
@@ -26324,6 +26327,8 @@ int SendData(WOLFSSL* ssl, const void* data, size_t sz)
2632426327 else {
2632526328 /* advance sent to previous sent + plain size just sent */
2632626329 sent = ssl->buffers.prevSent + ssl->buffers.plainSz;
26330+ ssl->buffers.prevSent = 0;
26331+ ssl->buffers.plainSz = 0;
2632726332 WOLFSSL_MSG("sent write buffered data");
2632826333
2632926334 if (sent > (word32)sz) {
0 commit comments