@@ -21209,13 +21209,11 @@ static byte MaskMac(const byte* data, int sz, int macSz, byte* expMac)
2120921209 int i, j;
2121021210 int r = 0;
2121121211 unsigned char mac[WC_MAX_DIGEST_SIZE];
21212- volatile int scanStart = sz - 1 - TLS_MAX_PAD_SZ - macSz;
21212+ int scanStart = sz - 1 - TLS_MAX_PAD_SZ - macSz;
2121321213 volatile int macEnd = sz - 1 - data[sz - 1];
21214- volatile int macStart = macEnd - macSz;
21214+ int macStart = macEnd - macSz;
2121521215 volatile int maskScanStart;
2121621216 volatile int maskMacStart;
21217- volatile unsigned char started;
21218- volatile unsigned char notEnded;
2121921217 unsigned char good = 0;
2122021218
2122121219 maskScanStart = ctMaskIntGTE(scanStart, 0);
@@ -21225,22 +21223,31 @@ static byte MaskMac(const byte* data, int sz, int macSz, byte* expMac)
2122521223
2122621224 /* Div on Intel has different speeds depending on value.
2122721225 * Use a bitwise AND or mod a specific value (converted to mul). */
21228- if ((macSz & (macSz - 1)) == 0)
21229- r = (macSz - (scanStart - macStart)) & (macSz - 1);
21226+ if ((macSz & (macSz - 1)) == 0) {
21227+ r = macSz - scanStart;
21228+ r += macStart;
21229+ r &= (macSz - 1);
21230+ }
2123021231#ifndef NO_SHA
21231- else if (macSz == WC_SHA_DIGEST_SIZE)
21232- r = (macSz - (scanStart - macStart)) % WC_SHA_DIGEST_SIZE;
21232+ else if (macSz == WC_SHA_DIGEST_SIZE) {
21233+ r = macSz - scanStart;
21234+ r += macStart;
21235+ r %= WC_SHA_DIGEST_SIZE;
21236+ }
2123321237#endif
2123421238#ifdef WOLFSSL_SHA384
21235- else if (macSz == WC_SHA384_DIGEST_SIZE)
21236- r = (macSz - (scanStart - macStart)) % WC_SHA384_DIGEST_SIZE;
21239+ else if (macSz == WC_SHA384_DIGEST_SIZE) {
21240+ r = macSz - scanStart;
21241+ r += macStart;
21242+ r %= WC_SHA384_DIGEST_SIZE;
21243+ }
2123721244#endif
2123821245
2123921246 XMEMSET(mac, 0, (size_t)(macSz));
2124021247 for (i = scanStart; i < sz; i += macSz) {
2124121248 for (j = 0; j < macSz && j + i < sz; j++) {
21242- started = ctMaskGTE(i + j, macStart);
21243- notEnded = ctMaskLT(i + j, macEnd);
21249+ unsigned char started = ctMaskGTE(i + j, macStart);
21250+ unsigned char notEnded = ctMaskLT(i + j, macEnd);
2124421251 mac[j] |= started & notEnded & data[i + j];
2124521252 }
2124621253 }
0 commit comments