-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Improve exceptions thrown by MLKem when key types aren't available. #116590
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
Tagging subscribers to this area: @dotnet/area-system-security, @bartonjs, @vcsjones |
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 enhances MLKEM error handling by throwing clearer exceptions when a key or seed isn’t available, instead of surfacing low-level errors.
- Introduces
ThrowExceptionIfNoSeed
andThrowExceptionIfNoDecapsulationKey
helpers. - Adds precondition checks before export/decapsulation operations in OpenSSL and Windows implementations.
- Supplies new localized exception messages and updates tests to expect
CryptographicException
.
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
File | Description |
---|---|
src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/MLKemOpenSsl.OpenSsl.cs | Added checks before exporting seed/decapsulation key |
src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/MLKemImplementation.OpenSsl.cs | Added availability checks before decapsulation and exports |
src/libraries/System.Security.Cryptography/src/Resources/Strings.resx | Added new messages for missing seed/decapsulation key |
src/libraries/Microsoft.Bcl.Cryptography/src/Resources/Strings.resx | Added new messages for missing seed/decapsulation key |
src/libraries/Common/tests/System/Security/Cryptography/MLKemBaseTests.cs | Switched from ThrowsAny to Throws in key-missing tests |
src/libraries/Common/src/System/Security/Cryptography/MLKemImplementation.Windows.cs | Added checks before decrypt/export operations on Windows |
src/libraries/Common/src/System/Security/Cryptography/MLKem.cs | Introduced helper methods to throw when seed/decap key are absent |
src/libraries/System.Security.Cryptography/src/Resources/Strings.resx
Outdated
Show resolved
Hide resolved
src/libraries/System.Security.Cryptography/src/Resources/Strings.resx
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Bcl.Cryptography/src/Resources/Strings.resx
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Bcl.Cryptography/src/Resources/Strings.resx
Outdated
Show resolved
Hide resolved
src/libraries/Common/src/System/Security/Cryptography/MLKemImplementation.Windows.cs
Outdated
Show resolved
Hide resolved
...raries/System.Security.Cryptography/src/System/Security/Cryptography/MLKemOpenSsl.OpenSsl.cs
Show resolved
Hide resolved
669e132
to
2122bb7
Compare
Win32 bcrypt gives us unhelpful errors for ML-KEM when certain key types are not available. For example, if you created the ML-KEM instance with an expanded decapsulation key, but you ask it for a seed. In that scenario, we are throwing an exception like:
This improves the exception to something understandable when we have enough information about the key.
Fixes #116509