summaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2022-08-03 09:27:27 +0100
committerMatt Caswell <matt@openssl.org>2022-08-03 09:27:27 +0100
commitb0501275ef56950bd77950dac1382357d91f8e7f (patch)
treebddeb9970cd6d91a07bb6cc51ac3b8047d868609 /crypto
parent20394c34ef2e058a1dc7e9cf7db2546338b11eb1 (diff)
Revert "Fix bug in EVP_CIPHER_CTX_get_iv_length()"
This reverts commit f428e2112c6c795db76d804e0fcb36aac40f1477. Reviewed-by: Hugo Landau <hlandau@openssl.org> Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com> (Merged from https://github.com/openssl/openssl/pull/18946)
Diffstat (limited to 'crypto')
-rw-r--r--crypto/evp/evp_lib.c45
1 files changed, 15 insertions, 30 deletions
diff --git a/crypto/evp/evp_lib.c b/crypto/evp/evp_lib.c
index 708583fea3..d5ae5ca4ad 100644
--- a/crypto/evp/evp_lib.c
+++ b/crypto/evp/evp_lib.c
@@ -504,36 +504,21 @@ int EVP_CIPHER_get_iv_length(const EVP_CIPHER *cipher)
int EVP_CIPHER_CTX_get_iv_length(const EVP_CIPHER_CTX *ctx)
{
- if (ctx->iv_len < 0) {
- int rv, len = EVP_CIPHER_get_iv_length(ctx->cipher);
- size_t v = len;
- OSSL_PARAM params[2] = { OSSL_PARAM_END, OSSL_PARAM_END };
-
- if (ctx->cipher->get_ctx_params != NULL) {
- params[0] = OSSL_PARAM_construct_size_t(OSSL_CIPHER_PARAM_IVLEN,
- &v);
- rv = evp_do_ciph_ctx_getparams(ctx->cipher, ctx->algctx, params);
- if (rv > 0) {
- if (OSSL_PARAM_modified(params)
- && !OSSL_PARAM_get_int(params, &len))
- return -1;
- } else if (rv != EVP_CTRL_RET_UNSUPPORTED) {
- return -1;
- }
- }
- /* Code below to be removed when legacy support is dropped. */
- else if ((EVP_CIPHER_get_flags(ctx->cipher)
- & EVP_CIPH_CUSTOM_IV_LENGTH) != 0) {
- rv = EVP_CIPHER_CTX_ctrl((EVP_CIPHER_CTX *)ctx, EVP_CTRL_GET_IVLEN,
- 0, &len);
- if (rv <= 0)
- return -1;
- }
- /*-
- * Casting away the const is annoying but required here. We need to
- * cache the result for performance reasons.
- */
- ((EVP_CIPHER_CTX *)ctx)->iv_len = len;
+ int rv, len = EVP_CIPHER_get_iv_length(ctx->cipher);
+ size_t v = len;
+ OSSL_PARAM params[2] = { OSSL_PARAM_END, OSSL_PARAM_END };
+
+ params[0] = OSSL_PARAM_construct_size_t(OSSL_CIPHER_PARAM_IVLEN, &v);
+ rv = evp_do_ciph_ctx_getparams(ctx->cipher, ctx->algctx, params);
+ if (rv == EVP_CTRL_RET_UNSUPPORTED)
+ goto legacy;
+ return rv != 0 ? (int)v : -1;
+ /* Code below to be removed when legacy support is dropped. */
+legacy:
+ if ((EVP_CIPHER_get_flags(ctx->cipher) & EVP_CIPH_CUSTOM_IV_LENGTH) != 0) {
+ rv = EVP_CIPHER_CTX_ctrl((EVP_CIPHER_CTX *)ctx, EVP_CTRL_GET_IVLEN,
+ 0, &len);
+ return (rv == 1) ? len : -1;
}
return len;
}