Skip to content

Implement AES-KW - #132349

Merged
vcsjones merged 8 commits into
dotnet:mainfrom
vcsjones:vcsjones/aes-kw
Aug 18, 2026
Merged

vcsjones merged 8 commits into
dotnet:mainfrom
vcsjones:vcsjones/aes-kw

Conversation

@vcsjones

Copy link
Copy Markdown
Member

This implements AES-KW.

  1. protected virtual's implementation is built using the existing AES-KW wrapping methods, which is built on top of AES-ECB.
  2. The Apple implementation overrides it and uses CryptoKit, when available. That is macOS 12+ and iOS / tvOS 15+. For macOS, all supported versions can use the CryptoKit implementation. For iOS 13-14, the base managed implementation is used as a fallback. Otherwise CryptoKit is used.
  3. OpenSSL uses the OpenSSL implementation, which is present on all supported OpenSSL. This re-uses much of the OpenSSL implementation as we did for AES-KWP. Given the difficulties we had getting that working I am inclined to use as much of the existing functionality there as possible.

Windows has no native implementation currently so it uses the managed implementation.

The diff for this is a tad yucky. AesKeyWrapTests.cs got renamed to AesKeyWrapPaddedTests.cs, and the AesKeyWrapTests.cs became the file with the unpadded variant. Open to suggestions to make this less blah.

Closes #130490

@vcsjones
vcsjones requested a review from bartonjs August 14, 2026 23:57
@vcsjones vcsjones self-assigned this Aug 14, 2026
Copilot AI lite review requested due to automatic review settings August 14, 2026 23:57
@vcsjones vcsjones added area-System.Security cryptographic-docs-impact Issues impacting cryptographic docs. Cleared and reused after documentation is updated each release. labels Aug 14, 2026
@vcsjones
vcsjones temporarily deployed to copilot-pat-pool August 14, 2026 23:57 — with GitHub Actions Inactive
@vcsjones
vcsjones temporarily deployed to copilot-pat-pool August 14, 2026 23:58 — with GitHub Actions Inactive
@azure-pipelines

Copy link
Copy Markdown
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.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 (and GetKeyWrapLength) 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

Copilot AI review requested due to automatic review settings August 18, 2026 01:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review details

  • Files reviewed: 19/19 changed files
  • Comments generated: 2
  • Review effort level: Lite

Copilot AI review requested due to automatic review settings August 18, 2026 01:21
Copilot stopped reviewing on behalf of vcsjones due to an error August 18, 2026 01:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review details

  • Files reviewed: 19/19 changed files
  • Comments generated: 3
  • Review effort level: Lite

@vcsjones

Copy link
Copy Markdown
Member Author

/ba-g failure is #132336

@vcsjones
vcsjones merged commit 300d7e7 into dotnet:main Aug 18, 2026
89 of 92 checks passed
@vcsjones
vcsjones deleted the vcsjones/aes-kw branch August 18, 2026 08:17
@bartonjs

Copy link
Copy Markdown
Member

/backport to release/11.0-rc1

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/11.0-rc1 (link to workflow run)

@github-actions github-actions Bot mentioned this pull request Aug 18, 2026
2 of 4 tasks
artl93 pushed a commit that referenced this pull request Aug 19, 2026
Backport of #132349 to release/11.0-rc1

/cc @bartonjs @vcsjones

## Customer Impact

- [ ] Customer reported
- [x] Found internally

This adds support for the AES-KW (vs the already added AES-KWP)
algorithm to the release. The algorithm support was requested on behalf
of JOSE libraries (such as (non-BCL) System.IdentityModel.Tokens.Jwt).
This also supports some future PQC functionality for ML-KEM in Enveloped
CMS.

## Regression

- [ ] Yes
- [x] No

New functionality only.

## Testing

Extensive unit tests from RFC test vectors are included. 

## Risk

Low. This is new API only and makes no functional changes to existing
APIs.

Co-authored-by: Kevin Jones <kevin@vcsjones.com>
Copilot-Session: 6b1cb57e-d970-404f-b8c6-c23af8d8910d
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Aug 21, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 20, 2026
@bartonjs bartonjs added the tracking This issue is tracking the completion of other related issues. label Oct 23, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.Security cryptographic-docs-impact Issues impacting cryptographic docs. Cleared and reused after documentation is updated each release. tracking This issue is tracking the completion of other related issues.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add RFC3394 KeyWrap

3 participants