Skip to content

Commit

Permalink
When changing IV length invalidate previously set IV
Browse files Browse the repository at this point in the history
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>

(cherry picked from commit eddbb78)

Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from #22613)
  • Loading branch information
t8m committed Nov 23, 2023
1 parent 761cb2f commit 38595b9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
5 changes: 4 additions & 1 deletion providers/implementations/ciphers/cipher_aes_ocb.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,10 @@ static int aes_ocb_set_ctx_params(void *vctx, const OSSL_PARAM params[])
/* IV len must be 1 to 15 */
if (sz < OCB_MIN_IV_LEN || sz > OCB_MAX_IV_LEN)
return 0;
ctx->base.ivlen = sz;
if (ctx->base.ivlen != sz) {
ctx->base.ivlen = sz;
ctx->iv_state = IV_STATE_UNINITIALISED;
}
}
p = OSSL_PARAM_locate_const(params, OSSL_CIPHER_PARAM_KEYLEN);
if (p != NULL) {
Expand Down
5 changes: 4 additions & 1 deletion providers/implementations/ciphers/ciphercommon_ccm.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ int ossl_ccm_set_ctx_params(void *vctx, const OSSL_PARAM params[])
ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_IV_LENGTH);
return 0;
}
ctx->l = ivlen;
if (ctx->l != ivlen) {
ctx->l = ivlen;
ctx->iv_set = 0;
}
}

p = OSSL_PARAM_locate_const(params, OSSL_CIPHER_PARAM_AEAD_TLS1_AAD);
Expand Down
7 changes: 6 additions & 1 deletion providers/implementations/ciphers/ciphercommon_gcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,12 @@ int ossl_gcm_set_ctx_params(void *vctx, const OSSL_PARAM params[])
ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_IV_LENGTH);
return 0;
}
ctx->ivlen = sz;
if (ctx->ivlen != sz) {
/* If the iv was already set or autogenerated, it is invalid. */
if (ctx->iv_state != IV_STATE_UNINITIALISED)
ctx->iv_state = IV_STATE_FINISHED;
ctx->ivlen = sz;
}
}

p = OSSL_PARAM_locate_const(params, OSSL_CIPHER_PARAM_AEAD_TLS1_AAD);
Expand Down

0 comments on commit 38595b9

Please sign in to comment.