From cfadbaa133504d47ece989486fde944d076e0222 Mon Sep 17 00:00:00 2001 From: Xi Ruoyao Date: Thu, 30 Apr 2026 22:53:20 +0800 Subject: [PATCH] gnutls: allow building with nettle 4.0 Closes #21169 --- lib/curl_sha512_256.c | 7 ++++++- lib/md5.c | 5 +++++ lib/sha256.c | 7 ++++++- lib/vtls/gtls.c | 5 +++++ m4/curl-gnutls.m4 | 4 ++-- 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/curl_sha512_256.c b/lib/curl_sha512_256.c index 73b959c91d..5c3bcdf800 100644 --- a/lib/curl_sha512_256.c +++ b/lib/curl_sha512_256.c @@ -75,7 +75,8 @@ #endif #if !defined(HAS_SHA512_256_IMPLEMENTATION) && defined(USE_GNUTLS) -# include +# include +# include # ifdef SHA512_256_DIGEST_SIZE # define USE_GNUTLS_SHA512_256 1 # endif @@ -281,8 +282,12 @@ static CURLcode Curl_sha512_256_finish(unsigned char *digest, void *context) { Curl_sha512_256_ctx * const ctx = (Curl_sha512_256_ctx *)context; +#if NETTLE_VERSION_MAJOR >= 4 + sha512_256_digest(ctx, (uint8_t *)digest); +#else sha512_256_digest(ctx, (size_t)CURL_SHA512_256_DIGEST_SIZE, (uint8_t *)digest); +#endif return CURLE_OK; } diff --git a/lib/md5.c b/lib/md5.c index 4dd0d7c278..9d339becfa 100644 --- a/lib/md5.c +++ b/lib/md5.c @@ -47,6 +47,7 @@ #ifdef USE_GNUTLS #include +#include typedef struct md5_ctx my_md5_ctx; @@ -64,7 +65,11 @@ static void my_md5_update(void *ctx, static void my_md5_final(unsigned char *digest, void *ctx) { +#if NETTLE_VERSION_MAJOR >= 4 + md5_digest(ctx, digest); +#else md5_digest(ctx, 16, digest); +#endif } #elif defined(USE_OPENSSL) && \ diff --git a/lib/sha256.c b/lib/sha256.c index eeeec6c696..6211d04cd0 100644 --- a/lib/sha256.c +++ b/lib/sha256.c @@ -113,7 +113,8 @@ static void my_sha256_final(unsigned char *digest, void *in) } #elif defined(USE_GNUTLS) -#include +#include +#include typedef struct sha256_ctx my_sha256_ctx; @@ -132,7 +133,11 @@ static void my_sha256_update(void *ctx, static void my_sha256_final(unsigned char *digest, void *ctx) { +#if NETTLE_VERSION_MAJOR >= 4 + sha256_digest(ctx, digest); +#else sha256_digest(ctx, SHA256_DIGEST_SIZE, digest); +#endif } #elif defined(USE_MBEDTLS) && \ diff --git a/lib/vtls/gtls.c b/lib/vtls/gtls.c index e60e5a5ecc..db62c75774 100644 --- a/lib/vtls/gtls.c +++ b/lib/vtls/gtls.c @@ -37,6 +37,7 @@ #include #include #include +#include #include "urldata.h" #include "curl_trc.h" @@ -2268,7 +2269,11 @@ static CURLcode gtls_sha256sum(const unsigned char *tmp, /* input */ struct sha256_ctx SHA256pw; sha256_init(&SHA256pw); sha256_update(&SHA256pw, (unsigned int)tmplen, tmp); +#if NETTLE_VERSION_MAJOR >= 4 + sha256_digest(&SHA256pw, sha256sum); +#else sha256_digest(&SHA256pw, (unsigned int)sha256len, sha256sum); +#endif return CURLE_OK; } diff --git a/m4/curl-gnutls.m4 b/m4/curl-gnutls.m4 index b8ee3f5780..222386e0d9 100644 --- a/m4/curl-gnutls.m4 +++ b/m4/curl-gnutls.m4 @@ -145,7 +145,7 @@ dnl if test "$GNUTLS_ENABLED" = "1"; then USE_GNUTLS_NETTLE= dnl First check if we can detect either crypto library via transitive linking - AC_CHECK_LIB(gnutls, nettle_MD5Init, [ USE_GNUTLS_NETTLE=1 ]) + AC_CHECK_LIB(gnutls, nettle_md5_init, [ USE_GNUTLS_NETTLE=1 ]) dnl If not, try linking directly to both of them to see if they are available if test -z "$USE_GNUTLS_NETTLE"; then @@ -174,7 +174,7 @@ if test "$GNUTLS_ENABLED" = "1"; then CPPFLAGS="$CPPFLAGS $addcflags" fi - AC_CHECK_LIB(nettle, nettle_MD5Init, + AC_CHECK_LIB(nettle, nettle_md5_init, [ USE_GNUTLS_NETTLE=1 ],