Skip to content
Open
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
29 changes: 27 additions & 2 deletions src/wp_aes_aead.c
Original file line number Diff line number Diff line change
Expand Up @@ -1326,6 +1326,12 @@ static int wp_aesgcm_stream_update(wp_AeadCtx *ctx, unsigned char *out,
ok = 0;
}

/* Reject encryption and decryption when no IV has been supplied by the
* caller. */
if (!done && ok && (ctx->ivState == IV_STATE_UNINITIALISED)) {
ok = 0;
}
Comment thread
gasbytes marked this conversation as resolved.

if ((!done) && ok) {
if (ctx->ivState == IV_STATE_BUFFERED) {
rc = wc_AesGcmInit(&ctx->aes, NULL, 0, ctx->iv, (word32)ctx->ivLen);
Expand Down Expand Up @@ -1408,6 +1414,13 @@ static int wp_aesgcm_stream_final(wp_AeadCtx *ctx, unsigned char *out,
ok = 0;
}

/*
* Reject encryption and decryption when no IV has been supplied.
*/
if ((!done) && ok && (ctx->ivState == IV_STATE_UNINITIALISED)) {
ok = 0;
}

if ((!done) && ok) {
if (outSize == 0) {
outSize = (ctx->tagLen != UNINITIALISED_SIZET) ? ctx->tagLen :
Expand Down Expand Up @@ -1472,6 +1485,10 @@ static int wp_aesgcm_encdec(wp_AeadCtx *ctx, unsigned char *out, size_t* outLen,
ok = 0;
}
}
/* Reject encryption and decryption when no IV has been supplied by the caller. */
if (ok && ctx->ivState == IV_STATE_UNINITIALISED) {
ok = 0;
}
/* Once loaded, always use original IV */
iv = ctx->iv;
if (ctx->ivState == IV_STATE_COPIED) {
Expand Down Expand Up @@ -1986,7 +2003,15 @@ static int wp_aesccm_encdec(wp_AeadCtx *ctx, unsigned char *out,
ctx->tagLen = EVP_CCM_TLS_TAG_LEN;
}

if (ctx->enc) {
/*
* Reject encryption and decryption when no IV/nonce has been supplied by
* the caller.
*/
if (ctx->ivState == IV_STATE_UNINITIALISED) {
ok = 0;
}

if (ok && ctx->enc) {
if (!ctx->ivSet) {
rc = wc_AesCcmSetNonce(&ctx->aes, ctx->iv, (word32)ctx->ivLen);
if (rc != 0) {
Expand All @@ -2006,7 +2031,7 @@ static int wp_aesccm_encdec(wp_AeadCtx *ctx, unsigned char *out,
}
}
}
else {
else if (ok) {
rc = wc_AesCcmDecrypt(&ctx->aes, out, in, (word32)inLen,
ctx->iv, (word32)ctx->ivLen, ctx->buf, (word32)ctx->tagLen,
ctx->aad, (word32)ctx->aadLen);
Expand Down
Loading
Loading