Repository navigation
Conversation
Pkcs11GetMldsaPublicKey passes the CK_ULONG public key size to wc_MlDsaKey_ImportPubRaw, and the ML-DSA sign callback stores the CK_ULONG signature length in a word32, both without a cast. clang reports them with -Wshorten-64-to-32, which the debug build enables, so a git checkout configured with --enable-pkcs11 --enable-mldsa --enable-debug fails to build under -Werror. Cast both, as the ML-KEM and RSA code in this file does. The public key size has already been matched against the ML-DSA key sizes, and C_Sign returns at most the buffer length it was given.
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
Both conversions are bounded by existing size constraints, with no unresolved correctness issues.
No open issues 🎉
What changed in this PR
Fixes Clang narrowing-conversion errors in wolfSSL’s PKCS#11 ML-DSA callbacks.
Changes:
- Adds explicit
word32casts for public-key and signature lengths. - Preserves existing behavior under the validated size and buffer-length constraints.
| File | Description |
|---|---|
| wolfcrypt/src/wc_pkcs11.c | Casts two ML-DSA lengths to resolve -Wshorten-64-to-32 errors. |
Review effort: Balanced
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11819
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs
Coverage: 1 of 1 in-scope changed file(s) opened by the reviewer
Fenrir result: Approved ✅
No new issues found in the changed files.
Advisory only — this automated result does not count as a GitHub approval.
Review tier: Lite
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
wolfcrypt/src/wc_pkcs11.cdoes not build from a git checkout configured with--enable-pkcs11 --enable-mldsa --enable-debugusing clang.Pkcs11GetMldsaPublicKeypasses theCK_ULONGpublic key size towc_MlDsaKey_ImportPubRaw, and the ML-DSA sign callback stores theCK_ULONGsignature length in aword32, both without a cast. The debug build enables-Wshorten-64-to-32, and a git checkout adds-Werror:This change casts both, as the ML-KEM and RSA code in the same file already does. Neither cast can truncate: the public key size has already been matched against the three ML-DSA public key sizes, and
C_Signreturns at most the buffer length it was given, which came from theword32output length.Found by a new wolfPKCS11 CI job that builds wolfSSL with
--enable-pkcs11(wolfSSL/wolfPKCS11#261).Testing
--enable-cryptocb --enable-aescfb --enable-rsapss --enable-keygen --enable-pwdbased --enable-scrypt --enable-md5 --enable-debug --enable-mldsa --enable-pkcs11andC_EXTRA_FLAGS="-DWOLFSSL_PUBLIC_MP -DWC_RSA_DIRECT -DHAVE_AES_ECB -DHAVE_AES_KEYWRAP -DWOLFSSL_MLKEM_DYNAMIC_KEYS -DWOLFSSL_MLDSA_DYNAMIC_KEYS", from a git checkout so-Werroris on:make checkagainst that build passes (75 pass, 9 skip).Checklist