]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
When changing IV length invalidate previously set IV
authorTomas Mraz <tomas@openssl.org>
Wed, 1 Nov 2023 13:00:22 +0000 (14:00 +0100)
committerTomas Mraz <tomas@openssl.org>
Thu, 23 Nov 2023 16:08:26 +0000 (17:08 +0100)
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(cherry picked from commit eddbb78f4e5196eee33b2fd3d6adeabb69d52eb7)

Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/22613)

providers/implementations/ciphers/cipher_aes_ocb.c
providers/implementations/ciphers/ciphercommon_ccm.c
providers/implementations/ciphers/ciphercommon_gcm.c

index ce377ad57409327533de1905f6e963647ffae9d7..eab315453ef1a3fdf6c390aa2824b501139faa2a 100644 (file)
@@ -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) {
index ce3f7527f31e4bd458fe8a47fd72f43f72738d96..33105911e36668518ea64250e3d04eb7df8f4717 100644 (file)
@@ -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);
index ed95c97ff473cbaecf9cfd9d15adc086faab63d7..4ec73d5a6dba056e5b8cffa408cf9c699d0f9885 100644 (file)
@@ -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);