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

Remove an allocation during RSA key generation #69024

Merged
merged 2 commits into from
May 9, 2022

Conversation

vcsjones
Copy link
Member

@vcsjones vcsjones commented May 8, 2022

When generating an RSA key, we are creating a CngProperty. Since CngProperty always created a defensive copy of data, this adds an internal constructor that accepts a ReadOnlySpan<byte> and copies it, with the added benefit that the source doesn't have to be a byte[] already.

So this effectively changes a new byte[4] to a stackalloc byte[4].

This also removes a full null checks that were not required.

@ghost
Copy link

ghost commented May 8, 2022

Tagging subscribers to this area: @dotnet/area-system-security, @vcsjones
See info in area-owners.md if you want to be subscribed.

Issue Details

When generating an RSA key, we are creating a CngProperty. Since CngProperty always created a defensive copy of data, this adds an internal constructor that accepts a ReadOnlySpan<byte> and copies it, with the added benefit that the source doesn't have to be a byte[] already.

So this effectively changes a new byte[4] to a stackalloc byte[4].

Author: vcsjones
Assignees: vcsjones
Labels:

area-System.Security

Milestone: -

Co-authored-by: Theodore Tsirpanis <teo@tsirpanis.gr>
@bartonjs bartonjs merged commit be20c44 into dotnet:main May 9, 2022
@vcsjones vcsjones deleted the cng-alg-alloc branch May 9, 2022 15:43
@ghost ghost locked as resolved and limited conversation to collaborators Jun 8, 2022
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.

None yet

5 participants