Skip to content

Add more robust parameter processing: DH#15016

Merged
reaperhulk merged 1 commit into
pyca:mainfrom
trail-of-forks:sj/robust-processing-dh
Jun 12, 2026
Merged

Add more robust parameter processing: DH#15016
reaperhulk merged 1 commit into
pyca:mainfrom
trail-of-forks:sj/robust-processing-dh

Conversation

@sjudson

@sjudson sjudson commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

This PR adds more robust key processing for DH by extending existing heuristic checks on parameter well-formedness to the PEM and DER load paths.

See #14992 and #15015 for related changes to DSA and RSA processing.

@reaperhulk reaperhulk merged commit 829520b into pyca:main Jun 12, 2026
63 checks passed
let g = utils::py_int_to_bn(py, numbers.g.bind(py))?;

let dh = openssl::dh::Dh::from_pqg(p, q, g)?;
check_dh_parameters(&dh)?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sjudson please see #15042

reaperhulk pushed a commit that referenced this pull request Jun 15, 2026
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 #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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants