Implement AES-KW - #132349
Open
vcsjones wants to merge 7 commits into
Open
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 6b1cb57e-d970-404f-b8c6-c23af8d8910d
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @bartonjs, @vcsjones, @dotnet/area-system-security |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds support for RFC 3394 AES Key Wrap (AES-KW) to System.Security.Cryptography.Aes, including managed fallback logic plus platform-specific acceleration on Apple (CryptoKit) and OpenSSL, along with updated/expanded test coverage and known-answer vectors.
Changes:
- Introduces new
Aes.EncryptKeyWrap*/Aes.DecryptKeyWrap*APIs (andGetKeyWrapLength) and a managed RFC3394 implementation path. - Wires up native support for AES-KW on OpenSSL and Apple (Swift/CryptoKit + managed interop).
- Splits padded vs unpadded test coverage into separate files and adds RFC 3394 KATs + tamper/validation tests.
Show a summary per file
| File | Description |
|---|---|
| src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/Aes.cs | Adds RFC3394 public API surface and managed core implementation. |
| src/libraries/System.Security.Cryptography/ref/System.Security.Cryptography.cs | Declares the new public Aes AES-KW APIs in the reference contract. |
| src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesImplementation.OpenSsl.cs | Implements AES-KW via OpenSSL EVP wrap ciphers. |
| src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesImplementation.Apple.cs | Implements AES-KW via CryptoKit when available; falls back to base implementation otherwise. |
| src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EVP.Cipher.cs | Adds P/Invokes for EVP AES wrap (unpadded) ciphers. |
| src/native/libs/System.Security.Cryptography.Native/pal_evp_cipher.h | Declares new native exports for EVP AES wrap (unpadded) ciphers. |
| src/native/libs/System.Security.Cryptography.Native/pal_evp_cipher.c | Implements new native exports for EVP AES wrap (unpadded) ciphers. |
| src/native/libs/System.Security.Cryptography.Native/opensslshim.h | Adds required OpenSSL symbols for EVP AES wrap (unpadded). |
| src/native/libs/System.Security.Cryptography.Native/entrypoints.c | Registers new CryptoNative entrypoints for AES wrap (unpadded). |
| src/native/libs/System.Security.Cryptography.Native.Apple/pal_swiftbindings.swift | Adds Swift-exported CryptoKit AES-KW wrap/unwrap entrypoints. |
| src/native/libs/System.Security.Cryptography.Native.Apple/pal_swiftbindings.h | Adds AppleCryptoNative symbol declarations for AES-KW entrypoints. |
| src/native/libs/System.Security.Cryptography.Native.Apple/entrypoints.c | Registers new AppleCryptoNative entrypoints for AES-KW. |
| src/libraries/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.AesKeyWrap.cs | Adds managed interop wrappers for Apple CryptoKit AES-KW entrypoints. |
| src/libraries/System.Security.Cryptography/src/System.Security.Cryptography.csproj | Includes new Apple interop source file in the library build. |
| src/libraries/System.Security.Cryptography/src/Resources/Strings.resx | Adds new resource strings for RFC3394 key wrap length validation errors. |
| src/libraries/System.Security.Cryptography/tests/System.Security.Cryptography.Tests.csproj | Includes new split test file for padded key wrap. |
| src/libraries/System.Security.Cryptography/tests/ShimHelpers.cs | Updates shim override verification to include new virtual core methods. |
| src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/AES/KeyWrapTests.cs | Converts/expands tests for unpadded RFC3394 key wrap, including KATs and tamper tests. |
| src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/AES/KeyWrapPaddedTests.cs | New file containing the padded (RFC5649) tests after rename/split. |
Review details
- Files reviewed: 19/19 changed files
- Comments generated: 2
- Review effort level: Lite
This was referenced Aug 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This implements AES-KW.
protected virtual's implementation is built using the existing AES-KW wrapping methods, which is built on top of AES-ECB.basemanaged implementation is used as a fallback. Otherwise CryptoKit is used.Windows has no native implementation currently so it uses the managed implementation.
The diff for this is a tad yucky.
AesKeyWrapTests.csgot renamed toAesKeyWrapPaddedTests.cs, and theAesKeyWrapTests.csbecame the file with the unpadded variant. Open to suggestions to make this less blah.Closes #130490