From bc36202087316f411d0939510418ed67f5becddd Mon Sep 17 00:00:00 2001 From: Sean Parkinson Date: Thu, 23 Nov 2023 09:51:44 +1000 Subject: [PATCH] TLS_hmac: when no raw hash, make sure maxSz is not neg When padding byte is invalid, the maxSz can be negative. Make maxSz 0 in this case so that blocks doesn't get very large and cause delays. --- src/tls.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/tls.c b/src/tls.c index eaa06a18b..bc09d0841 100644 --- a/src/tls.c +++ b/src/tls.c @@ -1139,6 +1139,8 @@ static int Hmac_UpdateFinal(Hmac* hmac, byte* digest, const byte* in, msgSz &= ~(0 - (msgSz >> 31)); realSz = WOLFSSL_TLS_HMAC_INNER_SZ + msgSz; maxSz = WOLFSSL_TLS_HMAC_INNER_SZ + (sz - 1) - macSz; + /* Make negative result 0 */ + maxSz &= ~(0 - (maxSz >> 31)); /* Calculate #blocks processed in HMAC for max and real data. */ blocks = maxSz >> blockBits;