From: "cron2 (Code Review)" Date: Mon, 19 Jan 2026 11:40:38 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., selva.nair@...277..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="pXQEqk3uLe8="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: cryptoapi: Avoid conversion warnings List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld , plaisthos , selvanair Cc: openvpn-devel --pXQEqk3uLe8= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has uploaded a new patch set (#2) to the change originally created by= flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1464?usp=3Demail ) The following approvals got outdated and were removed: Code-Review+1 by cron2, Code-Review+2 by selvanair Change subject: cryptoapi: Avoid conversion warnings ...................................................................... cryptoapi: Avoid conversion warnings Due to the differences in the types of APIs between xkey provider and Windows cryptoapi we can't avoid the casts. And they should be safe generally since the involved sizes should be small compared to the maximum values. So just add asserts and explicit cast to avoid the warnings. Change-Id: I789022af7c4977c4dff4f7671f491fe5836828fa Signed-off-by: Frank Lichtenheld Acked-by: Selva Nair Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1464 Message-Id: <20260116135729.40545-1-frank@...2641...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg35= 304.html Signed-off-by: Gert Doering --- M src/openvpn/cryptoapi.c 1 file changed, 11 insertions(+), 16 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/64/1464/2 diff --git a/src/openvpn/cryptoapi.c b/src/openvpn/cryptoapi.c index b18b9d4..49f5bbb 100644 --- a/src/openvpn/cryptoapi.c +++ b/src/openvpn/cryptoapi.c @@ -61,7 +61,7 @@ return 0; } -#else /* HAVE_XKEY_PROVIDER */ +#else /* HAVE_XKEY_PROVIDER */ static XKEY_EXTERNAL_SIGN_fn xkey_cng_sign; @@ -341,21 +341,18 @@ return rv; } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - /** Sign hash in tbs using EC key in cd and NCryptSignHash */ static int xkey_cng_ec_sign(CAPI_DATA *cd, unsigned char *sig, size_t *siglen, const = unsigned char *tbs, size_t tbslen) { - DWORD len =3D *siglen; + ASSERT(*siglen <=3D UINT_MAX); + ASSERT(tbslen <=3D UINT_MAX); + DWORD len =3D (DWORD)*siglen; msg(D_LOW, "Signing using NCryptSignHash with EC key"); - DWORD status =3D NCryptSignHash(cd->crypt_prov, NULL, (BYTE *)tbs, tbs= len, sig, len, &len, 0); + DWORD status =3D NCryptSignHash(cd->crypt_prov, NULL, (BYTE *)tbs, (DW= ORD)tbslen, sig, len, &len, 0); if (status !=3D ERROR_SUCCESS) { @@ -383,7 +380,9 @@ ASSERT(cd); ASSERT(sig); + ASSERT(*siglen <=3D UINT_MAX); ASSERT(tbs); + ASSERT(tbslen <=3D INT_MAX); DWORD status =3D ERROR_SUCCESS; DWORD len =3D 0; @@ -406,10 +405,10 @@ } else if (!strcmp(sigalg.padmode, "pss")) { - int saltlen =3D tbslen; /* digest size by default */ + int saltlen =3D (int)tbslen; /* digest size by default */ if (!strcmp(sigalg.saltlen, "max")) { - saltlen =3D xkey_max_saltlen(EVP_PKEY_bits(cd->pubkey), tbslen= ); + saltlen =3D xkey_max_saltlen(EVP_PKEY_bits(cd->pubkey), saltle= n); if (saltlen < 0) { msg(M_NONFATAL, "Error in cryptoapicert: invalid salt leng= th (%d)", saltlen); @@ -420,8 +419,8 @@ msg(D_LOW, "Signing using NCryptSignHash with PSS padding: hashalg= <%s>, saltlen <%d>", sigalg.mdname, saltlen); - BCRYPT_PSS_PADDING_INFO padinfo =3D { hashalg, - (DWORD)saltlen }; /* cast is s= afe as saltlen >=3D 0 */ + /* cast is safe as saltlen >=3D 0 */ + BCRYPT_PSS_PADDING_INFO padinfo =3D { hashalg, (DWORD)saltlen }; status =3D NCryptSignHash(cd->crypt_prov, &padinfo, (BYTE *)tbs, (= DWORD)tbslen, sig, (DWORD)*siglen, &len, BCRYPT_PAD_PSS); } @@ -442,10 +441,6 @@ return (*siglen > 0); } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic pop -#endif - /** Dispatch sign op to xkey_cng__sign */ static int xkey_cng_sign(void *handle, unsigned char *sig, size_t *siglen, const unsi= gned char *tbs, -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1464?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: newpatchset Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I789022af7c4977c4dff4f7671f491fe5836828fa Gerrit-Change-Number: 1464 Gerrit-PatchSet: 2 Gerrit-Owner: flichtenheld Gerrit-Reviewer: cron2 Gerrit-Reviewer: plaisthos Gerrit-Reviewer: selvanair Gerrit-CC: openvpn-devel --pXQEqk3uLe8= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 upl= oaded patch set #2 to the change originally created by flichtenhel= d.

View Change

The following approvals got outdated and were remove= d: Code-Review+1 by cron2, Code-Review+2 by selvanair

cryptoa=
pi: Avoid conversion warnings

Due to the differences in the types of= APIs
between xkey provider and Windows cryptoapi
we can't avoid = the casts. And they should be
safe generally since the involved sizes sh= ould
be small compared to the maximum values. So
just add asserts and= explicit cast to avoid
the warnings.

Change-Id: I789022af7c4977c= 4dff4f7671f491fe5836828fa
Signed-off-by: Frank Lichtenheld <frank@...493...= 2641...>
Acked-by: Selva Nair <selva.nair@...277...>
Gerrit = URL: https://gerrit.openvpn.net/c/openvpn/+/1464
Message-Id: <2026011= 6135729.40545-1-frank@...2641...>
URL: https://www.mail-archive.com/o= penvpn-devel@lists.sourceforge.net/msg35304.html
Signed-off-by: Gert Doe= ring <gert@...1296...>
---
M src/openvpn/cryptoapi.c
1 file = changed, 11 insertions(+), 16 deletions(-)

git p=
ull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/64/1464/2
d= iff --git a/src/openvpn/cryptoapi.c b/src/openvpn/cryptoapi.c
index b18b9d4..49f5bbb 100644
--- a/src/openvpn/cryptoap= i.c
+++ b/src/openvpn/cryptoapi.c
@@ -61,7 = +61,7 @@
return 0;
}
=
-#else /* HAVE_XKEY_P= ROVIDER */
+#else /*= HAVE_XKEY_PROVIDER */

