From: "cron2 (Code Review)" Date: Tue, 2 Apr 2024 14:56:52 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <794d6bd3d5dc26a7a40c7153a87405581c2fee0a-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="nr89hpdx2WI="; charset=UTF-8 Subject: [Openvpn-devel] [XS] Change in openvpn[master]: Remove/combine redundant call of EVP_CipherInit before EVP_CipherInit_Ex List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos Cc: flichtenheld , openvpn-devel --nr89hpdx2WI= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/55= 2?usp=3Demail ) Change subject: Remove/combine redundant call of EVP_CipherInit before EVP_= CipherInit_Ex ...................................................................... Remove/combine redundant call of EVP_CipherInit before EVP_CipherInit_Ex EVP_CipherInit basically is the same EVP_CipherInit_ex except that it in some instances it resets/inits the ctx parameter first. We already call EVP_CIPHER_CTX_reset to reset/init the ctx before. Also ensure that EVP_CipherInit_Ex gets the cipher to actually be able to initialise the context. OpenSSL 1.0.2: https://github.com/openssl/openssl/blob/OpenSSL_1_0_2-stable/crypto/evp/evp= _enc.c#L94 EVP_CipherInit calls first EVP_CIPHER_CTX_init and then EVP_CipherInit_ex Our openssl_compat.h has for these older OpenSSL versions OpenSSL 3.0: https://github.com/openssl/openssl/blob/openssl-3.2/crypto/evp/evp_enc.c#L4= 50 basically the same as 1.0.2. Just that method names have been changed. Change-Id: I911e25949a8647b567fd4178683534d4404ab469 Signed-off-by: Arne Schwabe Acked-by: Gert Doering Message-Id: <20240402134909.6340-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg28= 523.html Signed-off-by: Gert Doering --- M src/openvpn/crypto_openssl.c 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/openvpn/crypto_openssl.c b/src/openvpn/crypto_openssl.c index bfc5e37..b2c4eb6 100644 --- a/src/openvpn/crypto_openssl.c +++ b/src/openvpn/crypto_openssl.c @@ -846,11 +846,7 @@ evp_cipher_type *kt =3D cipher_get(ciphername); EVP_CIPHER_CTX_reset(ctx); - if (!EVP_CipherInit(ctx, kt, NULL, NULL, enc)) - { - crypto_msg(M_FATAL, "EVP cipher init #1"); - } - if (!EVP_CipherInit_ex(ctx, NULL, NULL, key, NULL, enc)) + if (!EVP_CipherInit_ex(ctx, kt, NULL, key, NULL, enc)) { crypto_msg(M_FATAL, "EVP cipher init #2"); } -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/552?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I911e25949a8647b567fd4178683534d4404ab469 Gerrit-Change-Number: 552 Gerrit-PatchSet: 4 Gerrit-Owner: plaisthos Gerrit-Reviewer: cron2 Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel Gerrit-MessageType: merged --nr89hpdx2WI= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 submitted this change.

View Change

Remove/combine redundant call of EVP_CipherIni=
t before EVP_CipherInit_Ex

EVP_CipherInit basically is the same EVP_= CipherInit_ex except that it
in some instances it resets/inits the ctx p= arameter first. We already
call EVP_CIPHER_CTX_reset to reset/init the c= tx before. Also ensure that
EVP_CipherInit_Ex gets the cipher to actuall= y be able to initialise the
context.

OpenSSL 1.0.2:

https:= //github.com/openssl/openssl/blob/OpenSSL_1_0_2-stable/crypto/evp/evp_enc.c= #L94

EVP_CipherInit calls first EVP_CIPHER_CTX_init and then EVP_Cip= herInit_ex

Our openssl_compat.h has

for these older OpenSSL v= ersions

OpenSSL 3.0:

https://github.com/openssl/openssl/blob/= openssl-3.2/crypto/evp/evp_enc.c#L450

basically the same as 1.0.2. J= ust that method names have been changed.

Change-Id: I911e25949a8647b= 567fd4178683534d4404ab469
Signed-off-by: Arne Schwabe <arne@...2477...= .>
Acked-by: Gert Doering <gert@...1296...>
Message-Id: <= 20240402134909.6340-1-gert@...1296...>
URL: https://www.mail-archive.= com/openvpn-devel@lists.sourceforge.net/msg28523.html
Signed-off-by: Ger= t Doering <gert@...1296...>
---
M src/openvpn/crypto_openssl.c<= br>1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/src/openvpn/crypto_openssl.c b/src/openvpn/crypto_openssl.c=

index bfc5e37..b2c4eb6 100644
--- a/src/op= envpn/crypto_openssl.c
+++ b/src/openvpn/crypto_openssl.c
@@ -846,11 +846,7 @@
evp_cipher_type *k= t =3D cipher_get(ciphername);

EVP_CI= PHER_CTX_reset(ctx);
- = if (!EVP_CipherInit(ctx, kt, NULL, NULL, enc))
- {
- crypto_msg(M_FATAL, "EVP cipher init #1");
- }
- if (!EVP_CipherInit_ex(ctx, NULL, NU= LL, key, NULL, enc))
= + if (!EVP_CipherInit_ex(ctx, kt, NULL, key, NULL, enc))
{

crypto_msg(M_FATAL, "EVP cipher init = #2");
}

To vi= ew, visit change 552. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I911e25949a8647b567fd4178683= 534d4404ab469
Gerrit-Change-Number: 552
Gerrit-PatchSet: 4
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-MessageType: merged
--nr89hpdx2WI=--