Skip to content

Add crypto callback mode for SLH-DSA - #512

Open
padelsbach wants to merge 8 commits into
wolfSSL:mainfrom
padelsbach:add-crypto-cb-slhdsa
Open

padelsbach wants to merge 8 commits into
wolfSSL:mainfrom
padelsbach:add-crypto-cb-slhdsa

Conversation

@padelsbach

Copy link
Copy Markdown
Contributor

No description provided.

@padelsbach
padelsbach force-pushed the add-crypto-cb-slhdsa branch 2 times, most recently from aed3238 to 7fe4069 Compare August 21, 2026 23:20
@padelsbach
padelsbach force-pushed the add-crypto-cb-slhdsa branch 4 times, most recently from 64514ae to a9eb8a9 Compare September 16, 2026 19:16
@padelsbach
padelsbach marked this pull request as ready for review September 16, 2026 19:49
@padelsbach
padelsbach requested review from Frauschi, bigbrett and wolfSSL-Fenrir-bot and removed request for bigbrett September 16, 2026 19:49

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #512

Scan targets checked: wolfhsm-core-bugs, wolfhsm-crypto-bugs, wolfhsm-src

Findings: 11
11 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Reported findings require changes before merge.

Comment thread test-refactor/client-server/wh_test_crypto_slhdsa.c
Comment thread src/wh_client_cryptocb.c Outdated
Comment thread src/wh_client_crypto.c Outdated
Comment thread src/wh_client_crypto.c Outdated
Comment thread src/wh_server_crypto.c Outdated
Comment thread test-refactor/client-server/wh_test_crypto_slhdsa.c
Comment thread src/wh_client_crypto.c Outdated
Comment thread src/wh_client_crypto.c Outdated
Comment thread src/wh_client_crypto.c Outdated
Comment thread src/wh_client_crypto.c

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #512

Scan targets checked: wolfhsm-core-bugs, wolfhsm-crypto-bugs, wolfhsm-src

Findings: 7
7 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Reported findings require changes before merge.

Comment thread src/wh_client_crypto.c Outdated
Comment thread src/wh_server_crypto.c
Comment thread src/wh_server_crypto.c Outdated
Comment thread src/wh_server_crypto.c
Comment thread src/wh_client_crypto.c
Comment thread src/wh_server_crypto.c
Comment thread test-refactor/client-server/wh_test_crypto_slhdsa.c

@Frauschi Frauschi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Went through the SLH-DSA callback support. Big addition, and the structure mirrors the ML-DSA paths closely enough to follow easily.

Comments inline. The ones I would most like to see addressed are the DMA READ_POST after a denied READ_PRE in _HandleSlhDsaVerifyDma, the unvalidated seedSz / 3 in both keygen handlers, and the seed left resident in the comm packet. The rest are smaller consistency points against the ML-DSA and ML-KEM siblings, and the last few are nits you can take or leave.

Nothing here is a blocker.

Comment thread src/wh_client_cryptocb.c
Comment thread src/wh_client_crypto.c
Comment thread src/wh_client_crypto.c
key_id = *inout_keyId;
}

ret = wh_Crypto_SlhDsaSerializeKeyDer(key, sizeof(buffer), buffer,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The wc_ForceZero(buffer, sizeof(buffer)) here only covers half the exposure. wh_Client_KeyCacheRequest_ex memcpys the same private-key DER into the shared transport buffer from wh_CommClient_GetDataPtr, and nothing clears that. _SlhDsaMakeKey in this PR does handle it, with wc_ForceZero(dataPtr, WOLFHSM_CFG_COMM_DATA_LEN), so the two new paths disagree.

It is not reliably overwritten by what follows either: the DER runs to about 320 bytes and a following CheckPrivKey writes roughly 88, so the tail survives in a buffer the server side can see under a shared-memory transport. wh_Client_SlhDsaImportKeyDma has the same gap through wh_Client_KeyCacheDma.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In wh_Client_SlhDsaImportKey() and the DMA equivalent, the CommBuffer still has the private key DER without a ForceZero.

Comment thread src/wh_client_crypto.c Outdated
Comment thread test-refactor/client-server/wh_test_crypto_slhdsa.c
Comment thread src/wh_server_crypto.c Outdated
Comment thread src/wh_crypto.c
Comment thread wolfhsm/wh_message_crypto.h Outdated
Comment thread src/wh_server_crypto.c Outdated
Comment thread test-refactor/wh_test_list.c Outdated
@bigbrett bigbrett removed their assignment Sep 21, 2026

@Frauschi Frauschi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Two small follow-ups from the last round - neither is blocking, and the rest of what I raised looks good now.

Comment thread src/wh_server_crypto.c

if (!_IsMlKemLevelSupported((int)req.level)) {
if (seedSz > (uint32_t)(inSize -
sizeof(whMessageCrypto_SlhDsaKeyGenRequest))) {
return WH_ERROR_BADARGS;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The new wc_ForceZero(seed, seedSz) covers the unsupported-param and wc_SlhDsaKey_Init failures as well as the post-keygen path, but this bounds rejection returns above all of it, so a rejected request still leaves the client's seed bytes in the comm buffer.

seedSz is the value being rejected here, so it cannot be the length to scrub - it would run past the request. inSize - sizeof(whMessageCrypto_SlhDsaKeyGenRequest) is what is actually there.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added

Comment thread src/wh_client_crypto.c Outdated
pub->devId = WH_CLIENT_DEVID(ctx);
}
else if (committed && !WH_KEYID_ISERASED(*inout_key_id)) {
/* The server committed a key but the best-effort export returned no

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This block and its twin in wh_Client_SlhDsaMakeCacheKeyDma (line 12337) both run to eight lines, and most of it is arguing the alternative that was not taken. That shape has been getting marked as slop in review lately, and I only asked for one line on the DMA side.

One sentence naming the constraint is enough, e.g. /* Gated on the commit latch: the response-frame check also reports ABORTED, before any key id has been read. */ - the reasoning behind it reads better in the commit message, where it will not go stale.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Cleaned up

@Frauschi Frauschi removed their assignment Sep 22, 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.

4 participants