-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Conversation
There was a problem hiding this 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. |
src/libraries/Common/tests/System/Security/Cryptography/MLKemTests.cs
Outdated
Show resolved
Hide resolved
Tagging subscribers to this area: @dotnet/area-system-security, @bartonjs, @vcsjones |
00f1e7a
to
87122a7
Compare
src/libraries/Common/tests/System/Security/Cryptography/MLKemTests.cs
Outdated
Show resolved
Hide resolved
The fix itself looks good, but awaiting resolution of the P8 question in case the answer to that is a large change :) |
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