Conversation
wc_SlhDsaKey_SignWithRandom() rejected msg == NULL for any length, so it and wc_SlhDsaKey_SignDeterministic() returned BAD_FUNC_ARG for an empty message passed as (NULL, 0), unlike wc_SlhDsaKey_Sign() and Verify(). Use the same check as Sign() and, like Sign(), replace a NULL message with a one-byte static stand-in before the crypto callback dispatch. Update the doxygen and source comments, and add tests for the (NULL, 0) case.
|
Can one of the admins verify this patch? |
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The implementation safely aligns API behavior, callback handling, tests, and documentation without unresolved issues.
Review effort: Balanced
Findings: None
What changed in this PR
Enables SLH-DSA randomized and deterministic signing APIs to accept empty messages as (NULL, 0), aligning them with existing sign/verify behavior.
Changes:
- Permits and safely canonicalizes
(NULL, 0)messages before callback dispatch. - Adds round-trip and argument-validation coverage.
- Updates public and source documentation.
| File | Description |
|---|---|
wolfcrypt/src/wc_slhdsa.c |
Updates validation and empty-message handling. |
wolfcrypt/test/test.c |
Adds deterministic empty-message round-trip coverage. |
tests/api/test_slhdsa.c |
Tests argument-check behavior for (NULL, 0). |
doc/dox_comments/header_files/wc_slhdsa.h |
Documents accepted empty-message semantics. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Commit 916de9c (#11381) made the sign and verify entry points accept an empty message passed as (NULL, 0). #11055, merged after it, added crypto callback support to wc_SlhDsaKey_SignWithRandom() together with an argument check of its own, and that check rejects msg == NULL for any length. As a result, wc_SlhDsaKey_SignWithRandom() and wc_SlhDsaKey_SignDeterministic(), which calls it, return BAD_FUNC_ARG for (NULL, 0), while wc_SlhDsaKey_Sign() and wc_SlhDsaKey_Verify() accept it. Both commits are in v5.9.4-stable.
This uses the same check as wc_SlhDsaKey_Sign(), so a NULL msg is rejected only when msgSz is not 0. As in Sign() and Verify(), a NULL message is then replaced with a one-byte static stand-in before the crypto callback dispatch, so devices and the hash code never see a NULL pointer. The stand-in is a one-element array to match the Coverity ARRAY_VS_SINGLETON change in #11457. The doxygen for SignDeterministic, SignWithRandom, Sign and Verify, and the source comments for the first two, are updated to match.
Testing
and the same with:
Without the wc_slhdsa.c change, both new checks fail with BAD_FUNC_ARG. With it, testwolfcrypt (including the crypto callback test) and the slhdsa API group pass in both builds. Tested on macOS (arm64) with Apple clang.
Checklist