One-shot decrypt in to user buffers
authorKevin Jones <kevin@vcsjones.com>
Fri, 11 Mar 2022 00:17:07 +0000 (19:17 -0500)
committerGitHub <noreply@github.com>
Fri, 11 Mar 2022 00:17:07 +0000 (19:17 -0500)
commitb3e380e3e64ab740fb2745f7ae234300578d021a
tree5541aa17c89cb17ba56f6125cdbf669ade1443e6
parent4f7d9e75611ec0f051ad05e852130392de5384c2
One-shot decrypt in to user buffers

This changes the one-shot decryption to allow decrypting directly in to user-supplied buffers, even in the presence of padding, so that a copy and CryptoPool rental can be avoided.

If the buffer is large enough to accommodate the padding, then decrypt directly in to the supplied buffer, zero the padding, and indicate the de-padded amount in bytesWritten.

If the buffer is possibly large enough, then decrypt all but the last block in to the buffer, and do the last block on the stack. If the de-padded amount in the stack is small enough, then copy the remaining. If it is too large, then zero everything in the user buffer.
src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/AES/AesCipherOneShotTests.cs
src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/Symmetric/SymmetricOneShotBase.cs
src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/UniversalCryptoOneShot.cs