Key state consistency in PQDSA_KEY setter functions#3040
Open
Key state consistency in PQDSA_KEY setter functions#3040
Conversation
dkostic
approved these changes
Feb 24, 2026
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3040 +/- ##
==========================================
+ Coverage 78.35% 78.51% +0.16%
==========================================
Files 689 689
Lines 121010 121015 +5
Branches 16992 16998 +6
==========================================
+ Hits 94813 95019 +206
+ Misses 25302 25097 -205
- Partials 895 899 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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 of changes:
The
PQDSA_KEYsetter functions could leave the key structure in an inconsistent state where stale fields no longer corresponded to the current key material.PQDSA_KEY_set_raw_private_key: Did not clearkey->seedon success. If the key previously held a seed (or had an uninitialized seed buffer fromPQDSA_KEY_init),pqdsa_priv_encodewould serialize stale or uninitialized seed bytes, since it gates onkey->seed != NULL.PQDSA_KEY_init: UsedOPENSSL_malloc(uninitialized) for all three buffers. Changed toOPENSSL_zallocas a defense-in-depth measure.PQDSA_KEY_get0_dsa: Added a NULL check on the input, consistent with other functions in this file.Call-outs:
The primary fix is in
PQDSA_KEY_set_raw_private_key. Current code paths through the public API are not affected becauseEVP_PKEY_pqdsa_set_paramsusesPQDSA_KEY_new(which zero-initializes all fields), but these functions are exposed viainternal.hand the inconsistency could be triggered by internal callers.Separately,
pqdsa_priv_decodecurrently ignores thepubkeyparameter fromOneAsymmetricKey, unlike the Ed25519 implementation which validates the provided public key against the derived one. This could be addressed as a follow-up.Testing:
All existing ML-DSA/PQDSA tests pass (76 tests).
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.