-
Notifications
You must be signed in to change notification settings - Fork 10.5k
DataProtection use built in AesGcm where available #29814
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
Conversation
|
@GrabYourPitchforks for the crypto @dotnet/aspnet-build for adding a new algorithms dependency, @dotnet/aspnet-blazor-eng for fyi/review |
src/DataProtection/DataProtection/src/Cng/GcmAuthenticatedEncryptor.cs
Outdated
Show resolved
Hide resolved
src/DataProtection/DataProtection/src/Cng/GcmAuthenticatedEncryptor.cs
Outdated
Show resolved
Hide resolved
| bytesA = new ReadOnlySpan<byte>(bufA, byteCount); | ||
| bytesB = new ReadOnlySpan<byte>(bufB, byteCount); | ||
| } | ||
| return CryptographicOperations.FixedTimeEquals(bytesA, bytesB); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
There are a bunch of places in data protection where we could leverage new primitives introduced to the framework in the past few releases. Might be interesting to have an issue for that. Identity likely can also benefit from it.
Co-authored-by: Pranav K <[email protected]>
Co-authored-by: Pranav K <[email protected]>
src/DataProtection/DataProtection/src/Cng/GcmAuthenticatedEncryptor.cs
Outdated
Show resolved
Hide resolved
src/DataProtection/DataProtection/src/Managed/AesGcmAuthenticatedEncryptor.cs
Outdated
Show resolved
Hide resolved
|
@GrabYourPitchforks when you get a chance could you review the new managed implementation and the test I added to make sure it looks legit? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only thing that really needs fixed is the comment on AuthenticatedEncryptorDescriptorTests.cs. Approved once that's done. Everything else is at your discretion.
Thanks for getting to this! 👍
| Assert(countA == countB, "countA == countB"); | ||
|
|
||
| #if NETCOREAPP | ||
| unsafe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extreme nits: No need to use unsafe here. If desired, you can also put the NoInlining | NoOptimization attribute within an #if !NETCOREAPP block. Maybe those can come with the spanification PR so as not to cause noise here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will address this in the span PR
src/DataProtection/DataProtection/src/AuthenticatedEncryption/AuthenticatedEncryptorFactory.cs
Outdated
Show resolved
Hide resolved
...ion/test/AuthenticatedEncryption/ConfigurationModel/AuthenticatedEncryptorDescriptorTests.cs
Outdated
Show resolved
Hide resolved
src/DataProtection/DataProtection/src/Managed/AesGcmAuthenticatedEncryptor.cs
Show resolved
Hide resolved
src/DataProtection/DataProtection/src/Managed/AesGcmAuthenticatedEncryptor.cs
Show resolved
Hide resolved
src/DataProtection/DataProtection/src/Managed/AesGcmAuthenticatedEncryptor.cs
Outdated
Show resolved
Hide resolved
src/DataProtection/DataProtection/src/Managed/AesGcmAuthenticatedEncryptor.cs
Outdated
Show resolved
Hide resolved
src/DataProtection/DataProtection/src/Managed/AesGcmAuthenticatedEncryptor.cs
Outdated
Show resolved
Hide resolved
src/DataProtection/DataProtection/src/Managed/AesGcmAuthenticatedEncryptor.cs
Outdated
Show resolved
Hide resolved
src/DataProtection/DataProtection/src/Managed/AesGcmAuthenticatedEncryptor.cs
Outdated
Show resolved
Hide resolved
|
|
||
| // Use the KDF to generate a new symmetric block cipher key | ||
| // We'll need a temporary buffer to hold the symmetric encryption subkey | ||
| var decryptedKdk = new byte[_keyDerivationKey.Length]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@GrabYourPitchforks would it be unwise to use the shared ArrayPool here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Going to merge this as is, can make this switch in the follow up / spanification PR if needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, because it's a cryptographic secret. Within the runtime, our crypto libraries use an internal CryptoPool type instead of the public singleton ArrayPool<T>.Shared instance.
During the spanification work, this can be switched to using stackalloc (the common case) or the pinned object heap. Then no pooling will be needed at all.
…tedEncryptor.cs Co-authored-by: Pranav K <[email protected]>
|
I finished reviewing again through the commit a752598 and everything looks great. Thanks so much Hao! |
|
Hi @GrabYourPitchforks. It looks like you just commented on a closed PR. The team will most probably miss it. If you'd like to bring something important up to their attention, consider filing a new issue and add enough details to build context. |
Fixes #20689
Use new framework crypto apis now that they are available, this enable these apis on non windows for non net461/netcore2.