Skip to content
Merged
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
24 changes: 9 additions & 15 deletions wolfcrypt/src/pkcs7.c
Original file line number Diff line number Diff line change
Expand Up @@ -9520,6 +9520,7 @@ static int wc_PKCS7_PwriKek_KeyUnWrap(wc_PKCS7* pkcs7, const byte* kek,
byte* tmpIv = NULL;
byte* lastBlock = NULL;
byte* outTmp = NULL;
byte fail = 0;

if (pkcs7 == NULL || kek == NULL || in == NULL ||
out == NULL || iv == NULL) {
Expand Down Expand Up @@ -9581,25 +9582,18 @@ static int wc_PKCS7_PwriKek_KeyUnWrap(wc_PKCS7* pkcs7, const byte* kek,
cekLen = outTmp[0];

/* verify length */
Comment thread
julek-wolfssl marked this conversation as resolved.
if ((word32)cekLen > inSz) {
ForceZero(outTmp, inSz);
XFREE(outTmp, pkcs7->heap, DYNAMIC_TYPE_TMP_BUFFER);
return BAD_FUNC_ARG;
}

fail |= ctMaskGT(cekLen, (int)inSz);
Comment thread
julek-wolfssl marked this conversation as resolved.
/* verify check bytes */
if ((outTmp[1] ^ outTmp[4]) != 0xFF ||
(outTmp[2] ^ outTmp[5]) != 0xFF ||
(outTmp[3] ^ outTmp[6]) != 0xFF) {
ForceZero(outTmp, inSz);
XFREE(outTmp, pkcs7->heap, DYNAMIC_TYPE_TMP_BUFFER);
return BAD_FUNC_ARG;
}
fail |= ctMaskNotEq((int)(outTmp[1] ^ outTmp[4]), 0xFF);
fail |= ctMaskNotEq((int)(outTmp[2] ^ outTmp[5]), 0xFF);
fail |= ctMaskNotEq((int)(outTmp[3] ^ outTmp[6]), 0xFF);
/* verify length */
Comment thread
julek-wolfssl marked this conversation as resolved.
fail |= ctMaskGT(cekLen, (int)outSz);
Comment thread
julek-wolfssl marked this conversation as resolved.

if (outSz < (word32)cekLen) {
if (fail) {
ForceZero(outTmp, inSz);
XFREE(outTmp, pkcs7->heap, DYNAMIC_TYPE_TMP_BUFFER);
return BUFFER_E;
return BAD_FUNC_ARG;
}
Comment thread
julek-wolfssl marked this conversation as resolved.

XMEMCPY(out, outTmp + 4, outTmp[0]);
Expand Down
Loading