static XKEY_EXTER= NAL_SIGN_fn xkey_cng_sign;

@@ -341,21 +34= 1,18 @@
return rv;
}
=
-#if defined(__GNUC__= ) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
<= span style=3D"color: hsl(0, 100%, 40%);">-#endif
-
/** Sign hash in tbs using EC = key in cd and NCryptSignHash */
static int
xkey_cng_ec_sign(CAPI_DATA *cd, unsigned char *sig, size_t *siglen, const= unsigned char *tbs,
size_t tbslen)

{
- DWOR= D len =3D *siglen;
+ = ASSERT(*siglen <=3D UINT_MAX);
+ ASSERT(tbslen <=3D UINT_MAX);
+ DWORD len =3D (DWORD)*siglen;<= br>
msg(D_LOW, "Signing using NCryptSignHa= sh with EC key");

- DWORD status =3D NCryptSignHash(cd->crypt_prov, N= ULL, (BYTE *)tbs, tbslen, sig, len, &len, 0);
+ DWORD status =3D NCryptSignHash(cd->cr= ypt_prov, NULL, (BYTE *)tbs, (DWORD)tbslen, sig, len, &len, 0);<= br>
if (status !=3D ERROR_SUCCESS)
{
@@ -383,7 +380,9 @@

= ASSERT(cd);
ASSERT(sig);
+ ASSERT(*siglen <=3D UINT_MAX);<= /span>
ASSERT(tbs);
+ ASSERT(tbslen <=3D INT_MAX);
<= br> DWORD status =3D ERROR_SUCCESS;
DWORD le= n =3D 0;
@@ -406,10 +405,10 @@
}
else if (!strcmp(sigalg.padmode, "pss")) {
- = int saltlen =3D tbslen; /* digest size by default */
+ int saltlen =3D (int)tbslen; /* d= igest size by default */
if (!strcmp(sigalg.saltle= n, "max"))
{
- saltlen =3D xkey_max_saltlen(EVP_PKEY= _bits(cd->pubkey), tbslen);
+ saltlen =3D xkey_max_saltlen(EVP_PKEY_bits(cd->pu= bkey), saltlen);
if (saltlen < 0) {
msg(M_NONFATAL, &quo= t;Error in cryptoapicert: invalid salt length (%d)", saltlen);<= br>@@ -420,8 +419,8 @@
msg(D_LOW, "Sign= ing using NCryptSignHash with PSS padding: hashalg <%s>, saltlen <= %d>",
sigalg.mdname, saltlen);<= br>
- BCR= YPT_PSS_PADDING_INFO padinfo =3D { hashalg,
- (DWORD)sa= ltlen }; /* cast is safe as saltlen >=3D 0 */
+ /* cast is safe as saltlen >=3D 0 *= /
+ BCRYPT_PSS= _PADDING_INFO padinfo =3D { hashalg, (DWORD)saltlen };
= status =3D NCryptSignHash(cd->crypt_prov, &padinfo, (BYTE *)tbs= , (DWORD)tbslen, sig,
(DWO= RD)*siglen, &len, BCRYPT_PAD_PSS);
}
@@ -442,10 +441,6 @@

return (*siglen > 0);
}

-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
/** Dispatch sign op to xkey_cng_&l= t;rsa/ec>_sign */
static int
xkey_cng_= sign(void *handle, unsigned char *sig, size_t *siglen, const unsigned char = *tbs,

To view, visit change 1464. To unsubs= cribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I789022af7c4977c4dff4f7671f4= 91fe5836828fa
Gerrit-Change-Number: 1464
Gerrit-PatchSet: 2
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-Reviewer: selvanair <selva.nair@...1665...= 77...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
= --pXQEqk3uLe8=--