@@ -4700,37 +4700,30 @@ static int EchCheckAcceptance(WOLFSSL* ssl, const byte* input,
47004700 byte transcriptEchConf [WC_MAX_DIGEST_SIZE ];
47014701 byte expandLabelPrk [WC_MAX_DIGEST_SIZE ];
47024702 byte acceptConfirmation [ECH_ACCEPT_CONFIRMATION_SZ ];
4703-
47044703 /* copy ech hashes to accept */
47054704 ret = InitHandshakeHashesAndCopy (ssl , ssl -> hsHashesEch , & acceptHashes );
4706-
47074705 /* swap hsHashes to acceptHashes */
47084706 tmpHashes = ssl -> hsHashes ;
47094707 ssl -> hsHashes = acceptHashes ;
4710-
47114708 /* hash up to the last 8 bytes */
47124709 if (ret == 0 )
47134710 ret = HashRaw (ssl , input , serverRandomOffset + RAN_LEN -
47144711 ECH_ACCEPT_CONFIRMATION_SZ );
4715-
47164712 /* hash 8 zeros */
47174713 if (ret == 0 )
47184714 ret = HashRaw (ssl , zeros , ECH_ACCEPT_CONFIRMATION_SZ );
4719-
47204715 /* hash the rest of the hello */
4721- if (ret == 0 )
4716+ if (ret == 0 ) {
47224717 ret = HashRaw (ssl , input + serverRandomOffset + RAN_LEN ,
47234718 helloSz + HANDSHAKE_HEADER_SZ - (serverRandomOffset + RAN_LEN ));
4724-
4719+ }
47254720 /* get the modified transcript hash */
47264721 if (ret == 0 )
47274722 ret = GetMsgHash (ssl , transcriptEchConf );
4728-
47294723 if (ret > 0 )
47304724 ret = 0 ;
4731-
47324725 /* pick the right type and size based on mac_algorithm */
4733- if (ret == 0 )
4726+ if (ret == 0 ) {
47344727 switch (ssl -> specs .mac_algorithm ) {
47354728#ifndef NO_SHA256
47364729 case sha256_mac :
@@ -4760,12 +4753,11 @@ static int EchCheckAcceptance(WOLFSSL* ssl, const byte* input,
47604753 ret = -1 ;
47614754 break ;
47624755 }
4763-
4756+ }
47644757 /* extract clientRandomInner with a key of all zeros */
47654758 if (ret == 0 )
47664759 ret = wc_HKDF_Extract (digestType , zeros , digestSize ,
47674760 ssl -> arrays -> clientRandomInner , RAN_LEN , expandLabelPrk );
4768-
47694761 /* tls expand with the confirmation label */
47704762 if (ret == 0 )
47714763 ret = wc_Tls13_HKDF_Expand_Label (acceptConfirmation ,
@@ -4774,52 +4766,39 @@ static int EchCheckAcceptance(WOLFSSL* ssl, const byte* input,
47744766 TLS13_PROTOCOL_LABEL_SZ , echAcceptConfirmationLabel ,
47754767 ECH_ACCEPT_CONFIRMATION_LABEL_SZ , transcriptEchConf , digestSize ,
47764768 digestType );
4777-
47784769 if (ret == 0 ) {
47794770 /* last 8 bytes should match our expand output */
47804771 ret = XMEMCMP (acceptConfirmation ,
47814772 ssl -> arrays -> serverRandom + RAN_LEN - ECH_ACCEPT_CONFIRMATION_SZ ,
47824773 ECH_ACCEPT_CONFIRMATION_SZ );
4783-
47844774 /* ech accepted */
47854775 if (ret == 0 ) {
47864776 /* use the inner random for client random */
47874777 XMEMCPY (ssl -> arrays -> clientRandom , ssl -> arrays -> clientRandomInner ,
47884778 RAN_LEN );
4789-
4790- /* switch back to original hsHashes */
4779+ /* switch back to original hsHashes to free */
47914780 ssl -> hsHashes = tmpHashes ;
4792-
4793- /* free hsHashes */
4794- FreeHandshakeHashes (ssl );
4795-
47964781 /* set the final hsHashes to the ech hashes */
47974782 tmpHashes = ssl -> hsHashesEch ;
4798-
4799- /* set hsHashesEch to NULL to avoid double free */
4800- ssl -> hsHashesEch = NULL ;
48014783 }
48024784 /* ech rejected */
48034785 else {
4804- /* switch to hsHashesEch */
4786+ /* switch to hsHashesEch to free */
48054787 ssl -> hsHashes = ssl -> hsHashesEch ;
4806-
4807- /* free ech hashes */
4808- FreeHandshakeHashes (ssl );
48094788 }
4810-
4789+ /* free hsHashes */
4790+ FreeHandshakeHashes (ssl );
4791+ /* set hsHashesEch to NULL to avoid double free */
4792+ ssl -> hsHashesEch = NULL ;
48114793 /* continue with outer if we failed to verify ech was accepted */
48124794 ret = 0 ;
48134795 }
4814-
48154796 /* switch to acceptHashes */
48164797 ssl -> hsHashes = acceptHashes ;
4817-
48184798 /* free acceptHashes */
48194799 FreeHandshakeHashes (ssl );
4820-
4800+ /* swap to tmp, will ech if accepted, hsHashes if rejected */
48214801 ssl -> hsHashes = tmpHashes ;
4822-
48234802 return ret ;
48244803}
48254804
0 commit comments