diff options
author | Tomas Mraz <tomas@openssl.org> | 2023-03-31 15:46:15 +0200 |
---|---|---|
committer | Pauli <pauli@openssl.org> | 2023-04-03 00:22:28 +0200 |
commit | eb52450f5151e8e78743ab05de21a344823316f5 (patch) | |
tree | adcc6528c3bd5754275bca0ee171c3030eb41557 /crypto/evp/evp_enc.c | |
parent | Fix compilation error when using clang-cl 16 or higher (diff) | |
download | openssl-eb52450f5151e8e78743ab05de21a344823316f5.tar.xz openssl-eb52450f5151e8e78743ab05de21a344823316f5.zip |
Avoid calling into provider with the same iv_len or key_len
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 https://github.com/openssl/openssl/pull/20664)
Diffstat (limited to 'crypto/evp/evp_enc.c')
-rw-r--r-- | crypto/evp/evp_enc.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/crypto/evp/evp_enc.c b/crypto/evp/evp_enc.c index b4d4441f6f..3187ba35c9 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; |