Skip to content

Conversation

@vcsjones
Copy link
Member

@vcsjones vcsjones commented May 7, 2021

This addresses one issue with how zero padding is handled and another theoretical one.

The first is performance. When applying zero padding, we were clearing the entire destination, then copying the plaintext over it. We were zeroing more data than required, the only data that needed to be zeroed is where the zero padding is applied.

The second is in the case of overlapping buffers for the plaintext and ciphertext. However, this cannot happen currently since we always ensure the destination buffer does not overlap the input buffer. If overlapping is permitted in a future change, this would clear the plaintext, not just where padding is required.

Contributes to #2406


I'm submitting this separately from the upcoming one-shot PR since that PR is getting fairly large and this is not immediately related to the one-shot APIs, but is adjacent.

This addresses two issues with how zero padding is handled.

The first is performance. When applying zero padding, we were clearing
the entire destination, then copying the plaintext over it. We were
zeroing more data than required, the only data that needed to be zeroed
is where the zero padding is applied.

The second is in the case of overlapping buffers for the plaintext
and ciphertext. However, this cannot happen currently since we always
ensure the destination buffer does not overlap the input buffer.
If overlapping is permitted in a future change, this would clear the
plaintext, not just where padding is required.
@ghost
Copy link

ghost commented May 7, 2021

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

@ghost
Copy link

ghost commented May 7, 2021

Tagging subscribers to this area: @bartonjs, @vcsjones, @krwq, @GrabYourPitchforks
See info in area-owners.md if you want to be subscribed.

Issue Details

This addresses one issue with how zero padding is handled and another theoretical one.

The first is performance. When applying zero padding, we were clearing the entire destination, then copying the plaintext over it. We were zeroing more data than required, the only data that needed to be zeroed is where the zero padding is applied.

The second is in the case of overlapping buffers for the plaintext and ciphertext. However, this cannot happen currently since we always ensure the destination buffer does not overlap the input buffer. If overlapping is permitted in a future change, this would clear the plaintext, not just where padding is required.

Contributes to #2406


I'm submitting this separately from the upcoming one-shot PR since that PR is getting fairly large and this is not immediately related to the one-shot APIs, but is adjacent.

Author: vcsjones
Assignees: -
Labels:

area-System.Security

Milestone: -

@vcsjones
Copy link
Member Author

vcsjones commented May 7, 2021

Just to be clear: nothing is "broken" right now. As-is, this is a performance improvement. But it will be more important for the one-shot APIs.

@bartonjs bartonjs merged commit 74cafe7 into dotnet:main May 7, 2021
@vcsjones vcsjones deleted the 2406-fix-zero-padding branch May 7, 2021 22:58
@karelz karelz added this to the 6.0.0 milestone May 20, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Jun 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants