Skip to content

Implement AES-KW - #132349

Open
vcsjones wants to merge 7 commits into
dotnet:mainfrom
vcsjones:vcsjones/aes-kw
Open

Implement AES-KW#132349
vcsjones wants to merge 7 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 deployed to copilot-pat-pool August 14, 2026 23:57 — with GitHub Actions Active
@vcsjones
vcsjones deployed to copilot-pat-pool August 14, 2026 23:58 — with GitHub Actions Active
@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Security cryptographic-docs-impact Issues impacting cryptographic docs. Cleared and reused after documentation is updated each release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add RFC3394 KeyWrap

2 participants