[WIP]: Managed HPKE - #133804
Conversation
Add HPKE algorithm identifiers, suite validation and equality, shared tests, and Microsoft.Bcl.Cryptography support. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 438fb068-aa8f-4969-9e8c-7065b52b74b5
Add KEM, KDF, and AEAD metadata, expose suite sizes and names, implement ciphertext length calculation, and extend shared public API tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 438fb068-aa8f-4969-9e8c-7065b52b74b5
Add the initial Hpke API, managed algorithm support metadata, deterministic DHKEM key derivation and adapters for NIST curves and X25519. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 438fb068-aa8f-4969-9e8c-7065b52b74b5
Move the base, ECDH, and X25519 KEM adapters into grouped source files and apply curve-specific candidate masking for deterministic scalar derivation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 438fb068-aa8f-4969-9e8c-7065b52b74b5
Implement random and deterministic HPKE key creation, resource ownership, reference declarations, and known-answer tests for DHKEM P-256, P-384, and X25519. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 438fb068-aa8f-4969-9e8c-7065b52b74b5
Forward private-key export through the KEM adapters, clear temporary secret buffers, and add public export coverage. Centralize factory support guards in Hpke while retaining backend-specific support queries. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 438fb068-aa8f-4969-9e8c-7065b52b74b5
Expose public-key export through the KEM adapters, update reference declarations and tests, and clarify decapsulation-key export documentation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 438fb068-aa8f-4969-9e8c-7065b52b74b5
Add public Seal scaffolding, KDF info-length validation, an AES-GCM adapter, and unsupported-platform dispatch. This is an intentionally incomplete, non-building checkpoint; SealCore remains unimplemented. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 438fb068-aa8f-4969-9e8c-7065b52b74b5
Implement DHKEM encapsulation, HKDF and SHAKE key schedules, and the ChaCha20-Poly1305 adapter. Centralize suite IDs and KEM labels, correct PRK slicing, and update Seal reference declarations. SealCore remains unimplemented. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 438fb068-aa8f-4969-9e8c-7065b52b74b5
Connect KEM encapsulation, the Base-mode key schedule, and AEAD encryption, and split the AEAD adapters into their own files. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 438fb068-aa8f-4969-9e8c-7065b52b74b5
Replace fixed-size crypto pool leases with bounded stack allocations and explicit secret clearing. Retain conditional pooling for variable-length KDF inputs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 438fb068-aa8f-4969-9e8c-7065b52b74b5
Add the approved Open APIs, DHKEM decapsulation, Base-mode authenticated decryption, and reference declarations. Cover known-answer vectors, round trips, input validation, and authentication failures. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 438fb068-aa8f-4969-9e8c-7065b52b74b5
Add the approved multi-shot base APIs, shared exporter limits, and CreateSender wrappers with managed and unsupported backend stubs. Include reference declarations and public wrapper coverage. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 438fb068-aa8f-4969-9e8c-7065b52b74b5
Initialize sender contexts with fresh encapsulation and Base-mode secrets. Add sequence-derived nonces, exhaustion checks, AEAD ownership and cleanup, and public factory and lifetime coverage. Leave secret export unimplemented. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 438fb068-aa8f-4969-9e8c-7065b52b74b5
Add approved CreateRecipient APIs and Base-mode recipient setup with sequence-derived nonces, authentication-failure recovery, and resource cleanup. Cover published multi-message vectors, validation, ordering and independent lifetimes. Leave secret export unimplemented. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 438fb068-aa8f-4969-9e8c-7065b52b74b5
Add approved PSK factories with a 32-byte minimum key length, nonempty identifiers, and KDF-specific input limits. Share Base and PSK context setup and cover published vectors, mode separation, authentication failures, and independent lifetimes. Leave secret export unimplemented. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 438fb068-aa8f-4969-9e8c-7065b52b74b5
Add the approved KEM identifier, metadata, HKDF-SHA512 mapping, and P-521 scalar derivation. Increase bounded stack buffers and extend public coverage with published key and Base/PSK ciphertext vectors. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 438fb068-aa8f-4969-9e8c-7065b52b74b5
Retain exporter secrets in fixed native memory and use the new span-capable UseKey overload for reference-protected exports. Remove nonce-only zeroing while preserving secret cleanup, and cover Base/PSK exporter vectors, length limits, sequencing and lifetimes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 438fb068-aa8f-4969-9e8c-7065b52b74b5
Add approved encapsulation and decapsulation key import overloads with NIST scalar validation, raw X25519 import, and exception-safe adapter ownership. Cover known-answer keys, malformed input, public-only operations, and imported key lifetimes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 438fb068-aa8f-4969-9e8c-7065b52b74b5
Guard the entire stateful SealCore operation with ConcurrencyBlock to prevent silent nonce reuse while preserving success-only sequence advancement. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 438fb068-aa8f-4969-9e8c-7065b52b74b5
Reject input/output and output/output overlap before sender core operations while permitting read-only input aliasing. Document overlapping-buffer exceptions and cover rejection before mutation and adjacent buffer handling. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 438fb068-aa8f-4969-9e8c-7065b52b74b5
Document allocating Seal overloads and SealCore, and align buffer-length exception documentation with Open. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 438fb068-aa8f-4969-9e8c-7065b52b74b5
Forward all HPKE types on .NET 11, use the unsupported implementation on .NET Framework, and omit HPKE from .NET 10 and .NET Standard. Add required resources and restrict the HashCode dependency to the Framework HPKE build. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 438fb068-aa8f-4969-9e8c-7065b52b74b5
Reject plaintext/input and exporter-context/destination overlap in public span overloads before invoking core operations. Document overlapping-buffer exceptions and cover rejection without mutation, empty spans and adjacent buffers. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 438fb068-aa8f-4969-9e8c-7065b52b74b5
Validate arguments before disposal checks. Use bounded stack storage with allocation fallbacks for nonsecret KDF context buffers, retaining pooled handling for secret material. Cover disposed-input validation and the labeled-info stack threshold. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 438fb068-aa8f-4969-9e8c-7065b52b74b5
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 438fb068-aa8f-4969-9e8c-7065b52b74b5
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 438fb068-aa8f-4969-9e8c-7065b52b74b5
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 438fb068-aa8f-4969-9e8c-7065b52b74b5
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 438fb068-aa8f-4969-9e8c-7065b52b74b5
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 438fb068-aa8f-4969-9e8c-7065b52b74b5
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 438fb068-aa8f-4969-9e8c-7065b52b74b5
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 438fb068-aa8f-4969-9e8c-7065b52b74b5
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 438fb068-aa8f-4969-9e8c-7065b52b74b5
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 438fb068-aa8f-4969-9e8c-7065b52b74b5
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 438fb068-aa8f-4969-9e8c-7065b52b74b5
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 438fb068-aa8f-4969-9e8c-7065b52b74b5
Replace legacy functional tests with shared corpus-driven coverage and simplify HPKE API documentation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 438fb068-aa8f-4969-9e8c-7065b52b74b5
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 438fb068-aa8f-4969-9e8c-7065b52b74b5
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 438fb068-aa8f-4969-9e8c-7065b52b74b5
Move static validation and unsupported-factory checks into shared fixtures, split null-argument and import-size tests, and share KEM test data. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 438fb068-aa8f-4969-9e8c-7065b52b74b5
Split export contract tests by key type and unroll invalid buffer-size checks. Exclude managed KEM adapters and AEAD support metadata from browser compilation, remove obsolete ECDH suppressions, and narrow the remaining AEAD pragmas. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 438fb068-aa8f-4969-9e8c-7065b52b74b5
|
Azure Pipelines: Successfully started running 4 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to this area: @bartonjs, @vcsjones, @dotnet/area-system-security |
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Diagnostics.CodeAnalysis; |
There was a problem hiding this comment.
Should these files rather live under System.Security.Cryprography?
Reshipping the implementation in the legacy Microsoft.Bcl.* package should not be a reason to move it under common.
I see we are inconsistent here. I think https://github.com/dotnet/runtime/blob/main/src/libraries/Microsoft.Bcl.AsyncInterfaces/src/Microsoft.Bcl.AsyncInterfaces.csproj or https://github.com/dotnet/runtime/blob/main/src/libraries/Microsoft.Bcl.Memory/src/Microsoft.Bcl.Memory.csproj are the right patterns to follow.
There was a problem hiding this comment.
Not always, I'll defer to @bartonjs if we want to try organizing our source different. It's a big departure from how we organize cryptography. We rely very heavily on partials. We don't have all the piece of HPKE in this PR so it's a bit "forward looking" here but usually the structure ends up being
- Common/Hpke.cs
- System.Security.Cryptography/src/Hpke.cs
- Microsoft.Bcl.Cryptography/src/Hpke.cs
Because we use very different implementations between M.B.C. and S.S.C.
There was a problem hiding this comment.
We rely very heavily on partials
Libraries depend heavily on partials. Partials are not a problem.
https://github.com/dotnet/runtime/blob/main/docs/coding-guidelines/project-guidelines.md#code-file-naming-conventions suggests using file name suffix for configuration specific slices of the partials, e.g. .netframework.cs, .downlevel.cs, .netcore.cs/.net.cs.
This is the first commit for HPKE support.