Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -41491,6 +41491,7 @@ static int DefTicketEncCb(WOLFSSL* ssl, byte key_name[WOLFSSL_TICKET_NAME_SZ],
{
RsaKey* key = (RsaKey*)ssl->hsKey;
volatile int lenErrMask;
int mask;

ret = RsaDec(ssl,
input + args->idx,
Expand All @@ -41517,8 +41518,11 @@ static int DefTicketEncCb(WOLFSSL* ssl, byte key_name[WOLFSSL_TICKET_NAME_SZ],
goto exit_dcke;

lenErrMask = 0 - (SECRET_LEN != args->sigSz);
args->lastErr = (ret & (~lenErrMask)) |
(WC_NO_ERR_TRACE(RSA_PAD_E) & lenErrMask);
/* Snapshot volatile to avoid multiple volatile
* accesses per expression. */
mask = lenErrMask;
args->lastErr = (ret & (~mask)) |
(WC_NO_ERR_TRACE(RSA_PAD_E) & mask);
ret = 0;
break;
} /* rsa_kea */
Expand Down
18 changes: 13 additions & 5 deletions wolfcrypt/src/rsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -1890,6 +1890,8 @@ static int RsaUnPad(const byte *pkcsBlock, unsigned int pkcsBlockLen,
volatile byte invalid = 0;
volatile byte minPad;
volatile int invalidMask;
byte inv;
word16 sep;

i = 0;
/* Decrypted with private key - unpad must be constant time. */
Expand All @@ -1900,18 +1902,24 @@ static int RsaUnPad(const byte *pkcsBlock, unsigned int pkcsBlockLen,
pastSep |= ctMask16Eq(pkcsBlock[j], 0x00);
}

/* Snapshot volatiles to avoid multiple volatile accesses per
* expression. */
inv = invalid;
sep = pastSep;

/* Minimum of 11 bytes of pre-message data - including leading 0x00. */
minPad = ctMaskLT(i, RSA_MIN_PAD_SZ);
invalid |= minPad;
inv |= minPad;
/* Must have seen separator. */
invalid |= (byte)~pastSep;
inv |= (byte)~sep;
/* First byte must be 0x00. */
invalid |= ctMaskNotEq(pkcsBlock[0], 0x00);
inv |= ctMaskNotEq(pkcsBlock[0], 0x00);
/* Check against expected block type: padValue */
invalid |= ctMaskNotEq(pkcsBlock[1], padValue);
inv |= ctMaskNotEq(pkcsBlock[1], padValue);

invalid = inv;
*output = (byte *)(pkcsBlock + i);
invalidMask = (int)-1 + (int)(invalid >> 7);
invalidMask = (int)-1 + (int)(inv >> 7);
ret = invalidMask & ((int)pkcsBlockLen - i);
}
#endif
Expand Down
Loading