-
Notifications
You must be signed in to change notification settings - Fork 5k
Add SymmetricAlgorithm.SetKey(ROSpan) #113146
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
Note regarding the
|
1 similar comment
Note regarding the
|
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.
PR Overview
This pull request introduces a new SetKey(ReadOnlySpan key) API for symmetric algorithms. It refactors key management by using a FixedMemoryKeyBox in implementations such as AES and AppleCCCryptor, and it updates tests across AES, RC2, DES, TripleDES, and one-shot paths to verify the new SetKey functionality.
Reviewed Changes
File | Description |
---|---|
src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/AES/AesContractTests.cs | Adds tests checking behavior when setting the key via property assignment and SetKey. |
src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RC2/RC2CipherTests.cs | Introduces SetKey_Sanity tests to verify key exchange between instances. |
src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/DES/DESCipherTests.cs | Updates tests to use SetKey for ensuring consistency of key and IV handling. |
src/libraries/System/Security/Cryptography/src/System/Security/Cryptography/AesImplementation.cs | Refactors key handling with FixedMemoryKeyBox support and overrides Key, KeySize and GenerateKey. |
src/libraries/System/Security/Cryptography/src/System/Security/Cryptography/AppleCCCryptor.cs | Upgrades key storage to use FixedMemoryKeyBox and disposes the key in Dispose. |
Other files (AesImplementation.OpenSsl.cs, AesImplementation.Windows.cs, ref/System.Security.Cryptography.cs, etc.) | Update API definitions and implementations to support SetKey overload with ReadOnlySpan. |
Copilot reviewed 25 out of 25 changed files in this pull request and generated no comments.
This change adds SymmetricAlgorithm.SetKey to set the key of an instance based on a ReadOnlySpan.
The AesImplementation type takes advantage of it by moving the key to a FixedMemoryKeyBox. None of the other algorithms are being changed at this time, mostly because no one should be using them.
AesCng could also change to using FixedMemoryKeyBox, but it's a non-trivial change due to the externalization of state into the CngSymmetricAlgorithmCore struct; and the main intended purpose for the AesCng type is to open a persisted key (where the change wouldn't matter).
Fixes #111154.