Skip to content

Avoid unnecessary stackalloc in DataProtection#66428

Merged
BrennanConroy merged 2 commits intomainfrom
brecon/alloc
Apr 24, 2026
Merged

Avoid unnecessary stackalloc in DataProtection#66428
BrennanConroy merged 2 commits intomainfrom
brecon/alloc

Conversation

@BrennanConroy
Copy link
Copy Markdown
Member

Stackalloc isn't needed since we already have an array of the correct size (the one the user passed in).

Also does some minor cleanup of the code.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the CNG CBC+HMAC authenticated encryptor to avoid allocating a stack buffer for “size query” encryption operations by reusing the caller-provided plaintext buffer, along with minor related cleanup.

Changes:

  • Refactors encrypted-size calculation to take the plaintext ArraySegment<byte> rather than just a length.
  • Updates the padding/output-size query helper to use the plaintext segment instead of stackalloc’d dummy input.

Comment thread src/DataProtection/DataProtection/src/Cng/CbcAuthenticatedEncryptor.cs Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-dataprotection Includes: DataProtection

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants