Hardening fixes for ML-DSA digest mode, XTS key comparison, and urandom fd#3129
Merged
Hardening fixes for ML-DSA digest mode, XTS key comparison, and urandom fd#3129
Conversation
nebeid
approved these changes
Mar 27, 2026
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3129 +/- ##
=======================================
Coverage 78.01% 78.01%
=======================================
Files 689 689
Lines 122406 122414 +8
Branches 17071 17086 +15
=======================================
+ Hits 95493 95500 +7
- Misses 26014 26016 +2
+ Partials 899 898 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
jakemas
approved these changes
Mar 27, 2026
| out->signature_len = MLDSA44_SIGNATURE_BYTES; | ||
| out->keygen_seed_len = MLDSA44_KEYGEN_SEED_BYTES; | ||
| out->sign_seed_len = MLDSA44_SIGNATURE_SEED_BYTES; | ||
| out->digest_len = 64; // MLDSA_CRHBYTES, unavailable here due to bcm.c undef |
Contributor
There was a problem hiding this comment.
Looks good to me. I see no need to statically assert MLDSA_CRHBYTES == 64 anywhere as this has to match the out put length of fixed shake256.
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.
Issues
Description of changes:
Several small hardening fixes:
digest_lento thePQDSAstruct and enforce that themuinput to ML-DSA sign/verify digest mode is exactlyMLDSA_CRHBYTES(64 bytes). Previously the digest-mode paths accepted anymessage_lenand passed it directly to the underlying implementation without validation.sig_lencheck from!=to<so callers providing a larger-than-needed buffer aren't rejected. This is consistent with standard OpenSSL buffer conventions.OPENSSL_memcmptoCRYPTO_memcmpto avoid timing leakage on key material.urandom_fdfrom0to-1so that any use before initialization fails withEBADFrather than silently reading from stdin.Call-outs:
The
digest_lenfield inpqdsa.cis set to the literal64rather thanMLDSA_CRHBYTESbecause the macro is not available in that translation unit (due tobcm.cundef behavior). Comments in the code explain this.Testing:
Existing test coverage for ML-DSA sign/verify, XTS, and RAND should exercise these code paths. The ML-DSA digest length checks are new validation — negative test cases that pass an incorrect
mulength could be a useful follow-up.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.