From: "flichtenheld (Code Review)" Date: Thu, 7 Aug 2025 10:32:11 +0000 In-Reply-To: References: Reply-To: frank@...2641..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="t6/BFcn392k="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: openvpn_PRF: Change API to use size_t for lenghts List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos Cc: openvpn-devel --t6/BFcn392k= 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 reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/1135?usp=3Demail to look at the new patch set (#2). Change subject: openvpn_PRF: Change API to use size_t for lenghts ...................................................................... openvpn_PRF: Change API to use size_t for lenghts Basically all users already wanted that anyway. And most of the library functions also take size_t nowadays. Change-Id: Ic88cd6e143bc48cab3c9ebb7c7007513803bd199 Signed-off-by: Frank Lichtenheld --- M src/openvpn/crypto.c M src/openvpn/crypto_backend.h M src/openvpn/crypto_mbedtls.c M src/openvpn/crypto_openssl.c M src/openvpn/ssl.c M tests/unit_tests/openvpn/test_crypto.c 6 files changed, 23 insertions(+), 23 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/35/1135/2 diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c index 1fa08fd..e128bb8 100644 --- a/src/openvpn/crypto.c +++ b/src/openvpn/crypto.c @@ -1903,8 +1903,8 @@ uint8_t out[8]; uint8_t expected_out[] =3D { 'q', 'D', '\xfe', '%', '@', 's', 'u', '\x= 95' }; - int ret =3D ssl_tls1_PRF((uint8_t *)seed, (int)strlen(seed), (uint8_t = *)secret, - (int)strlen(secret), out, sizeof(out)); + int ret =3D ssl_tls1_PRF((uint8_t *)seed, strlen(seed), (uint8_t *)sec= ret, + strlen(secret), out, sizeof(out)); return (ret && memcmp(out, expected_out, sizeof(out)) =3D=3D 0); } diff --git a/src/openvpn/crypto_backend.h b/src/openvpn/crypto_backend.h index 59418f6..b74cb7f 100644 --- a/src/openvpn/crypto_backend.h +++ b/src/openvpn/crypto_backend.h @@ -716,7 +716,7 @@ * * @return true if successful, false on any error */ -bool ssl_tls1_PRF(const uint8_t *seed, int seed_len, const uint8_t *secret= , int secret_len, - uint8_t *output, int output_len); +bool ssl_tls1_PRF(const uint8_t *seed, size_t seed_len, const uint8_t *sec= ret, size_t secret_len, + uint8_t *output, size_t output_len); #endif /* CRYPTO_BACKEND_H_ */ diff --git a/src/openvpn/crypto_mbedtls.c b/src/openvpn/crypto_mbedtls.c index 86317dd..87a2d12 100644 --- a/src/openvpn/crypto_mbedtls.c +++ b/src/openvpn/crypto_mbedtls.c @@ -983,8 +983,8 @@ * from recent versions, so we use our own implementation if necessary. */ #if defined(HAVE_MBEDTLS_SSL_TLS_PRF) && defined(MBEDTLS_SSL_TLS_PRF_TLS1) bool -ssl_tls1_PRF(const uint8_t *seed, int seed_len, const uint8_t *secret, int= secret_len, - uint8_t *output, int output_len) +ssl_tls1_PRF(const uint8_t *seed, size_t seed_len, const uint8_t *secret, = size_t secret_len, + uint8_t *output, size_t output_len) { return mbed_ok(mbedtls_ssl_tls_prf(MBEDTLS_SSL_TLS_PRF_TLS1, secret, s= ecret_len, "", seed, seed_len, output, output_len)); @@ -1002,8 +1002,8 @@ * @param olen Length of the output buffer */ static void -tls1_P_hash(const mbedtls_md_info_t *md_kt, const uint8_t *sec, int sec_le= n, const uint8_t *seed, - int seed_len, uint8_t *out, int olen) +tls1_P_hash(const mbedtls_md_info_t *md_kt, const uint8_t *sec, size_t sec= _len, const uint8_t *seed, + size_t seed_len, uint8_t *out, size_t olen) { struct gc_arena gc =3D gc_new(); uint8_t A1[MAX_HMAC_KEY_LENGTH]; @@ -1089,8 +1089,8 @@ * (2) The pre-master secret is generated by the client. */ bool -ssl_tls1_PRF(const uint8_t *label, int label_len, const uint8_t *sec, int = slen, uint8_t *out1, - int olen) +ssl_tls1_PRF(const uint8_t *label, size_t label_len, const uint8_t *sec, s= ize_t slen, uint8_t *out1, + size_t olen) { struct gc_arena gc =3D gc_new(); const md_kt_t *md5 =3D md_get("MD5"); diff --git a/src/openvpn/crypto_openssl.c b/src/openvpn/crypto_openssl.c index 2351bfd..19eb988 100644 --- a/src/openvpn/crypto_openssl.c +++ b/src/openvpn/crypto_openssl.c @@ -1341,8 +1341,8 @@ } #if (OPENSSL_VERSION_NUMBER >=3D 0x30000000L) && !defined(LIBRESSL_VERSION= _NUMBER) bool -ssl_tls1_PRF(const uint8_t *seed, int seed_len, const uint8_t *secret, int= secret_len, - uint8_t *output, int output_len) +ssl_tls1_PRF(const uint8_t *seed, size_t seed_len, const uint8_t *secret, = size_t secret_len, + uint8_t *output, size_t output_len) { bool ret =3D true; EVP_KDF_CTX *kctx =3D NULL; @@ -1368,9 +1368,9 @@ params[0] =3D OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, SN_md5_sha= 1, strlen(SN_md5_sha1)); params[1] =3D OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SECRET,= (uint8_t *)secret, - (size_t)secret_len); + secret_len); params[2] =3D - OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SEED, (uint8_t *)= seed, (size_t)seed_len); + OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SEED, (uint8_t *)= seed, seed_len); params[3] =3D OSSL_PARAM_construct_end(); if (EVP_KDF_derive(kctx, output, output_len, params) <=3D 0) @@ -1392,15 +1392,15 @@ } #elif defined(OPENSSL_IS_AWSLC) bool -ssl_tls1_PRF(const uint8_t *label, int label_len, const uint8_t *sec, int = slen, uint8_t *out1, - int olen) +ssl_tls1_PRF(const uint8_t *label, size_t label_len, const uint8_t *sec, s= ize_t slen, uint8_t *out1, + size_t olen) { CRYPTO_tls1_prf(EVP_md5_sha1(), out1, olen, sec, slen, label, label_le= n, NULL, 0, NULL, 0); } #elif !defined(LIBRESSL_VERSION_NUMBER) && !defined(ENABLE_CRYPTO_WOLFSSL) bool -ssl_tls1_PRF(const uint8_t *seed, int seed_len, const uint8_t *secret, int= secret_len, - uint8_t *output, int output_len) +ssl_tls1_PRF(const uint8_t *seed, size_t seed_len, const uint8_t *secret, = size_t secret_len, + uint8_t *output, size_t output_len) { EVP_PKEY_CTX *pctx =3D EVP_PKEY_CTX_new_id(EVP_PKEY_TLS1_PRF, NULL); if (!pctx) @@ -1448,7 +1448,7 @@ * OpenSSL does. As result they will only be able to support * peers that support TLS EKM like when running with OpenSSL 3.x FIPS */ bool -ssl_tls1_PRF(const uint8_t *label, int label_len, const uint8_t *sec, int = slen, uint8_t *out1, +ssl_tls1_PRF(const uint8_t *label, size_t label_len, const uint8_t *sec, i= nt slen, uint8_t *out1, int olen) { return false; diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c index 84ef4fb..17065aa 100644 --- a/src/openvpn/ssl.c +++ b/src/openvpn/ssl.c @@ -1294,10 +1294,10 @@ } static bool -openvpn_PRF(const uint8_t *secret, int secret_len, const char *label, cons= t uint8_t *client_seed, - int client_seed_len, const uint8_t *server_seed, int server_se= ed_len, +openvpn_PRF(const uint8_t *secret, size_t secret_len, const char *label, c= onst uint8_t *client_seed, + size_t client_seed_len, const uint8_t *server_seed, size_t ser= ver_seed_len, const struct session_id *client_sid, const struct session_id *= server_sid, - uint8_t *output, int output_len) + uint8_t *output, size_t output_len) { /* concatenate seed components */ diff --git a/tests/unit_tests/openvpn/test_crypto.c b/tests/unit_tests/open= vpn/test_crypto.c index de8f9fe..77834e8 100644 --- a/tests/unit_tests/openvpn/test_crypto.c +++ b/tests/unit_tests/openvpn/test_crypto.c @@ -161,7 +161,7 @@ uint8_t out[32]; - bool ret =3D ssl_tls1_PRF(seed, (int)seed_len, secret, (int)secret_len= , out, sizeof(out)); + bool ret =3D ssl_tls1_PRF(seed, seed_len, secret, secret_len, out, siz= eof(out)); #if defined(LIBRESSL_VERSION_NUMBER) || defined(ENABLE_CRYPTO_WOLFSSL) /* No TLS1 PRF support in these libraries */ -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1135?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: Ic88cd6e143bc48cab3c9ebb7c7007513803bd199 Gerrit-Change-Number: 1135 Gerrit-PatchSet: 2 Gerrit-Owner: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-MessageType: newpatchset --t6/BFcn392k= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: plaisthos.

flichtenheld uploaded patch set #2 to this change.

<= p>View C= hange

openvpn_PRF: Change API to use size_t for lenghts

Basicall= y all users already wanted that anyway. And most
of the library function= s also take size_t nowadays.

Change-Id: Ic88cd6e143bc48cab3c9ebb7c70= 07513803bd199
Signed-off-by: Frank Lichtenheld <frank@...2641...><= br>---
M src/openvpn/crypto.c
M src/openvpn/crypto_backend.h
M src= /openvpn/crypto_mbedtls.c
M src/openvpn/crypto_openssl.c
M src/openvp= n/ssl.c
M tests/unit_tests/openvpn/test_crypto.c
6 files changed, 23 = insertions(+), 23 deletions(-)

git pull ssh://gerrit.openvpn.net:=
29418/openvpn refs/changes/35/1135/2
diff --git a/src/openvpn/crypt=
o.c b/src/openvpn/crypto.c
index 1fa08fd..e128bb8 100644
--- a/src/openvpn/crypto.c
+++ b/src/openvpn/= crypto.c
@@ -1903,8 +1903,8 @@
uint8_t= out[8];
uint8_t expected_out[] =3D { 'q', = 9;D', '\xfe', '%', '@', 's', 'u'= ;, '\x95' };

- int ret =3D ssl_tls1_PRF((uint8_t *)seed, (int)strlen(= seed), (uint8_t *)secret,
- (int)strlen(secret), out, sizeof(out));
+ int ret =3D ssl_tls1= _PRF((uint8_t *)seed, strlen(seed), (uint8_t *)secret,
+ strlen(secret= ), out, sizeof(out));

return (ret &a= mp;& memcmp(out, expected_out, sizeof(out)) =3D=3D 0);
= }
diff --git a/src/openvpn/crypto_backend.h b/src/openvpn/= crypto_backend.h
index 59418f6..b74cb7f 100644
--- a/src/openvpn/crypto_backend.h

+++ b/src/openvpn/cr= ypto_backend.h
@@ -716,7 +716,7 @@
*
* @return true if successful, false on any error=
*/
-= bool ssl_tls1_PRF(const uint8_t *seed, int seed_len, const uint8_t *secret,= int secret_len,
- = uint8_t *output, int output_len);
+bool ssl_tls1_PRF(const uint8_t *seed, size_t se= ed_len, const uint8_t *secret, size_t secret_len,
+ uint8_t *output, size_t out= put_len);

#endif /* CRYPTO_BACKEND_H_ */=
diff --git a/src/openvpn/crypto_mbedtls.c b/src/openvpn/cr= ypto_mbedtls.c
index 86317dd..87a2d12 100644
--- a/src/openvpn/crypto_mbedtls.c

+++ b/src/openvpn/cryp= to_mbedtls.c
@@ -983,8 +983,8 @@
* from r= ecent versions, so we use our own implementation if necessary. */ #if defined(HAVE_MBEDTLS_SSL_TLS_PRF) && defined(MBEDTLS_SS= L_TLS_PRF_TLS1)
bool
-ssl_tls1_PRF(const uint8_t *seed, int seed_len, const uint8= _t *secret, int secret_len,
- uint8_t *output, int output_len)
+ssl_tls1_PRF(const uint8_t *seed, size_t = seed_len, const uint8_t *secret, size_t secret_len,
+ uint8_t *output, size_t outp= ut_len)
{
return mbed_ok(mbedtls_ssl_= tls_prf(MBEDTLS_SSL_TLS_PRF_TLS1, secret, secret_len, "", seed,
seed_len, output, ou= tput_len));
@@ -1002,8 +1002,8 @@
* @para= m olen Length of the output buffer
*/
= static void
-tls= 1_P_hash(const mbedtls_md_info_t *md_kt, const uint8_t *sec, int sec_len, c= onst uint8_t *seed,
- = int seed_len, uint8_t *out, int olen)
+tls1_P_hash(const mbedtls_md_info_t *md_kt, con= st uint8_t *sec, size_t sec_len, const uint8_t *seed,
+ size_t seed_len, uint8_t *out= , size_t olen)
{
struct gc_arena gc = =3D gc_new();
uint8_t A1[MAX_HMAC_KEY_LENGTH];<= br>@@ -1089,8 +1089,8 @@
* (2) The pre-master secre= t is generated by the client.
*/
bool
-ssl_tls1_PRF(const uint8= _t *label, int label_len, const uint8_t *sec, int slen, uint8_t *out1,
- int olen)
+ssl_tls1_PRF(const uint= 8_t *label, size_t label_len, const uint8_t *sec, size_t slen, uint8_t *out= 1,
+ size= _t olen)
{
struct gc_arena gc =3D gc_= new();
const md_kt_t *md5 =3D md_get("MD5");=
diff --git a/src/openvpn/crypto_openssl.c b/src/openvpn/cr= ypto_openssl.c
index 2351bfd..19eb988 100644
--- a/src/openvpn/crypto_openssl.c

+++ b/src/openvpn/cryp= to_openssl.c
@@ -1341,8 +1341,8 @@
}
#if (OPENSSL_VERSION_NUMBER >=3D 0x30000000L) && !de= fined(LIBRESSL_VERSION_NUMBER)
bool
-ssl_tls1_PRF(const uint8_t *seed, int seed_= len, const uint8_t *secret, int secret_len,
- uint8_t *output, int output_len)<= br>+ssl_tls1_PRF(const uint8_t = *seed, size_t seed_len, const uint8_t *secret, size_t secret_len,+ uint8_t *output,= size_t output_len)
{
bool ret =3D tr= ue;
EVP_KDF_CTX *kctx =3D NULL;
@@ -13= 68,9 +1368,9 @@
params[0] =3D
= OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, SN_md5_sha1, strle= n(SN_md5_sha1));
params[1] =3D OSSL_PARAM_construct_oc= tet_string(OSSL_KDF_PARAM_SECRET, (uint8_t *)secret,
- = (size_t)secret_len);
+ secret_len);
params[2] =3D
- OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SEED, (ui= nt8_t *)seed, (size_t)seed_len);
+ OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SEED,= (uint8_t *)seed, seed_len);
params[3] =3D OSSL_PARAM_= construct_end();

