From: "flichtenheld (Code Review)" Date: Sat, 4 Apr 2026 23:12:56 +0000 References: Reply-To: frank@...2641..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net Message-ID: <050e3f9be80e22e8e80cf0bc50ea4994ca71e97f-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="QKIXn9ZHs5s="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: crypto_backend: Remove md_full List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos Cc: openvpn-devel --QKIXn9ZHs5s= 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/+/1612?usp=3Demail to review the following change. Change subject: crypto_backend: Remove md_full ...................................................................... crypto_backend: Remove md_full There was only one user for mbedtls < 4.0, so remove all the unused implementations. Identified by cppcheck. Change-Id: Ie2285f5bf52f5c669fb01f9ae36d6aa1674f0929 Signed-off-by: Frank Lichtenheld --- M src/openvpn/crypto_backend.h M src/openvpn/crypto_mbedtls.c M src/openvpn/crypto_mbedtls_legacy.c M src/openvpn/crypto_mbedtls_legacy.h M src/openvpn/crypto_openssl.c M src/openvpn/ssl_mbedtls.c 6 files changed, 5 insertions(+), 54 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/12/1612/1 diff --git a/src/openvpn/crypto_backend.h b/src/openvpn/crypto_backend.h index 4e9283d..360abbe 100644 --- a/src/openvpn/crypto_backend.h +++ b/src/openvpn/crypto_backend.h @@ -549,18 +549,6 @@ * */ -/** - * Calculates the message digest for the given buffer. - * - * @param mdname message digest name - * @param src Buffer to digest. May not be NULL. - * @param src_len The length of the incoming buffer. - * @param dst Buffer to write the message digest to. May not be = NULL. - * - * @return true on success, false on failure - */ -bool md_full(const char *mdname, const uint8_t *src, size_t src_len, uint8= _t *dst); - /* * Allocate a new message digest context * diff --git a/src/openvpn/crypto_mbedtls.c b/src/openvpn/crypto_mbedtls.c index b0d0820..665257c0 100644 --- a/src/openvpn/crypto_mbedtls.c +++ b/src/openvpn/crypto_mbedtls.c @@ -696,28 +696,6 @@ return ctx; } -bool -md_full(const char *mdname, const uint8_t *src, size_t src_len, uint8_t *d= st) -{ - const md_info_t *md =3D md_get(mdname); - if (md =3D=3D NULL) - { - return false; - } - - /* We depend on the caller to ensure that dst has enough room for the = hash, - * so we just tell PSA that it can hold the appropriate amount of byte= s. */ - size_t dst_size =3D PSA_HASH_LENGTH(md->psa_alg); - size_t hash_length =3D 0; - - psa_status_t status =3D psa_hash_compute(md->psa_alg, src, src_len, ds= t, dst_size, &hash_length); - if (status !=3D PSA_SUCCESS || hash_length !=3D dst_size) - { - return false; - } - return true; -} - void md_ctx_free(md_ctx_t *ctx) { diff --git a/src/openvpn/crypto_mbedtls_legacy.c b/src/openvpn/crypto_mbedt= ls_legacy.c index 3f04a3e..6556358 100644 --- a/src/openvpn/crypto_mbedtls_legacy.c +++ b/src/openvpn/crypto_mbedtls_legacy.c @@ -769,7 +769,7 @@ */ -static const mbedtls_md_info_t * +const mbedtls_md_info_t * md_get(const char *digest) { const mbedtls_md_info_t *md =3D NULL; @@ -825,13 +825,6 @@ * */ -bool -md_full(const char *mdname, const uint8_t *src, size_t src_len, uint8_t *d= st) -{ - const mbedtls_md_info_t *kt =3D md_get(mdname); - return 0 =3D=3D mbedtls_md(kt, src, src_len, dst); -} - mbedtls_md_context_t * md_ctx_new(void) { diff --git a/src/openvpn/crypto_mbedtls_legacy.h b/src/openvpn/crypto_mbedt= ls_legacy.h index 1005057..23113be 100644 --- a/src/openvpn/crypto_mbedtls_legacy.h +++ b/src/openvpn/crypto_mbedtls_legacy.h @@ -137,4 +137,6 @@ */ #define mbed_ok(errval) mbed_log_func_line_lite(D_CRYPT_ERRORS, errval, __= func__, __LINE__) +const mbedtls_md_info_t *md_get(const char *digest); + #endif /* CRYPTO_MBEDTLS_H_ */ diff --git a/src/openvpn/crypto_openssl.c b/src/openvpn/crypto_openssl.c index e49f654..e268d7c 100644 --- a/src/openvpn/crypto_openssl.c +++ b/src/openvpn/crypto_openssl.c @@ -1107,17 +1107,6 @@ * */ -bool -md_full(const char *mdname, const uint8_t *src, size_t src_len, uint8_t *d= st) -{ - unsigned int in_md_len =3D 0; - evp_md_type *kt =3D md_get(mdname); - - int ret =3D EVP_Digest(src, src_len, dst, &in_md_len, kt, NULL); - EVP_MD_free(kt); - return ret =3D=3D 1; -} - EVP_MD_CTX * md_ctx_new(void) { diff --git a/src/openvpn/ssl_mbedtls.c b/src/openvpn/ssl_mbedtls.c index d0c481e..a62ff76 100644 --- a/src/openvpn/ssl_mbedtls.c +++ b/src/openvpn/ssl_mbedtls.c @@ -1029,8 +1029,9 @@ if (NULL !=3D ctx->crt_chain) { mbedtls_x509_crt *cert =3D ctx->crt_chain; + const mbedtls_md_info_t *kt =3D md_get("SHA256"); - if (!md_full("SHA256", cert->tbs.p, cert->tbs.len, sha256_hash)) + if (0 !=3D mbedtls_md(kt, cert->tbs.p, cert->tbs.len, sha256_hash)) { msg(M_WARN, "WARNING: failed to personalise random"); } -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1612?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: Ie2285f5bf52f5c669fb01f9ae36d6aa1674f0929 Gerrit-Change-Number: 1612 Gerrit-PatchSet: 1 Gerrit-Owner: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos --QKIXn9ZHs5s= 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

crypto_backend: Remove md_full

There= was only one user for mbedtls < 4.0,
so remove all the unused implem= entations.

Identified by cppcheck.

Change-Id: Ie2285f5bf52f5c= 669fb01f9ae36d6aa1674f0929
Signed-off-by: Frank Lichtenheld <frank@...1186...= .2641...>
---
M src/openvpn/crypto_backend.h
M src/openvpn/cryp= to_mbedtls.c
M src/openvpn/crypto_mbedtls_legacy.c
M src/openvpn/cryp= to_mbedtls_legacy.h
M src/openvpn/crypto_openssl.c
M src/openvpn/ssl_= mbedtls.c
6 files changed, 5 insertions(+), 54 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes=
/12/1612/1
diff --git a/src/openvpn/crypto_backend.h b/src/openvpn/=
crypto_backend.h
index 4e9283d..360abbe 100644
--- a/src/openvpn/crypto_backend.h
+++ b/src/openvpn/cr= ypto_backend.h
@@ -549,18 +549,6 @@
*
*/

-/**
- * C= alculates the message digest for the given buffer.
- *
- * @param mdname message digest name
- * @param src Buffer to digest. M= ay not be NULL.
- * @pa= ram src_len The length of the incoming buffer.
- * @param dst Buffer to write the= message digest to. May not be NULL.
- *
- * @= return true on success, false on failure
- */
-bool md_full(const char *mdname, const uint8_t *src, size_t s= rc_len, uint8_t *dst);
= -
/*
* Allocate a new message digest con= text
*
diff --git a/src/openvpn/crypto_mb= edtls.c b/src/openvpn/crypto_mbedtls.c
index b0d0820..66525= 7c0 100644
--- a/src/openvpn/crypto_mbedtls.c
+++ b/src/openvpn/crypto_mbedtls.c

@@ -696,28 +696,6 @@<= /span>
return ctx;
}

-bool
-md_full(const char *mdname, const uint8_t *= src, size_t src_len, uint8_t *dst)
-{
- con= st md_info_t *md =3D md_get(mdname);
- if (md =3D=3D NULL)
- {
= - return false;
= - }
-
- /* We depend on the caller to en= sure that dst has enough room for the hash,

- * so we just tell PSA that it can hold the appro= priate amount of bytes. */
- size_t dst_size =3D PSA_HASH_LENGTH(md->psa_alg);
- size_t hash_length =3D 0;
-
- psa_status_t status =3D psa_hash_compute(md-= >psa_alg, src, src_len, dst, dst_size, &hash_length);
- if (status !=3D PSA_SUCCESS || h= ash_length !=3D dst_size)

- {
- retu= rn false;
- }=
- return true;
<= span style=3D"color: hsl(0, 100%, 40%);">-}
-
void
md_ctx_free(m= d_ctx_t *ctx)
{
diff --git a/src/openvpn/c= rypto_mbedtls_legacy.c b/src/openvpn/crypto_mbedtls_legacy.c
index 3f04a3e..6556358 100644
--- a/src/openvpn/crypto_mb= edtls_legacy.c
+++ b/src/openvpn/crypto_mbedtls_legacy.c

@@ -769,7 +769,7 @@
*/


-static= const mbedtls_md_info_t *
+const mbedtls_md_info_t *
md_get(const char *digest= )
{
const mbedtls_md_info_t *md =3D N= ULL;
@@ -825,13 +825,6 @@
*
*/


-bool
-md_full(const= char *mdname, const uint8_t *src, size_t src_len, uint8_t *dst)
= -{
- const mbedtls_md_info_t *kt =3D md_get(mdname);<= /span>
- return 0 =3D=3D mb= edtls_md(kt, src, src_len, dst);
-}
- mbedtls_md_context_t *
md_ctx_new(void) {
diff --git a/src/openvpn/crypto_mbedtls_legacy.h = b/src/openvpn/crypto_mbedtls_legacy.h
index 1005057..23113b= e 100644
--- a/src/openvpn/crypto_mbedtls_legacy.h+++ b/src/openvpn/crypto_mbedtls_legacy.h
@@ -137,4= +137,6 @@
*/
#define mbed_ok(errval) mb= ed_log_func_line_lite(D_CRYPT_ERRORS, errval, __func__, __LINE__)
+const mbedt= ls_md_info_t *md_get(const char *digest);
+
#endif /* CRYPTO_MBEDTLS_H_ */
diff --git a/src/openvpn/crypto_openssl.c b/src/openvpn/crypto_= openssl.c
index e49f654..e268d7c 100644
---= a/src/openvpn/crypto_openssl.c
+++ b/src/openvpn/crypto_op= enssl.c
@@ -1107,17 +1107,6 @@
* */

-bool
-md_full(= const char *mdname, const uint8_t *src, size_t src_len, uint8_t *dst)
-{
- unsigned int in_md_len =3D 0;
- evp_md_type *kt =3D md_get(mdna= me);

-
- int ret =3D EVP_Digest(src, src_le= n, dst, &in_md_len, kt, NULL);
- EVP_MD_free(kt);
- return ret =3D=3D 1;
-}
-
EVP_MD_CTX *
md_ctx_new(void)
{

diff --git a/src/openvpn/ssl_mbedtls.c b/src/openvpn/ss= l_mbedtls.c
index d0c481e..a62ff76 100644
-= -- a/src/openvpn/ssl_mbedtls.c
+++ b/src/openvpn/ssl_mbedtl= s.c
@@ -1029,8 +1029,9 @@
if (NULL != =3D ctx->crt_chain)
{
mbed= tls_x509_crt *cert =3D ctx->crt_chain;
+ const mbedtls_md_info_t *kt =3D md_get("= SHA256");

- if (!md_full("SHA256", cert->tbs.p, cert-&g= t;tbs.len, sha256_hash))
+ if (0 !=3D mbedtls_md(kt, cert->tbs.p, cert->tbs.len, sh= a256_hash))
{
msg(M_W= ARN, "WARNING: failed to personalise random");
= }

To view, visit change 1612. To uns= ubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ie2285f5bf52f5c669fb01f9ae36= d6aa1674f0929
Gerrit-Change-Number: 1612
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...>
= --QKIXn9ZHs5s=--