Skip to content

Commit

Permalink
Avoid calling into provider with the same iv_len or key_len
Browse files Browse the repository at this point in the history
Fixes #20625

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from #20664)

(cherry picked from commit eb52450)
  • Loading branch information
t8m authored and paulidale committed Apr 2, 2023
1 parent ce90b5e commit 6f80020
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions crypto/evp/evp_enc.c
Expand Up @@ -1078,6 +1078,11 @@ int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)

switch (type) {
case EVP_CTRL_SET_KEY_LENGTH:
if (arg < 0)
return 0;
if (ctx->key_len == arg)
/* Skip calling into provider if unchanged. */
return 1;
params[0] = OSSL_PARAM_construct_size_t(OSSL_CIPHER_PARAM_KEYLEN, &sz);
ctx->key_len = -1;
break;
Expand All @@ -1103,6 +1108,9 @@ int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
case EVP_CTRL_AEAD_SET_IVLEN:
if (arg < 0)
return 0;
if (ctx->iv_len == arg)
/* Skip calling into provider if unchanged. */
return 1;
params[0] = OSSL_PARAM_construct_size_t(OSSL_CIPHER_PARAM_IVLEN, &sz);
ctx->iv_len = -1;
break;
Expand Down

0 comments on commit 6f80020

Please sign in to comment.