From: "cron2 (Code Review)" Date: Sun, 31 Mar 2024 14:17:54 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641..., a@...2181... Message-ID: <93c122aa60b1ea3466a078589bb14b03f39151a4-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="IMsFSyLNDQk="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: crypto_backend: fix type of enc parameter List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld Cc: plaisthos , openvpn-devel --IMsFSyLNDQk= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/54= 8?usp=3Demail ) Change subject: crypto_backend: fix type of enc parameter ...................................................................... crypto_backend: fix type of enc parameter We had parts of a abstraction, but it wasn't consistent. GCC 13 now complains about the type mismatch with mbedtls now: crypto_mbedtls.c:568:1: error: conflicting types for =E2=80=98cipher_ctx_init=E2=80=99 due to enum/integer= mismatch; have =E2=80=98void(mbedtls_cipher_context_t *, const uint8_t *, const char = *, const mbedtls_operation_t)=E2=80=99 [...] [-Werror=3Denum-int-mismatch] crypto_backend.h:341:6: note: previous declaration of =E2=80=98cipher_ctx_init=E2=80=99 with type =E2=80=98void(cipher_ctx_t *, const uint8_t *, const char *, int)=E2=80=99 = [...] Previous compiler versions did not complain. v2: - clean solution instead of quick solution. Fix the actual API definition Change-Id: If0dcdde30879fd6185efb2ad31399c1629c04d22 Signed-off-by: Frank Lichtenheld Acked-by: Arne Schwabe Message-Id: <20240327162621.1792414-1-frank@...2641...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg28= 498.html Signed-off-by: Gert Doering --- M src/openvpn/crypto_backend.h M src/openvpn/crypto_mbedtls.c M src/openvpn/crypto_mbedtls.h M src/openvpn/crypto_openssl.c M src/openvpn/crypto_openssl.h 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/openvpn/crypto_backend.h b/src/openvpn/crypto_backend.h index 8d37e64..c454c64 100644 --- a/src/openvpn/crypto_backend.h +++ b/src/openvpn/crypto_backend.h @@ -336,10 +336,10 @@ * @param key Buffer containing the key to use * @param ciphername Ciphername of the cipher to use * @param enc Whether to encrypt or decrypt (either - * \c MBEDTLS_OP_ENCRYPT or \c MBEDTLS_OP_DECRYPT). + * \c OPENVPN_OP_ENCRYPT or \c OPENVPN_OP_DECRYPT). */ void cipher_ctx_init(cipher_ctx_t *ctx, const uint8_t *key, - const char *cipername, int enc); + const char *cipername, crypto_operation_t enc); /** * Returns the size of the IV used by the cipher, in bytes, or 0 if no IV = is diff --git a/src/openvpn/crypto_mbedtls.c b/src/openvpn/crypto_mbedtls.c index 1a39752..c230292 100644 --- a/src/openvpn/crypto_mbedtls.c +++ b/src/openvpn/crypto_mbedtls.c @@ -566,7 +566,7 @@ void cipher_ctx_init(mbedtls_cipher_context_t *ctx, const uint8_t *key, - const char *ciphername, const mbedtls_operation_t operatio= n) + const char *ciphername, crypto_operation_t enc) { ASSERT(NULL !=3D ciphername && NULL !=3D ctx); CLEAR(*ctx); @@ -580,7 +580,7 @@ msg(M_FATAL, "mbed TLS cipher context init #1"); } - if (!mbed_ok(mbedtls_cipher_setkey(ctx, key, (int)key_bitlen, operatio= n))) + if (!mbed_ok(mbedtls_cipher_setkey(ctx, key, (int)key_bitlen, enc))) { msg(M_FATAL, "mbed TLS cipher set key"); } diff --git a/src/openvpn/crypto_mbedtls.h b/src/openvpn/crypto_mbedtls.h index 46f76e2..48d1e20 100644 --- a/src/openvpn/crypto_mbedtls.h +++ b/src/openvpn/crypto_mbedtls.h @@ -63,6 +63,8 @@ /** Cipher is in GCM mode */ #define OPENVPN_MODE_GCM MBEDTLS_MODE_GCM +typedef mbedtls_operation_t crypto_operation_t; + /** Cipher should encrypt */ #define OPENVPN_OP_ENCRYPT MBEDTLS_ENCRYPT diff --git a/src/openvpn/crypto_openssl.c b/src/openvpn/crypto_openssl.c index 50683b6..bfc5e37 100644 --- a/src/openvpn/crypto_openssl.c +++ b/src/openvpn/crypto_openssl.c @@ -840,7 +840,7 @@ void cipher_ctx_init(EVP_CIPHER_CTX *ctx, const uint8_t *key, - const char *ciphername, int enc) + const char *ciphername, crypto_operation_t enc) { ASSERT(NULL !=3D ciphername && NULL !=3D ctx); evp_cipher_type *kt =3D cipher_get(ciphername); diff --git a/src/openvpn/crypto_openssl.h b/src/openvpn/crypto_openssl.h index c0e95b4..4cd988a 100644 --- a/src/openvpn/crypto_openssl.h +++ b/src/openvpn/crypto_openssl.h @@ -85,6 +85,8 @@ /** Cipher is in GCM mode */ #define OPENVPN_MODE_GCM EVP_CIPH_GCM_MODE +typedef int crypto_operation_t; + /** Cipher should encrypt */ #define OPENVPN_OP_ENCRYPT 1 -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/548?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: If0dcdde30879fd6185efb2ad31399c1629c04d22 Gerrit-Change-Number: 548 Gerrit-PatchSet: 4 Gerrit-Owner: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-CC: ordex Gerrit-MessageType: merged --IMsFSyLNDQk= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 submitted this change.

