X25519DiffieHellman agreement with byte-based public keys#128086
Open
vcsjones wants to merge 6 commits into
Open
X25519DiffieHellman agreement with byte-based public keys#128086vcsjones wants to merge 6 commits into
vcsjones wants to merge 6 commits into
Conversation
Contributor
|
Tagging subscribers to this area: @bartonjs, @vcsjones, @dotnet/area-system-security |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends X25519DiffieHellman with byte-based public-key key agreement APIs and wires them through the platform implementations (OpenSSL/Apple/Windows/CNG), adding native shim entrypoints where needed, plus expanded contract and functional test coverage.
Changes:
- Add
DeriveRawSecretAgreement(byte[] otherPartyPublicKey)andDeriveRawSecretAgreement(ReadOnlySpan<byte> otherPartyPublicKey, Span<byte> destination)along with a new abstractDeriveRawSecretAgreementCore(ReadOnlySpan<byte>, Span<byte>). - Implement the new core overload across OpenSSL/Apple/Windows/CNG implementations and add new native entrypoints for OpenSSL and Apple to derive directly from raw public-key bytes.
- Add/extend tests validating argument checks, disposal behavior, symmetry, vectors, and zero-shared-secret behavior for the new overloads.
Show a summary per file
| File | Description |
|---|---|
| src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X25519DiffieHellman.cs | Adds the new public overloads and new abstract core method plus length validation helper. |
| src/libraries/System.Security.Cryptography/ref/System.Security.Cryptography.cs | Updates the public ref surface to include the new overloads and abstract core method. |
| src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X25519DiffieHellmanImplementation.OpenSsl.cs | Implements the new core overload and switches fallback to the new raw-public-key interop. |
| src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X25519DiffieHellmanOpenSsl.OpenSsl.cs | Same as above for the public OpenSSL-backed type. |
| src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X25519DiffieHellmanImplementation.Apple.cs | Implements the new core overload and routes to the new Apple bytes-based interop. |
| src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X25519DiffieHellmanImplementation.Windows.cs | Implements the new core overload and refactors shared Windows derivation path. |
| src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X25519DiffieHellmanCng.Windows.cs | Implements the new core overload and factors shared public-key handling. |
| src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X25519DiffieHellmanCng.cs | Declares the new protected override in the partial type. |
| src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X25519DiffieHellmanImplementation.NotSupported.cs | Adds the new core overload stub for unsupported platforms. |
| src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X25519DiffieHellmanOpenSsl.NotSupported.cs | Adds the new core overload stub (currently throws NotImplementedException). |
| src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/Cng.NotSupported.cs | Adds the new core overload stub in the CNG PNSE implementation. |
| src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EvpPkey.X25519.cs | Adds interop for the new OpenSSL native entrypoint deriving from raw public-key bytes. |
| src/native/libs/System.Security.Cryptography.Native/pal_evp_pkey_x25519.h | Declares CryptoNative_X25519DeriveSecretAgreementWithPublicKey. |
| src/native/libs/System.Security.Cryptography.Native/pal_evp_pkey_x25519.c | Implements the new OpenSSL helper by importing the peer key and deriving. |
| src/native/libs/System.Security.Cryptography.Native/entrypoints.c | Exposes the new OpenSSL entrypoint via the resolver table. |
| src/libraries/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.X25519.cs | Adds interop for the new Apple bytes-based derivation export. |
| src/native/libs/System.Security.Cryptography.Native.Apple/pal_swiftbindings.swift | Implements AppleCryptoNative_X25519DeriveRawSecretAgreementWithBytes and shares logic via a helper. |
| src/native/libs/System.Security.Cryptography.Native.Apple/pal_swiftbindings.h | Declares the new Apple export. |
| src/native/libs/System.Security.Cryptography.Native.Apple/entrypoints.c | Exposes the new Apple export via the resolver table. |
| src/libraries/System.Security.Cryptography/tests/X25519DiffieHellmanContractTests.cs | Adds contract tests for the new overloads and adds callback plumbing for the new core method. |
| src/libraries/System.Security.Cryptography/tests/X25519DiffieHellmanBaseTests.cs | Adds functional tests covering new overloads (symmetry, vectors, public-key-only, zero-secret). |
Copilot's findings
- Files reviewed: 21/21 changed files
- Comments generated: 3
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.
Contributes to #128040.
This introduces a
DeriveRawSecretAgreementthat does key agreement with the other party's key as a sequence of bytes instead of forcing creating the instance ofX25519DiffieHellman. This reduces allocations in the typical use case of X25519.