Skip to content

Add crypto callback support for SM 2 and SM4 - #513

Draft
padelsbach wants to merge 6 commits into
wolfSSL:mainfrom
padelsbach:sm-crypto-cb
Draft

padelsbach wants to merge 6 commits into
wolfSSL:mainfrom
padelsbach:sm-crypto-cb

Conversation

@padelsbach

@padelsbach padelsbach commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Add SM2 and SM4 support. No async support.

Copilot AI balanced review requested due to automatic review settings October 14, 2026 18:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

SM4 DMA lengths can truncate silently, and advertised SM3 offloading remains unimplemented.

3 open findings
What changed in this PR

Adds SM2 and SM4 offloading to wolfHSM’s crypto callback infrastructure, with optional SM-enabled builds.

Changes:

  • Adds client/server operations, wire messages, and SM4 DMA support.
  • Adds interoperability, cached-key, streaming, and DMA tests.
  • Enables SM builds and installs pinned wolfsm sources in CI.
File Description
wolfhsm/​wh_message_crypto.h Defines SM2/SM4 wire messages.
wolfhsm/​wh_client_crypto.h Declares SM2/SM4 client APIs.
test/​wh_test_check_struct_padding.c Checks new message layouts.
test/​Makefile Adds SM=1 option.
test/​config/​user_settings.h Enables SM algorithms for testing.
test-refactor/​wh_test_list.c Registers SM2/SM4 tests.
test-refactor/​posix/​Makefile Adds SM=1 option.
test-refactor/​misc/​wh_test_check_struct_padding.c Checks new message layouts.
test-refactor/​client-server/​wh_test_crypto_sm4.c Tests SM4 modes and DMA.
test-refactor/​client-server/​wh_test_crypto_sm2.c Tests SM2 operations and cached keys.
src/​wh_server_crypto.c Implements SM2/SM4 server handlers.
src/​wh_message_crypto.c Adds message translation functions.
src/​wh_client_cryptocb.c Dispatches SM2/SM4 callbacks.
src/​wh_client_crypto.c Implements client requests and responses.
docs/​src/​6-Utilities.md Documents SM test prerequisites.
.github/​actions/​checkout-wolfssl/​action.yml Pins dependencies and enables SM testing.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/wh_server_crypto.c Outdated
if (needed != inSize) {
return WH_ERROR_BADARGS;
}
if (req.input.sz != req.output.sz) {
}
if (ret == 0) {
ret = wc_ecc_sm2_verify_hash(sig, sigLen, hash, sizeof(hash),
&verified, hsmKey);
/* SM2/SM3/SM4 Options, set by SM=1. Needs wolfsm installed into wolfSSL. */
#ifdef WOLFHSM_CFG_TEST_SM
#define WOLFSSL_SM2
#define WOLFSSL_SM3
@padelsbach padelsbach changed the title Add crypto callback support for SM 2/3/4 Add crypto callback support for SM 2 and SM4 Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants