Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance improvements for SymmetricAlgorithm one-shots #55601

Open
1 of 3 tasks
Tracked by #64488
vcsjones opened this issue Jul 13, 2021 · 6 comments
Open
1 of 3 tasks
Tracked by #64488

Performance improvements for SymmetricAlgorithm one-shots #55601

vcsjones opened this issue Jul 13, 2021 · 6 comments
Assignees
Milestone

Comments

@vcsjones
Copy link
Member

vcsjones commented Jul 13, 2021

With #2406 merged, we got the basic API shape in and functioning. As follow up work, there are a few places we can optimize for better performance:

  • Skip the Reset after performing a one-shot operation. Since it's only used one time, there is no point of performing a reset right before it gets disposed.
  • Skip allocating an IV when possible.
    Unix and macOS don't need a copy of the IV since it's only used during initialization and their native APIs create copy themselves for internal use when performing update / final.
    Windows requires passing the IV to each call, expecting the callers to track the IV between updates. But we don't need to support transferring this between calls to update, so it can be stack allocated.
  • Cache algorithm instance handles but remain thread safe. We could store the handles in a ThreadLocal or similar.
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Jul 13, 2021
@dotnet-issue-labeler
Copy link

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

@ghost
Copy link

ghost commented Jul 13, 2021

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

Issue Details

With #2406 merged, we got the basic API shape in and functioning. As follow up work, there are a few places we can optimize for better performance:

  • Skip the Reset after performing a one-shot operation. Since it's only used one time, there is no point of performing a reset right before it gets disposed.
  • Skip allocating an IV when possible.
    Unix and macOS don't need a copy of the IV since it's only used during initialization and their native APIs create copy themselves for internal use when performing update / final.
    Windows requires passing the IV to each call, expecting the callers to track the IV between updates. But we don't need to support transferring this between calls to update, so it can be stack allocated.
Author: vcsjones
Assignees: -
Labels:

area-System.Security, untriaged

Milestone: -

@vcsjones
Copy link
Member Author

Much of this was already done in #55090 already - but it's non-trivial and should be done post-6.0.

@vcsjones vcsjones self-assigned this Jul 13, 2021
@bartonjs bartonjs removed the untriaged New issue has not been triaged by the area owner label Jul 13, 2021
@bartonjs bartonjs added this to the 7.0.0 milestone Jul 13, 2021
@GSPP
Copy link

GSPP commented Aug 14, 2021

This would be appreciated by the https://github.com/gpailler/MegaApiClient project. The mega.nz file hoster uses a custom encryption system based on chained AES calls. No existing mode can do that. So for each block, there needs to be an ECB call. This leads to a very chatty API use with lots of overhead.

This Mega client library is used by the popular https://github.com/duplicati/duplicati project. It's a client-side encrypted backup solution.

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Aug 27, 2021
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Sep 8, 2021
@bartonjs
Copy link
Member

@vcsjones Checked the boxes at the top that I think are done now. Uncheck them if you disagree, of course 😄.

@magole
Copy link

magole commented Mar 10, 2022

@vcsjones for the item:

Cache algorithm instance handles but remain thread safe. We could store the handles in a ThreadLocal or similar.

maybe worth checking if BCryptDuplicateKey can be used on an already imported key.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants