copy full inner hashes to hsHashesEch so that it has

the unmodified hrr and sh in the digest
This commit is contained in:
John Bland
2023-10-03 02:03:14 -04:00
parent f6555fd753
commit b62f582fcc

View File

@ -4122,7 +4122,7 @@ int EchConfigGetSupportedCipherSuite(WOLFSSL_EchConfig* config)
} }
/* returns status after we hash the ech inner */ /* returns status after we hash the ech inner */
static int EchHashHelloInner(WOLFSSL* ssl, WOLFSSL_ECH* ech, int server) static int EchHashHelloInner(WOLFSSL* ssl, WOLFSSL_ECH* ech)
{ {
int ret = 0; int ret = 0;
word32 realSz; word32 realSz;
@ -4130,21 +4130,13 @@ static int EchHashHelloInner(WOLFSSL* ssl, WOLFSSL_ECH* ech, int server)
byte falseHeader[HANDSHAKE_HEADER_SZ]; byte falseHeader[HANDSHAKE_HEADER_SZ];
if (ssl == NULL || ech == NULL) if (ssl == NULL || ech == NULL)
return BAD_FUNC_ARG; return BAD_FUNC_ARG;
if (server) realSz = ech->innerClientHelloLen - ech->paddingLen - ech->hpke->Nt;
realSz = ech->innerClientHelloLen + HANDSHAKE_HEADER_SZ;
else
realSz = ech->innerClientHelloLen - ech->paddingLen - ech->hpke->Nt;
tmpHashes = ssl->hsHashes; tmpHashes = ssl->hsHashes;
/* init the ech hashes */ /* init the ech hashes */
if (ssl->hsHashesEch == NULL) { InitHandshakeHashesAndCopy(ssl, ssl->hsHashes, &ssl->hsHashesEch);
ssl->hsHashes = ssl->hsHashesEch;
InitHandshakeHashes(ssl);
ssl->hsHashesEch = ssl->hsHashes;
ssl->hsHashes = tmpHashes;
}
/* swap hsHashes so the regular hash functions work */ /* swap hsHashes so the regular hash functions work */
ssl->hsHashes = ssl->hsHashesEch; ssl->hsHashes = ssl->hsHashesEch;
if (ret == 0 && server == 0) { if (ret == 0) {
/* do the handshake header then the body */ /* do the handshake header then the body */
AddTls13HandShakeHeader(falseHeader, realSz, 0, 0, client_hello, ssl); AddTls13HandShakeHeader(falseHeader, realSz, 0, 0, client_hello, ssl);
ret = HashRaw(ssl, falseHeader, HANDSHAKE_HEADER_SZ); ret = HashRaw(ssl, falseHeader, HANDSHAKE_HEADER_SZ);
@ -4172,7 +4164,7 @@ static int EchHashHelloInner(WOLFSSL* ssl, WOLFSSL_ECH* ech, int server)
if (ret == 0) if (ret == 0)
ret = HashRaw(ssl, ech->innerClientHello, realSz); ret = HashRaw(ssl, ech->innerClientHello, realSz);
/* hash with inner */ /* hash with inner */
if (ret == 0 && server == 0) { if (ret == 0) {
ssl->hsHashes = ssl->hsHashesEchInner; ssl->hsHashes = ssl->hsHashesEchInner;
ret = HashRaw(ssl, ech->innerClientHello, realSz); ret = HashRaw(ssl, ech->innerClientHello, realSz);
} }
@ -4649,7 +4641,7 @@ int SendTls13ClientHello(WOLFSSL* ssl)
#if defined(HAVE_ECH) #if defined(HAVE_ECH)
/* compute the inner hash */ /* compute the inner hash */
if (ssl->options.useEch == 1) { if (ssl->options.useEch == 1) {
ret = EchHashHelloInner(ssl, args->ech, 0); ret = EchHashHelloInner(ssl, args->ech);
} }
#endif #endif
/* compute the outer hash */ /* compute the outer hash */
@ -7414,7 +7406,8 @@ int SendTls13ServerHello(WOLFSSL* ssl, byte extMsgType)
} }
/* replace the last 8 bytes of server random with the accept */ /* replace the last 8 bytes of server random with the accept */
if (((WOLFSSL_ECH*)echX->data)->state == ECH_PARSED_INTERNAL) { if (((WOLFSSL_ECH*)echX->data)->state == ECH_PARSED_INTERNAL) {
ret = EchHashHelloInner(ssl, (WOLFSSL_ECH*)echX->data, 1); ret = InitHandshakeHashesAndCopy(ssl, ssl->hsHashes,
&ssl->hsHashesEch);
if (ret == 0) { if (ret == 0) {
ret = EchWriteAcceptance(ssl, acceptLabel, ret = EchWriteAcceptance(ssl, acceptLabel,
acceptLabelSz, output + RECORD_HEADER_SZ, acceptLabelSz, output + RECORD_HEADER_SZ,