Skip to content

Add more robust parameter and key processing for DH, DSA, and RSA#14992

Open
sjudson wants to merge 3 commits into
pyca:mainfrom
trail-of-forks:sj/robust-processing
Open

Add more robust parameter and key processing for DH, DSA, and RSA#14992
sjudson wants to merge 3 commits into
pyca:mainfrom
trail-of-forks:sj/robust-processing

Conversation

@sjudson

@sjudson sjudson commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

This PR adds more robust parameter processing for DH and key processing for DSA and RSA. In particular:

  • existing checks on parameter and key structure (e.g., that a DH parameter set appears well-formed or that for RSA e != 1) are added to the PEM and DER load paths, alongside where they were already used for direct constructions; and
  • a new check, check_dsa_public_numbers, is added to verify that for DSA the public y value both 1 < y < p and y ** q mod p = 1, as keys failing validation may be weak to forgery.

A new batch of appropriate tests are also added, including invalid test keys.

@alex alex left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

All the new vectors need to be documented in test-vectors.rst -- please split those out into their own PR.

For ease of review, I think it'd be best to split the actual changes into one PR per algorithm.

Comment thread src/rust/src/backend/dsa.rs Outdated
}

pub(crate) fn private_key_from_pkey(
_py: pyo3::Python<'_>,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If we don't need this arg, we can just drop it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Comment thread src/rust/src/backend/rsa.rs Outdated
Comment on lines +64 to +65
let numbers = key.public_numbers(py)?;
check_public_key_components(numbers.e.bind(py), numbers.n.bind(py))?;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm, ideally we wouldn't have to round trip via the public numbers to create a public key... is there some way to structure this to avoid that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@alex thoughts on this alternative? Modifies the existing check to work on bignums as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll leave this as the RSA PR btw, and split out the DH and DSA and vectors as requested

@sjudson sjudson force-pushed the sj/robust-processing branch from 85717cf to 2c0c828 Compare June 9, 2026 18:02
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.

2 participants