Do IV reset also for DES and 3DES implementations
authorTomas Mraz <tomas@openssl.org>
Thu, 15 Apr 2021 07:55:04 +0000 (09:55 +0200)
committerTomas Mraz <tomas@openssl.org>
Mon, 19 Apr 2021 08:01:08 +0000 (10:01 +0200)
Fixes #14704

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/14882)

providers/implementations/ciphers/cipher_des.c
providers/implementations/ciphers/cipher_tdes_common.c

index 9010ce90992d77e844a6da758b19d797dff1e11a..4563ea2edb0418a72efe86cbe8a048eb9be3546f 100644 (file)
@@ -86,6 +86,9 @@ static int des_init(void *vctx, const unsigned char *key, size_t keylen,
     if (iv != NULL) {
         if (!ossl_cipher_generic_initiv(ctx, iv, ivlen))
             return 0;
+    } else if (ctx->iv_set) {
+        /* reset IV to keep compatibility with 1.1.1 */
+        memcpy(ctx->iv, ctx->oiv, ctx->ivlen);
     }
 
     if (key != NULL) {
index 048b08661d532d9a0e64e1e48caa3aa379a00022..88acc16049b74b7ca9fda95a1a5514353e7dc536 100644 (file)
@@ -77,6 +77,12 @@ static int tdes_init(void *vctx, const unsigned char *key, size_t keylen,
     if (iv != NULL) {
         if (!ossl_cipher_generic_initiv(ctx, iv, ivlen))
             return 0;
+    } else if (ctx->iv_set
+               && (ctx->mode == EVP_CIPH_CBC_MODE
+                   || ctx->mode == EVP_CIPH_CFB_MODE
+                   || ctx->mode == EVP_CIPH_OFB_MODE)) {
+        /* reset IV to keep compatibility with 1.1.1 */
+        memcpy(ctx->iv, ctx->oiv, ctx->ivlen);
     }
 
     if (key != NULL) {