@@ -21211,10 +21211,8 @@ static byte MaskMac(const byte* data, int sz, int macSz, byte* expMac)
2121121211 volatile int scanStart = sz - 1 - TLS_MAX_PAD_SZ - macSz;
2121221212 volatile int macEnd = sz - 1 - data[sz - 1];
2121321213 volatile int macStart = macEnd - macSz;
21214- volatile int maskScanStart;
21215- volatile int maskMacStart;
21216- volatile unsigned char started;
21217- volatile unsigned char notEnded;
21214+ int maskScanStart;
21215+ int maskMacStart;
2121821216 unsigned char good = 0;
2121921217
2122021218 maskScanStart = ctMaskIntGTE(scanStart, 0);
@@ -21224,22 +21222,31 @@ static byte MaskMac(const byte* data, int sz, int macSz, byte* expMac)
2122421222
2122521223 /* Div on Intel has different speeds depending on value.
2122621224 * Use a bitwise AND or mod a specific value (converted to mul). */
21227- if ((macSz & (macSz - 1)) == 0)
21228- r = (macSz - (scanStart - macStart)) & (macSz - 1);
21225+ if ((macSz & (macSz - 1)) == 0) {
21226+ r = macSz - scanStart;
21227+ r += macStart;
21228+ r &= (macSz - 1);
21229+ }
2122921230#ifndef NO_SHA
21230- else if (macSz == WC_SHA_DIGEST_SIZE)
21231- r = (macSz - (scanStart - macStart)) % WC_SHA_DIGEST_SIZE;
21231+ else if (macSz == WC_SHA_DIGEST_SIZE) {
21232+ r = macSz - scanStart;
21233+ r += macStart;
21234+ r %= WC_SHA_DIGEST_SIZE;
21235+ }
2123221236#endif
2123321237#ifdef WOLFSSL_SHA384
21234- else if (macSz == WC_SHA384_DIGEST_SIZE)
21235- r = (macSz - (scanStart - macStart)) % WC_SHA384_DIGEST_SIZE;
21238+ else if (macSz == WC_SHA384_DIGEST_SIZE) {
21239+ r = macSz - scanStart;
21240+ r += macStart;
21241+ r %= WC_SHA384_DIGEST_SIZE;
21242+ }
2123621243#endif
2123721244
2123821245 XMEMSET(mac, 0, (size_t)(macSz));
2123921246 for (i = scanStart; i < sz; i += macSz) {
2124021247 for (j = 0; j < macSz && j + i < sz; j++) {
21241- started = ctMaskGTE(i + j, macStart);
21242- notEnded = ctMaskLT(i + j, macEnd);
21248+ unsigned char started = ctMaskGTE(i + j, macStart);
21249+ unsigned char notEnded = ctMaskLT(i + j, macEnd);
2124321250 mac[j] |= started & notEnded & data[i + j];
2124421251 }
2124521252 }
0 commit comments