From: "flichtenheld (Code Review)"
Date: Mon, 12 Jan 2026 13:26:59 +0000
References:
Reply-To: frank@...2641..., arne-openvpn@...1227...,
openvpn-devel@lists.sourceforge.net
Message-ID: <2de5e4f72213ed67b9a327c6197036822288ad89-HTML@...2715...>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Disposition: inline
Content-Type: multipart/alternative; boundary="K2IDI7yazno="; 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: plaisthos
Cc: openvpn-devel
--K2IDI7yazno=
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Attention is currently required from: plaisthos.
Hello plaisthos,
I'd like you to do a code review.
Please visit
http://gerrit.openvpn.net/c/openvpn/+/1464?usp=3Demail
to review the following change.
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
---
M src/openvpn/cryptoapi.c
1 file changed, 11 insertions(+), 16 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/64/1464/1
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: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I789022af7c4977c4dff4f7671f491fe5836828fa
Gerrit-Change-Number: 1464
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld
Gerrit-Reviewer: plaisthos
Gerrit-CC: openvpn-devel
Gerrit-Attention: plaisthos
--K2IDI7yazno=
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Attention is cur=
rently required from: plaisthos.
flichtenheld would like plaisthos to review this change.
V=
iew Change
cryptoapi: Avoid conversion warnings Due to the differences in the types of APIs between xkey provider and W=
indows cryptoapi we can't avoid the casts. And they should be saf=
e generally since the involved sizes should be small compared to the max=
imum values. So just add asserts and explicit cast to avoid the warni=
ngs. Change-Id: I789022af7c4977c4dff4f7671f491fe5836828fa Signed-=
off-by: Frank Lichtenheld <frank@...2641...> --- M src/openvpn/=
cryptoapi.c 1 file changed, 11 insertions(+), 16 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/chang=
es/64/1464/1 diff --git a/src/openvpn/cryptoapi.c b/src/openvpn/cry=
ptoapi.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 "-Wconv=
ersion" -#endif - /** Si=
gn hash in tbs using EC key in cd and NCryptSignHash */ st=
atic int xkey_cng_ec_sign(CAPI_DATA *cd, unsigned char *si=
g, 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, "Si=
gning using NCryptSignHash with EC key"); =
- DWORD status =3D NCryptSignH=
ash(cd->crypt_prov, NULL, (BYTE *)tbs, tbslen, sig, len, &len, 0);=
span>+ DWORD status =3D =
NCryptSignHash(cd->crypt_prov, NULL, (BYTE *)tbs, (DWORD)tbslen, sig, le=
n, &len, 0); if (status !=3D ERR=
OR_SUCCESS) { @@ -383,7 +380,9 @@ ASSERT(cd); ASSERT(=
sig); + ASSERT(*si=
glen <=3D UINT_MAX); ASSERT(tbs); + ASSERT(tbslen <=3D INT_MAX);=
span> DWORD status =3D ERROR_SUCCESS; DWORD len =3D 0; @@ -406,10 +405,10 @@ } else if (!strcmp(sigalg.padmode, &q=
uot;pss")) { - int saltlen =3D tbslen; /* digest size by default =
*/ + int saltl=
en =3D (int)tbslen; /* digest size by default */ i=
f (!strcmp(sigalg.saltlen, "max")) {- saltlen =3D x=
key_max_saltlen(EVP_PKEY_bits(cd->pubkey), tbslen); + saltlen =3D xkey_max_saltlen=
(EVP_PKEY_bits(cd->pubkey), saltlen); if (s=
altlen < 0) { =
msg(M_NONFATAL, "Error in cryptoapicert: invalid salt length (%d)&=
quot;, saltlen); @@ -420,8 +419,8 @@ =
msg(D_LOW, "Signing using NCryptSignHash with PSS padding: hashalg =
<%s>, saltlen <%d>", sigalg.m=
dname, saltlen); - BCRYPT_PSS_PADDING_INFO padinfo =3D { hashalg, <=
br>- =
(DWORD)saltlen }; /* cast is safe as saltlen >=3D 0 */+ /* cast is saf=
e as saltlen >=3D 0 */ + BCRYPT_PSS_PADDING_INFO padinfo =3D { hashalg, (DWORD)saltlen=
}; status =3D NCryptSignHash(cd->crypt_prov, &=
amp;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 diagnos=
tic pop -#endif <=
br>- /** Dispatc=
h sign op to xkey_cng_<rsa/ec>_sign */ static int xkey_cng_sign(void *handle, unsigned char *sig, size_t *sigl=
en, const unsigned char *tbs, To view, =
visit ch=
ange 1464 . To unsubscribe, or for help writing mail filters, visit settings .
Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I789022af7c4977c4dff4f7671f4=
91fe5836828fa
Gerrit-Change-Number: 1464
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <frank@...2723...=
.>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...=
.1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...=
ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...=
..1227...>
=
--K2IDI7yazno=--