Fix loading PKCS#3 DH parameters with privateValueLength#15045
Merged
Conversation
A PKCS#3 "DH PARAMETERS" structure may carry an optional trailing INTEGER, privateValueLength. The loader parsed every DH parameters blob with the X9.42-shaped struct (p, g, q?), so it misread privateValueLength as the subprime q. Since pyca#15016 added a check_key() validation, this now fails with "Invalid DH parameters". Route the PEM loader by tag: "DH PARAMETERS" (PKCS#3) ignores privateValueLength, while "X9.42 DH PARAMETERS" keeps q. The DER loader stays X9.42-permissive since DER carries no tag to disambiguate and the existing rfc5114 DER vectors require q to be parsed. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
reaperhulk
approved these changes
Jun 15, 2026
Member
|
I think we're going to need a backport and 49.0.1 around this, sigh. |
|
hi @reaperhulk, is there an schedule for 49.0.1 release? :D |
Member
|
There is not, but we'll likely do it this upcoming week once we know what all we want to backport. |
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.
PKCS#3
DH PARAMETERSmay carry an optional trailing INTEGER,privateValueLength. The loader parsed every DH parameters blob with the X9.42-shaped struct (p, g, q?), so it misreadprivateValueLengthas the subprimeq. Since #15016 added acheck_key()validation, loading such a file now fails withValueError: Invalid DH parameters(previously it silently exposed a bogusq).This routes the PEM loader by tag:
DH PARAMETERS(PKCS#3) parses withBasicDHParams, ignoringprivateValueLength.X9.42 DH PARAMETERSparses withDHParams, keepingq.The DER loader stays X9.42-permissive: DER carries no tag to disambiguate PKCS#3 from X9.42, and the existing
dhp_rfc5114_2.dervectors requireqto be parsed (its 224-bitqcan't fitprivateValueLength'su32).Adds a
dhp_privatevaluelength.pemvector (documented intest-vectors.rst) and a regression test.🤖 Generated with Claude Code