if (EVP_KDF_derive(= kctx, output, output_len, params) <=3D 0)
@@ -1392,15 +1= 392,15 @@
}
#elif defined(OPENSSL_IS_AWSL= C)
bool
= - int olen)
+ssl_tls1_PRF(const uint8_t *label, size_t label_len, const uint8_t *sec= , size_t slen, uint8_t *out1,
+ size_t olen)
{
= CRYPTO_tls1_prf(EVP_md5_sha1(), out1, olen, sec, slen, label, label_len, N= ULL, 0, NULL, 0);
}
#elif !defined(LIBRES= SL_VERSION_NUMBER) && !defined(ENABLE_CRYPTO_WOLFSSL)
bool

-ssl_tls1_PRF(= const uint8_t *seed, int seed_len, const uint8_t *secret, int secret_len,
- uint8_t *o= utput, int output_len)
= + uint8_t *output, size_t output_len)
{=
EVP_PKEY_CTX *pctx =3D EVP_PKEY_CTX_new_id(EVP_PKEY_TLS1_PRF= , NULL);
if (!pctx)
@@ -1448,7 +1448,7= @@
* OpenSSL does. As result they will only be able to s= upport
* peers that support TLS EKM like when running wit= h OpenSSL 3.x FIPS */
bool
-ssl_tls1_PRF(const uint8_t *label, int label_len, con= st uint8_t *sec, int slen, uint8_t *out1,
+ssl_tls1_PRF(const uint8_t *label, size_t label_len, = const uint8_t *sec, int slen, uint8_t *out1,
= int olen)
{
return false;
<= span>diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c

ind= ex 84ef4fb..17065aa 100644
--- a/src/openvpn/ssl.c+++ b/src/openvpn/ssl.c
@@ -1294,10 +1294,10 @@
}

static bool
-openvpn_PRF(const uint8_t *secret,= int secret_len, const char *label, const uint8_t *client_seed,

<= span style=3D"color: hsl(0, 100%, 40%);">- int client_seed_len, = const uint8_t *server_seed, int server_seed_len,

+openvpn_PRF(const uint8_t *secret, size_t secr= et_len, const char *label, const uint8_t *client_seed,
+ size_t client_seed_len, cons= t uint8_t *server_seed, size_t server_seed_len,
= const struct session_id *client_sid, const struct session_id *server_sid,=
- uint8_t *= output, int output_len)
+ uint8_t *output, size_t output_len)
{
/* concatenate seed components */
=
diff --git a/tests/unit_tests/openvpn/test_crypto.c b/tests/unit_= tests/openvpn/test_crypto.c
index de8f9fe..77834e8 100644
--- a/tests/unit_tests/openvpn/test_crypto.c
+++ b/tests/unit_tests/openvpn/test_crypto.c

@@ -161,7 +16= 1,7 @@


uint8_t out= [32];
- bool ret =3D= ssl_tls1_PRF(seed, (int)seed_len, secret, (int)secret_len, out, sizeof(out= ));
+ bool ret =3D= ssl_tls1_PRF(seed, seed_len, secret, secret_len, out, sizeof(out));=

#if defined(LIBRESSL_VERSION_NUMBER) || define= d(ENABLE_CRYPTO_WOLFSSL)
/* No TLS1 PRF support in the= se libraries */

To view, visit change 1135= . To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ic88cd6e143bc48cab3c9ebb7c70= 07513803bd199
Gerrit-Change-Number: 1135
Gerrit-PatchSet: 2
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...>
Gerrit-MessageType: newpatchset
--t6/BFcn392k=--