@@ -1890,6 +1890,8 @@ static int RsaUnPad(const byte *pkcsBlock, unsigned int pkcsBlockLen,
18901890 volatile byte invalid = 0 ;
18911891 volatile byte minPad ;
18921892 volatile int invalidMask ;
1893+ byte inv ;
1894+ word16 sep ;
18931895
18941896 i = 0 ;
18951897 /* Decrypted with private key - unpad must be constant time. */
@@ -1900,18 +1902,24 @@ static int RsaUnPad(const byte *pkcsBlock, unsigned int pkcsBlockLen,
19001902 pastSep |= ctMask16Eq (pkcsBlock [j ], 0x00 );
19011903 }
19021904
1905+ /* Snapshot volatiles to avoid multiple volatile accesses per
1906+ * expression. */
1907+ inv = invalid ;
1908+ sep = pastSep ;
1909+
19031910 /* Minimum of 11 bytes of pre-message data - including leading 0x00. */
19041911 minPad = ctMaskLT (i , RSA_MIN_PAD_SZ );
1905- invalid |= minPad ;
1912+ inv |= minPad ;
19061913 /* Must have seen separator. */
1907- invalid |= (byte )~pastSep ;
1914+ inv |= (byte )~sep ;
19081915 /* First byte must be 0x00. */
1909- invalid |= ctMaskNotEq (pkcsBlock [0 ], 0x00 );
1916+ inv |= ctMaskNotEq (pkcsBlock [0 ], 0x00 );
19101917 /* Check against expected block type: padValue */
1911- invalid |= ctMaskNotEq (pkcsBlock [1 ], padValue );
1918+ inv |= ctMaskNotEq (pkcsBlock [1 ], padValue );
19121919
1920+ invalid = inv ;
19131921 * output = (byte * )(pkcsBlock + i );
1914- invalidMask = (int )-1 + (int )(invalid >> 7 );
1922+ invalidMask = (int )-1 + (int )(inv >> 7 );
19151923 ret = invalidMask & ((int )pkcsBlockLen - i );
19161924 }
19171925#endif
0 commit comments