Skip to content

Add bindings for ML-DSA#2519

Open
FinnRG wants to merge 11 commits intorust-openssl:masterfrom
FinnRG:feat/ml-dsa
Open

Add bindings for ML-DSA#2519
FinnRG wants to merge 11 commits intorust-openssl:masterfrom
FinnRG:feat/ml-dsa

Conversation

@FinnRG
Copy link
Copy Markdown
Contributor

@FinnRG FinnRG commented Nov 13, 2025

Based on #2459. I addressed all review comments and refactored the key generation API.
For example pkey_ml_dsa::new_generate(variant) is now a method on PKey: PKey::generate_mldsa(variant). This is more in line with the other key types.

I had to extend openssl-sys with various new methods, because ML-DSA doesn't have a NID and needs to be handled with new methods like EVP_PKEY_new_raw_private_key_ex, EVP_PKEY_new_raw_public_key_ex and EVP_PKEY_CTX_new_from_name.

I've also added a few new tests based on boringssl test vectors.

swenson and others added 3 commits September 8, 2025 20:05
Splitting up rust-openssl#2405 into a few parts as suggest by @alex.

Adapting ML-DSA changes from rust-openssl#2405 to use the OsslParamBuilder changes
over the last few PRs and to juggle lifetimes appropriately

Co-authored-by: Jakub Jelen <jjelen@redhat.com>
Co-authored-by: Justus Winter <justus@sequoia-pgp.org>
Copy link
Copy Markdown
Collaborator

@alex alex left a comment

Choose a reason for hiding this comment

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

(I only started reviewing, didn't finish, but wanted to leave these since I won't get back to this for a bit)

