Skip to content

curl_sha512_256: support delegating to wolfSSL API#21077

Closed
vszakats wants to merge 14 commits intocurl:masterfrom
vszakats:curl_sha512_256
Closed

curl_sha512_256: support delegating to wolfSSL API#21077
vszakats wants to merge 14 commits intocurl:masterfrom
vszakats:curl_sha512_256

Conversation

@vszakats
Copy link
Copy Markdown
Member

@vszakats vszakats commented Mar 23, 2026

Offered by wolfSSL v5.0.0+ (2021-11-01).


@vszakats vszakats marked this pull request as draft March 23, 2026 17:55
can't redefine because:
```
/home/runner/work/curl/curl/lib/sha256.c:63:22: error: call to undeclared function 'EVP_MD_CTX_create'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
   63 |   ctx->openssl_ctx = EVP_MD_CTX_create();
      |                      ^
/home/runner/work/curl/curl/lib/sha256.c:63:22: note: did you mean 'EVP_MD_CTX_free'?
/usr/include/openssl/evp.h:700:6: note: 'EVP_MD_CTX_free' declared here
  700 | void EVP_MD_CTX_free(EVP_MD_CTX *ctx);
      |      ^
In file included from /home/runner/work/curl/curl/bld/lib/CMakeFiles/libcurl_static.dir/Unity/unity_0_c.c:310:
/home/runner/work/curl/curl/lib/sha256.c:63:20: error: incompatible integer to pointer conversion assigning to 'EVP_MD_CTX *' (aka 'struct evp_md_ctx_st *') from 'int' [-Wint-conversion]
   63 |   ctx->openssl_ctx = EVP_MD_CTX_create();
      |                    ^ ~~~~~~~~~~~~~~~~~~~
/home/runner/work/curl/curl/lib/sha256.c:68:5: error: call to undeclared function 'EVP_MD_CTX_destroy'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
   68 |     EVP_MD_CTX_destroy(ctx->openssl_ctx);
      |     ^
/home/runner/work/curl/curl/lib/sha256.c:86:3: error: call to undeclared function 'EVP_MD_CTX_destroy'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
   86 |   EVP_MD_CTX_destroy(ctx->openssl_ctx);
      |   ^
In file included from /home/runner/work/curl/curl/bld/lib/CMakeFiles/libcurl_static.dir/Unity/unity_0_c.c:439:
/home/runner/work/curl/curl/lib/vtls/openssl.c:5468:11: error: call to undeclared function 'EVP_MD_CTX_create'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
 5468 |   mdctx = EVP_MD_CTX_create();
      |           ^
/home/runner/work/curl/curl/lib/vtls/openssl.c:5468:9: error: incompatible integer to pointer conversion assigning to 'EVP_MD_CTX *' (aka 'struct evp_md_ctx_st *') from 'int' [-Wint-conversion]
 5468 |   mdctx = EVP_MD_CTX_create();
      |         ^ ~~~~~~~~~~~~~~~~~~~
/home/runner/work/curl/curl/lib/vtls/openssl.c:5472:5: error: call to undeclared function 'EVP_MD_CTX_destroy'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
 5472 |     EVP_MD_CTX_destroy(mdctx);
      |     ^
/home/runner/work/curl/curl/lib/vtls/openssl.c:5477:3: error: call to undeclared function 'EVP_MD_CTX_destroy'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
 5477 |   EVP_MD_CTX_destroy(mdctx);
      |   ^
8 errors generated.
```
https://github.com/curl/curl/actions/runs/23453717544/job/68237366259?pr=21077
@testclutch

This comment was marked as outdated.

@vszakats vszakats marked this pull request as ready for review March 23, 2026 20:34
@vszakats vszakats closed this in 28f0932 Mar 24, 2026
@vszakats vszakats deleted the curl_sha512_256 branch March 24, 2026 18:30
@vszakats vszakats requested a review from Copilot March 24, 2026 21:52
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds wolfSSL (v5.0.0+) support to the SHA-512/256 helper by delegating to wolfSSL’s OpenSSL-compat EVP API when available, so curl can avoid using the internal/other-backend implementations on wolfSSL builds.

Changes:

  • Add a wolfSSL selection branch (version-gated) that enables the EVP-based SHA-512/256 implementation.
  • Switch the EVP-based implementation to use either OpenSSL or wolfSSL EVP context/types and functions depending on the active backend.
  • Update the backend-selection comment describing ordering/selection.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 30 to 37
/* The recommended order of the TLS backends:
* 1. OpenSSL
* 2. GnuTLS
* 3. wolfSSL
* 4. Schannel SSPI
* 5. mbedTLS
* 6. Rustls
* 1. USE_OPENSSL
* 2. USE_WOLFSSL
* 3. USE_GNUTLS
* 4. USE_MBEDTLS
* 5. USE_RUSTLS
* 6. USE_WIN32_CRYPTO
* Skip the backend if it does not support the required algorithm */
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The “recommended order” comment lists backends (USE_MBEDTLS/USE_RUSTLS/USE_WIN32_CRYPTO) that this file doesn’t actually have #if branches for, and it doesn’t include the usual rationale used elsewhere (keeping SSL backend-specific branches in a fixed order to ensure deterministic selection when multiple backends are enabled). Please adjust this comment to match the actual branches present in this file and align with the standard wording used in e.g. lib/sha256.c and lib/curl_ntlm_core.c.

Copilot uses AI. Check for mistakes.
Comment on lines +68 to +70
# include <wolfssl/version.h>
# if defined(LIBWOLFSSL_VERSION_HEX) && LIBWOLFSSL_VERSION_HEX >= 0x05000000
# include <wolfssl/options.h>
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wolfSSL headers are typically included with <wolfssl/options.h> before <wolfssl/version.h> (see lib/vtls/wolfssl.c). Consider swapping the include order here to match that convention, since options.h can affect wolfSSL header feature macros.

Suggested change
# include <wolfssl/version.h>
# if defined(LIBWOLFSSL_VERSION_HEX) && LIBWOLFSSL_VERSION_HEX >= 0x05000000
# include <wolfssl/options.h>
# include <wolfssl/options.h>
# include <wolfssl/version.h>
# if defined(LIBWOLFSSL_VERSION_HEX) && LIBWOLFSSL_VERSION_HEX >= 0x05000000

Copilot uses AI. Check for mistakes.
# if defined(LIBWOLFSSL_VERSION_HEX) && LIBWOLFSSL_VERSION_HEX >= 0x05000000
# include <wolfssl/options.h>
# include <wolfssl/openssl/evp.h>
# ifndef WOLFSSL_NOSHA512_256
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wolfSSL feature gate uses WOLFSSL_NOSHA512_256, but other wolfSSL capability checks in this repo use unprefixed NO_* macros from wolfssl/options.h (e.g. NO_MD4/NO_MD5). Please verify that WOLFSSL_NOSHA512_256 is the correct macro exported by wolfSSL; if not, switch to the correct NO_* guard (and/or guard on the presence of the wolfSSL EVP SHA-512/256 symbols) to avoid compiling the EVP path when SHA-512/256 is disabled in wolfSSL.

Suggested change
# ifndef WOLFSSL_NOSHA512_256
# ifndef NO_SHA512_256

Copilot uses AI. Check for mistakes.
vszakats added a commit that referenced this pull request Mar 25, 2026
Replacing the OpenSSL-like compatibility interface, and syncing with
existing API use within lib/wolfssl.c for SHA-256.

Ref: https://www.wolfssl.com/documentation/manuals/wolfssl/group__SHA.html

Follow-up to 28f0932 #21077
Follow-up to 988b352 #21078

Closes #21090
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants