commit 331003e
Michael Forney
·
2026-05-15 21:36:07 +0000 UTC
parent fda402b
curl: Use bearssl for md5/sha256/sha512-256 This reduces code size a bit by avoiding multiple implementations. The SHA-512/256 implementation requires a patched BearSSL, so we'll keep it as a local curl patch.
3 files changed,
+123,
-1
+1,
-0
1@@ -21,6 +21,7 @@
2 [submodule "pkg/curl/src"]
3 path = pkg/curl/src
4 url = https://github.com/oasislinux/curl.git
5+ ignore = all
6 [submodule "pkg/dosfstools/src"]
7 path = pkg/dosfstools/src
8 url = https://github.com/dosfstools/dosfstools
1@@ -0,0 +1,121 @@
2+From d1d4f8d4effdb9729bcdca711910bd418651f3fe Mon Sep 17 00:00:00 2001
3+From: Michael Forney <mforney@mforney.org>
4+Date: Fri, 15 May 2026 03:02:00 -0700
5+Subject: [PATCH] sha512-256: support delegating to (patched) bearssl
6+
7+---
8+ lib/curl_sha512_256.c | 81 ++++++++++++++++++++++++++++++++++++++++---
9+ 1 file changed, 77 insertions(+), 4 deletions(-)
10+
11+diff --git a/lib/curl_sha512_256.c b/lib/curl_sha512_256.c
12+index 75a7765931..2ac9002ea6 100644
13+--- a/lib/curl_sha512_256.c
14++++ b/lib/curl_sha512_256.c
15+@@ -31,10 +31,10 @@
16+ * 1. USE_OPENSSL
17+ * 2. USE_WOLFSSL
18+ * 3. USE_GNUTLS
19+- * 4. USE_MBEDTLS (TBD)
20+- * 5. USE_RUSTLS (TBD)
21+- * 6. USE_WIN32_CRYPTO (TBD)
22+- * 7. USE_BEARSSL (TBD)
23++ * 4. USE_BEARSSL
24++ * 5. USE_MBEDTLS (TBD)
25++ * 6. USE_RUSTLS (TBD)
26++ * 7. USE_WIN32_CRYPTO (TBD)
27+ * Skip the backend if it does not support the required algorithm */
28+
29+ #ifdef USE_OPENSSL
30+@@ -79,9 +79,16 @@
31+ # include <nettle/sha.h>
32+ # ifdef SHA512_256_DIGEST_SIZE
33+ # define USE_GNUTLS_SHA512_256 1
34++# define HAS_SHA512_256_IMPLEMENTATION 1
35+ # endif
36+ #endif /* !HAS_SHA512_256_IMPLEMENTATION && USE_GNUTLS */
37+
38++#if !defined(HAS_SHA512_256_IMPLEMENTATION) && defined(USE_BEARSSL)
39++# include <bearssl.h>
40++# define USE_BEARSSL_SHA512_256 1
41++# define HAS_SHA512_256_IMPLEMENTATION 1
42++#endif /* !HAS_SHA512_256_IMPLEMENTATION && USE_BEARSSL */
43++
44+ #ifdef USE_OPENSSL_SHA512_256
45+
46+ /* OpenSSL does not provide macros for SHA-512/256 sizes */
47+@@ -288,6 +295,72 @@ static CURLcode Curl_sha512_256_finish(unsigned char *digest, void *context)
48+ return CURLE_OK;
49+ }
50+
51++#elif defined(USE_BEARSSL_SHA512_256)
52++
53++#define CURL_SHA512_256_BLOCK_SIZE 128
54++#define CURL_SHA512_256_DIGEST_SIZE br_sha512_256_SIZE
55++
56++/**
57++ * Context type used for SHA-512/256 calculations
58++ */
59++typedef br_sha512_256_context Curl_sha512_256_ctx;
60++
61++/**
62++ * Initialise structure for SHA-512/256 calculation.
63++ *
64++ * @param context the calculation context
65++ * @return always CURLE_OK
66++ */
67++static CURLcode Curl_sha512_256_init(void *context)
68++{
69++ Curl_sha512_256_ctx * const ctx = (Curl_sha512_256_ctx *)context;
70++
71++ /* Check whether the header and this file use the same numbers */
72++ DEBUGASSERT(CURL_SHA512_256_DIGEST_LENGTH == CURL_SHA512_256_DIGEST_SIZE);
73++
74++ br_sha512_256_init(ctx);
75++
76++ return CURLE_OK;
77++}
78++
79++/**
80++ * Process portion of bytes.
81++ *
82++ * @param context the calculation context
83++ * @param data bytes to add to hash
84++ * @param length number of bytes in @a data
85++ * @return always CURLE_OK
86++ */
87++static CURLcode Curl_sha512_256_update(void *context,
88++ const unsigned char *data,
89++ size_t length)
90++{
91++ Curl_sha512_256_ctx * const ctx = (Curl_sha512_256_ctx *)context;
92++
93++ DEBUGASSERT((data != NULL) || (length == 0));
94++
95++ br_sha512_256_update(ctx, data, length);
96++
97++ return CURLE_OK;
98++}
99++
100++/**
101++ * Finalise SHA-512/256 calculation, return digest.
102++ *
103++ * @param context the calculation context
104++ * @param[out] digest set to the hash, must be #CURL_SHA512_256_DIGEST_SIZE
105++ * bytes
106++ * @return always CURLE_OK
107++ */
108++static CURLcode Curl_sha512_256_finish(unsigned char *digest, void *context)
109++{
110++ Curl_sha512_256_ctx * const ctx = (Curl_sha512_256_ctx *)context;
111++
112++ br_sha512_256_out(ctx, digest);
113++
114++ return CURLE_OK;
115++}
116++
117+ #else /* No system or TLS backend SHA-512/256 implementation available */
118+
119+ /* ** This implementation of SHA-512/256 hash calculation was originally ** *
120+--
121+2.54.0
122+
+1,
-1
1@@ -1 +1 @@
2-8.20.0 r1
3+8.20.0 r2