Skip to content

ML-KEM: Fix checking encapsulation key size #114574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 12, 2025

Conversation

vcsjones
Copy link
Member

Looking through some coverage reports, ImportSubjectPublicKeyInfo didn't have adequate test coverage for negative test cases. This lead to the discovery that an incorrectly sized encapsulation key would make it all the way down to the native shim.

This change more eagerly rejects incorrectly sized encapsulation keys, and adds more SPKI negative test cases.

Contributes to #113508

@Copilot Copilot AI review requested due to automatic review settings April 11, 2025 21:25
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR aims to fix the encapsulation key size check in ML-KEM by rejecting keys with incorrect sizes and enhancing negative test coverage for the SPKI import functionality.

  • Added new tests in MLKemTests.cs to validate incorrect algorithm, parameters, and key sizes.
  • Updated MLKem.ImportSubjectPublicKeyInfo to throw a CryptographicException when the encapsulation key size does not match the expected length.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/libraries/Common/tests/System/Security/Cryptography/MLKemTests.cs Added tests for invalid SPKI scenarios to improve negative test coverage.
src/libraries/Common/src/System/Security/Cryptography/MLKem.cs Updated key size validation logic in the SPKI import method.

@vcsjones vcsjones added this to the 10.0.0 milestone Apr 11, 2025
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-security, @bartonjs, @vcsjones
See info in area-owners.md if you want to be subscribed.

@vcsjones vcsjones force-pushed the fix-ml-kem-spki-imports branch from 00f1e7a to 87122a7 Compare April 11, 2025 21:34
@bartonjs
Copy link
Member

The fix itself looks good, but awaiting resolution of the P8 question in case the answer to that is a large change :)

@vcsjones vcsjones merged commit 464e5fe into dotnet:main Apr 12, 2025
80 of 86 checks passed
@vcsjones vcsjones deleted the fix-ml-kem-spki-imports branch April 12, 2025 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants