From: Tomas Mraz Date: Fri, 31 Mar 2023 13:46:15 +0000 (+0200) Subject: Avoid calling into provider with the same iv_len or key_len X-Git-Tag: openssl-3.2.0-alpha1~1035 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eb52450f5151e8e78743ab05de21a344823316f5;p=thirdparty%2Fopenssl.git Avoid calling into provider with the same iv_len or key_len Fixes #20625 Reviewed-by: Matt Caswell Reviewed-by: Dmitry Belyavskiy Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/20664) --- diff --git a/crypto/evp/evp_enc.c b/crypto/evp/evp_enc.c index b4d4441f6fc..3187ba35c99 100644 --- a/crypto/evp/evp_enc.c +++ b/crypto/evp/evp_enc.c @@ -1082,6 +1082,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; @@ -1107,6 +1112,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;