Skip to content

MLKEM-768 with AWS-LC#14598

Merged
reaperhulk merged 38 commits intopyca:mainfrom
trail-of-forks:dm/mlkem-768
Apr 15, 2026
Merged

MLKEM-768 with AWS-LC#14598
reaperhulk merged 38 commits intopyca:mainfrom
trail-of-forks:dm/mlkem-768

Conversation

@DarkaMaul
Copy link
Copy Markdown
Contributor

Add the support for ML-KEM using AWS-LC as the backend.

The PR is massive (sorry), about 1000 lines, but I could not reduce it more.

It follows closely the pattern of MLDSA, with the latest changes (class cases, variant enum)

A following PR with the documentation will be opened once this one get merged.

(Note: until aws/aws-lc#3140 is fixed, we have to store the ML-KEM seed on our side)

Comment thread src/cryptography/hazmat/primitives/asymmetric/mlkem.py
Comment thread src/rust/cryptography-key-parsing/src/pkcs8.rs Outdated
Comment thread src/rust/cryptography-key-parsing/src/pkcs8.rs Outdated
Comment thread src/rust/cryptography-openssl/src/mlkem.rs Outdated
Comment thread src/rust/src/backend/mlkem.rs Outdated
Comment thread tests/hazmat/primitives/test_mlkem.py
This was referenced Apr 8, 2026
Comment thread src/rust/cryptography-key-parsing/src/lib.rs Outdated
Comment thread src/rust/src/backend/mlkem.rs Outdated
# Conflicts:
#	src/cryptography/hazmat/primitives/asymmetric/types.py
Comment thread src/rust/cryptography-openssl/src/mlkem.rs
Comment thread src/rust/src/backend/keys.rs Outdated
Comment thread src/rust/src/backend/keys.rs Outdated
Comment thread src/rust/src/backend/mlkem.rs Outdated
Comment thread tests/hazmat/primitives/test_mlkem.py
Comment thread tests/wycheproof/test_mlkem.py
Comment thread src/rust/cryptography-openssl/src/mlkem.rs Outdated
alex
alex previously approved these changes Apr 14, 2026
Copy link
Copy Markdown
Member

@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.

handful of Qs + I'd like paul's review, but I think this is basically ready

Comment thread src/cryptography/hazmat/primitives/asymmetric/mlkem.py
Comment thread src/rust/cryptography-key-parsing/src/pkcs8.rs
pub fn from_pkey<T: openssl::pkey::HasPublic>(
pkey: &openssl::pkey::PKeyRef<T>,
) -> MlKemVariant {
// AWS-LC is missing the equivalent `EVP_PKEY_pqdsa_get_type`, so we
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.

Have we filed a bug to ask for 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.

Opened as aws/aws-lc#3165

ciphertext.len(),
))?;
}
shared_secret.truncate(ss_len);
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.

Can ss_len ever not be equal to shared_secret.len()?

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 don't think so (source).

I've updated the code to use an assert like the encapsulate method instead.

Copy link
Copy Markdown
Member

@reaperhulk reaperhulk left a comment

Choose a reason for hiding this comment

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

just two small nits

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

#[pyo3::pyfunction]
fn from_mlkem768_public_bytes(data: &[u8]) -> pyo3::PyResult<MlKem768PublicKey> {
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.

The python type stub documents this as taking Buffer so this arg should be a cffibuf or we need to change the signature.

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. I also opened #14667 to fix the mldsa side.

Comment thread tests/hazmat/primitives/test_mlkem.py
DarkaMaul and others added 2 commits April 15, 2026 11:53
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@reaperhulk
Copy link
Copy Markdown
Member

ruff format needed

@reaperhulk reaperhulk enabled auto-merge (squash) April 15, 2026 16:20
@reaperhulk reaperhulk merged commit 437507d into pyca:main Apr 15, 2026
68 checks passed
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