View Change

crypto_backend: fix type of enc parameter
<= br>We had parts of a abstraction, but it wasn't consistent.
GCC 13 n= ow complains about the type mismatch with mbedtls now:

crypto_mbedtl= s.c:568:1: error:
conflicting types for =E2=80=98cipher_ctx_init=E2=80= =99 due to enum/integer mismatch;
have =E2=80=98void(mbedtls_cipher_cont= ext_t *, const uint8_t *, const char *, const mbedtls_operation_t)=E2=80=99=
[...] [-Werror=3Denum-int-mismatch]
crypto_backend.h:341:6: note:previous declaration of =E2=80=98cipher_ctx_init=E2=80=99 with type
=E2= =80=98void(cipher_ctx_t *, const uint8_t *, const char *, int)=E2=80=99 [..= .]

Previous compiler versions did not complain.

v2:
- cle= an solution instead of quick solution. Fix the actual API
definition<= br>
Change-Id: If0dcdde30879fd6185efb2ad31399c1629c04d22
Signed-off-b= y: Frank Lichtenheld <frank@...2641...>
Acked-by: Arne Schwabe <= ;arne-openvpn@...1227...>
Message-Id: <20240327162621.1792414-1-fr= ank@...2641...>
URL: https://www.mail-archive.com/openvpn-devel@...1697...= .sourceforge.net/msg28498.html
Signed-off-by: Gert Doering <gert@...1386...= 296...>
---
M src/openvpn/crypto_backend.h
M src/openvpn/crypto= _mbedtls.c
M src/openvpn/crypto_mbedtls.h
M src/openvpn/crypto_openss= l.c
M src/openvpn/crypto_openssl.h
5 files changed, 9 insertions(+), = 5 deletions(-)

diff --git a/src/openvpn/crypto_backend.h b/src/openvpn/crypto_backend.h=

index 8d37e64..c454c64 100644
--- a/src/op= envpn/crypto_backend.h
+++ b/src/openvpn/crypto_backend.h
@@ -336,10 +336,10 @@
* @param key = Buffer containing the key to use
* @param ciphername = Ciphername of the cipher to use
* @param enc = Whether to encrypt or decrypt (either
- * \c MBEDTLS_OP_ENCRYPT or \c MBEDTLS= _OP_DECRYPT).
+ * = \c OPENVPN_OP_ENCRYPT or \c OPENVPN_OP_DECRYPT). */
void cipher_ctx_init(cipher_ctx_t *ctx, const= uint8_t *key,
- = const char *cipername, int enc);
+ const char *cipername, cryp= to_operation_t enc);

/**
* Returns the size of the IV used by the cipher, in bytes, or 0 if no IV= is

diff --git a/src/openvpn/crypto_mbedtls.c b/src/openvpn= /crypto_mbedtls.c
index 1a39752..c230292 100644
<= span>--- a/src/openvpn/crypto_mbedtls.c
+++ b/src/openvpn/c= rypto_mbedtls.c
@@ -566,7 +566,7 @@

void
cipher_ctx_init(mbedtls_cipher_context_t = *ctx, const uint8_t *key,
- const char *ciphername, const mbedtls_operation_t opera= tion)
+ = const char *ciphername, crypto_operation_t enc)
{=
ASSERT(NULL !=3D ciphername && NULL !=3D ctx);
CLEAR(*ctx);
@@ -580,7 +580,7 @@
= msg(M_FATAL, "mbed TLS cipher context init #1");
}

- if (!mbed_ok(mbedtls_cipher_setkey(ctx, key, (int)key= _bitlen, operation)))
+ if (!mbed_ok(mbedtls_cipher_setkey(ctx, key, (int)key_bitlen, enc)))<= /span>
{
msg(M_FATAL, "mbed TLS= cipher set key");
}
diff --git a= /src/openvpn/crypto_mbedtls.h b/src/openvpn/crypto_mbedtls.h
index 46f76e2..48d1e20 100644

--- a/src/openvpn/crypto_mb= edtls.h
+++ b/src/openvpn/crypto_mbedtls.h
= @@ -63,6 +63,8 @@
/** Cipher is in GCM mode */
<= span> #define OPENVPN_MODE_GCM MBEDTLS_MODE_GCM


+typedef mbedtls_operat= ion_t crypto_operation_t;
+
/** Cipher should encrypt */
#defi= ne OPENVPN_OP_ENCRYPT MBEDTLS_ENCRYPT

diff --git a/src/openvpn/crypto_openssl.c b/src/openvpn/crypto_openssl.c<= /span>
index 50683b6..bfc5e37 100644
--- a/src/ope= nvpn/crypto_openssl.c
+++ b/src/openvpn/crypto_openssl.c
@@ -840,7 +840,7 @@

void
cipher_ctx_init(EVP_CIPHER_CTX *ctx, const uint8_t *key,
- const ch= ar *ciphername, int enc)
+ const char *ciphername, crypto_operation_t enc)=
{
ASSERT(NULL !=3D ciphername && NU= LL !=3D ctx);
evp_cipher_type *kt =3D cipher_get(ciphe= rname);
diff --git a/src/openvpn/crypto_openssl.h b/src/ope= nvpn/crypto_openssl.h
index c0e95b4..4cd988a 100644<= br>--- a/src/openvpn/crypto_openssl.h
+++ b/src/openv= pn/crypto_openssl.h
@@ -85,6 +85,8 @@
/** = Cipher is in GCM mode */
#define OPENVPN_MODE_GCM E= VP_CIPH_GCM_MODE

+typedef int crypto_operation_t;
+
/** Cipher should encrypt */
#define OPENVPN_OP_ENCRYPT 1
<= br>

To view, visit change 548. To unsubscribe, or for h= elp writing mail filters, visit settings.

<= /div>
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: If0dcdde30879fd6185efb2ad313= 99c1629c04d22
Gerrit-Change-Number: 548
Gerrit-PatchSet: 4
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-CC: ordex <a@...2181...>
Gerrit-MessageType: merged
--IMsFSyLNDQk=--