Comment thread openssl-sys/src/handwritten/evp.rs
Comment thread openssl/src/pkey.rs Outdated
Comment thread openssl/src/pkey.rs
/// Creates a private key from its raw byte representation using a string keytype
#[corresponds(EVP_PKEY_new_raw_private_key)]
#[cfg(ossl300)]
pub fn private_key_from_raw_bytes_ex(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

is there anyways to consolidate this with the existing private key from bytes?

Copy link
Copy Markdown
Contributor Author

@FinnRG FinnRG Nov 15, 2025

Choose a reason for hiding this comment

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

We could refactor Id to have a string internally and then change private_key_from_raw_bytes to use the _ex method for all key types. I'm not sure if this will have larger implications though (and it would be a larger refactoring effort).

As I understand it the supported key types from private_key_from_raw_bytes_ex are a superset of private_key_from_raw_bytes.

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.

Also EVP_PKEY_new_raw_public_key_ex was only introduced in ossl300, while EVP_PKEY_new_raw_public_key exists since ossl110.

@FinnRG FinnRG requested a review from alex November 25, 2025 09:39
@FinnRG FinnRG mentioned this pull request Dec 3, 2025
@swenson
Copy link
Copy Markdown
Contributor

swenson commented Dec 30, 2025

Checking back in on this. I should have some capacity for rust-openssl now, and wanted to see if I could assist with the ML-DSA or ML-KEM work?

@FinnRG
Copy link
Copy Markdown
Contributor Author

FinnRG commented Jan 5, 2026

@swenson I have created PRs for both ML-DSA (this PR) and ML-KEM (#2532). I am just waiting for reviews.

@FinnRG
Copy link
Copy Markdown
Contributor Author

FinnRG commented Jan 8, 2026

@alex Do you have a rough estimate when you will get time to review the PR? I’m not trying to rush you, just trying to get a sense of timing so I can organize my work on pyca/cryptography.

@alex
Copy link
Copy Markdown
Collaborator

alex commented Jan 10, 2026

I do not, and I apologize for that. Very candidly the API choices and complexity that OpenSSL have introduced have really sapped my motivation to engage on this part of the codebase. Hopefully one of the other maintainers feels differently.

@swenson
Copy link
Copy Markdown
Contributor

swenson commented Jan 11, 2026

Understood. I'm not a maintainer, but I'm happy to assist if I can with reviewing or code.

@FinnRG
Copy link
Copy Markdown
Contributor Author

FinnRG commented Jan 12, 2026

That's very understandable. @botovq Would you have capacity to take a look at this PR (and potentially the #2532 PR which is very similar)?

@botovq
Copy link
Copy Markdown
Contributor

botovq commented Jan 13, 2026

I won't have time for this anytime soon, but I can try to take a look when I get some time. I should say that I'm most likely the least interested in OpenSSL 3 among the maintainers - I don't use it.

@FinnRG
Copy link
Copy Markdown
Contributor Author

FinnRG commented Jan 14, 2026

@botovq Thank you, I just pinged because you were the first maintainer I could find by looking at the recently merged PRs. If there are other maintainers (the rust-openssl member list is private) who are better suited, please feel free to redirect me to them or let me know who would be best to loop in...

@FinnRG
Copy link
Copy Markdown
Contributor Author

FinnRG commented Jan 15, 2026

@alex I just read https://cryptography.io/en/latest/statements/state-of-openssl/, which explicitly mentions ML-KEM and ML-DSA. Do you want me to close this (and the ML-KEM) PR for now?

I would also be happy to help out with any changes necessary to get these algorithms working for LibreSSL/BoringSSL/AWS-LC, if required.

@alex
Copy link
Copy Markdown
Collaborator

alex commented Jan 15, 2026

No need to close this -- hopefully it provides some color though.

(I expect we'll eventually land ML-DSA/ML-KEM for OpenSSL, but we won't block getting the other implementation on having an OpenSSL one.)

@abbra
Copy link
Copy Markdown
Contributor

abbra commented Jan 18, 2026

@alex I have over past few weeks implemented both ML-DSA and ML-KEM support for pyca based on the work of @FinnRG in this and the other PR.

@abbra
Copy link
Copy Markdown
Contributor

abbra commented Jan 20, 2026

@FinnRG, @alex: I have pushed my pyca changes that add ML-DSA, ML-KEM, and hybrid KEMs to https://github.com/abbra/cryptography/tree/abbra-add-pqc. It requires both @FinnRG pull requests to rust-openssl to build.

Let me know if I should open a PR to https://github.com/pyca/cryptography or it should wait until these two PRs merged to rust-openssl.

@abbra
Copy link
Copy Markdown
Contributor

abbra commented Jan 20, 2026

I also pushed a generated documentation to https://abbra.fedorapeople.org/.draft/pyca-pqc/hazmat/primitives/asymmetric/mldsa44.html

@abbra
Copy link
Copy Markdown
Contributor

abbra commented Jan 21, 2026

Here is an upstream CI workflow running: https://github.com/abbra/cryptography/actions/runs/21213933260. It is mostly green, except documentation spell-checking which cannot handle encapsulate/decapsulate. And there is a bug in Windows openssl binary as it is misconfigured and cannot read files.

Comment thread openssl/src/pkey.rs
Comment on lines +237 to +238
fn is_key_type(&self, key_type: &str) -> Result<bool, ErrorStack> {
let key_type = CString::new(key_type).unwrap();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Any reason to not take &CStr and avoid an allocation?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

To do this neatly and consistently is a bigger change than it seems at first. I will have a go at it and see if the juice is worth the squeeze.

@frasertweedale
Copy link
Copy Markdown

Hi @FinnRG and all,

Based on this PR and @abbra's experimental branch, I have pushed this work a bit further including adding BoringSSL support. I am in the process of cleaning up the code and commit history and will prepare a new PR(s) soon.

Fixup commits, and in some cases more substantive commits, for the sake of clarity and ease of reviewing, will be squashed down into the relevant preceding commits. In cases where commit authorship differs, I acknowledge the contributions via Co-Authored-By: lines in the commit message. Primary authorship of smaller commits may be ceded in some cases to the author of the larger commit. I want to be transparent about this ahead of time. If you have concerns (now, or after I submit the PRs) please do not hesitate to speak up.

In line with expressed priorities of python-cryptography upstream, I also intend to reorder the work somewhat to ensure BoringSSL support comes before OpenSSL. And certainly ML-DSA before ML-KEM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants