-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
SP800-108 CTR HMAC #79120
SP800-108 CTR HMAC #79120
Conversation
Tagging subscribers to this area: @dotnet/area-system-security, @vcsjones Issue DetailsThis implements SP800-108 HMAC CTR as a package. It is not inboxed. Some implementation notes.
Closes #65577
|
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
Thanks. We really need a new package/assembly for this one type? We can't, for example, just squint and say it's related to hashing so it can go in System.IO.Hashing? |
There is internal (from Microsoft) interest in this capability for .NET Framework, and the API proposal suggested this as a package name.
My 2c: that's... quite a bit of a squint. That package is specifically documented as "non cryptographic hashing" in its README. This API is 1. cryptographic and 2. doesn't do hashing, strictly speaking (though the PRF is HMAC in this one case). Thinking about it more, I don't really see a good "home" for this type in an existing package, so a new package makes sense to me. Though I will defer to y'all. |
If we really lack a good existing package/assembly for it, then we should think hard about what to name this one so we don't need to create yet another the next time we need to ship another cryptographic algorithm downlevel. |
@terrajobst @bartonjs @GrabYourPitchforks do y'all have any thoughts here? Something like System.Security.Cryptography.Extensions? |
If I recall correctly, I asked that same question either on the text portion of the proposal or during the API review, and there wasn't a good answer because we didn't know what the next thing would be. We... could... do something like Because, certainly, if this wasn't going to NS2.0 it'd just be in System.Security.Cryptography.dll, and we wouldn't bother with NuGet at all. |
I would probably avoid calling anything I do have a bit of a preference for using a generic name at all. One thing I don't really want is a big invitation / debate on what should be in I think there is clear evidence that SP800108 needs to be made available in downlevel targets. What's not clear to me is why everything else couldn't argue that criteria.
It was discussed in the API review here. https://youtu.be/bDTLx5SXusY?t=5714 (1:35:20 in). My take away from that discussion a slight preference to avoid a "dumping ground" package and "fine with another one off package". |
...ography.SP800108/src/System/Security/Cryptography/SP800108HmacCounterKdfImplementationCng.cs
Outdated
Show resolved
Hide resolved
...s/System.Security.Cryptography.SP800108/src/System/Security/Cryptography/NetStandardShims.cs
Outdated
Show resolved
Hide resolved
...0108/src/System/Security/Cryptography/SP800108HmacCounterKdfImplementationCng.NetStandard.cs
Outdated
Show resolved
Hide resolved
...em.Security.Cryptography.SP800108/src/System/Security/Cryptography/SP800108HmacCounterKdf.cs
Outdated
Show resolved
Hide resolved
...em.Security.Cryptography.SP800108/src/System/Security/Cryptography/SP800108HmacCounterKdf.cs
Outdated
Show resolved
Hide resolved
...em.Security.Cryptography.SP800108/src/System/Security/Cryptography/SP800108HmacCounterKdf.cs
Outdated
Show resolved
Hide resolved
.../src/System/Security/Cryptography/SP800108HmacCounterKdfImplementationManaged.NetStandard.cs
Outdated
Show resolved
Hide resolved
...phy.SP800108/src/System/Security/Cryptography/SP800108HmacCounterKdfImplementationManaged.cs
Outdated
Show resolved
Hide resolved
I've finished review of the prod logic - haven't gotten to tests yet. Some nits, and a race condition in Thanks Kevin for getting to this! It's awesome to see it come together. :)
Your line of reasoning is valid. I'm seeing some internal requests for AES-GCM (and maybe AES-CCM?) to be made available downlevel as well since folks are clamoring for them on net4x. |
That would probably have to be Windows-only or limited to .NETFramework. Supporting a true netstandard2.0 for GCM / CCM would be a huge multiplier in complexity. |
@GrabYourPitchforks I believe I have addressed all of your feedback thus far, with most of it actioned, some of it "maybe not". I appreciate your time! |
Oh, it would definitely add complexity. But just yesterday I was in an email thread (which I think you were on as well!) where the writing on the wall looms ever larger. Fortunately that's a problem for future us and not for this PR! 🫠 |
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.
I know we've still been waiting for a re-review from @GrabYourPitchforks, but from what I can tell all previous comments have been addressed. @bartonjs, if this looks good to you, I propose we go ahead and merge this ahead of Preview 1. We can revisit the packaging topic if another idea emerges there, and if there's post-merge feedback from @GrabYourPitchforks, we can address it in a separate PR.
If we rename it, won't that mean we'll have another dead-end package on nuget forevermore? It's not the end of the world, just, not ideal. |
True. I rationalized it as: It'd only exist with Is |
My 2 cents, it's my preferred choice. |
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.
Nit-picky: It looks like we always use lower-case .netstandard.cs
and .netcoreapp.cs
throughout the repo. Can you rename those files to lowercase the suffixes please?
@bartonjs is going to re-review, so we'll give him a chance to weigh in on that again. In anticipation of that being OK, I'm tempted to get a commit ready with that restructuring. Would you like to do that, @vcsjones; or would you like me to? (Either's good with me; I have time today). |
I should be able to get that in over the next few hours. |
If we want to propose a new package name, that needs to go back to API Review. |
...em.Security.Cryptography.SP800108/src/System/Security/Cryptography/SP800108HmacCounterKdf.cs
Outdated
Show resolved
Hide resolved
Since there's active discussion about renaming it, it should go back to API Review. If this gets merged in the next couple of hours, it makes it into Preview 1... which we don't want to do if we're going to rename it literally tomorrow. So, despite having signed off on the code, marked the PR as No Merge. |
Okay. I'll address some nits but hold off on pushing the commit that does the rename until it comes back from API review. |
Significant changes from the API proposal.
12f6ec7
to
7a51f3e
Compare
@ViktorHofer added you to get input on the packaging for |
...libraries/Common/src/System/Security/Cryptography/SP800108HmacCounterKdfImplementationCng.cs
Outdated
Show resolved
Hide resolved
...aries/Common/src/System/Security/Cryptography/SP800108HmacCounterKdfImplementationManaged.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Bcl.Cryptography/ref/Microsoft.Bcl.Cryptography.csproj
Outdated
Show resolved
Hide resolved
...Cryptography/src/System/Security/Cryptography/SP800108HmacCounterKdfImplementationManaged.cs
Show resolved
Hide resolved
...tem.Security.Cryptography/src/System/Security/Cryptography/SP800108HmacCounterKdf.Windows.cs
Outdated
Show resolved
Hide resolved
@vcsjones would this be interesting to add to dotnet/core#8134? If so please consider adding today before end of day. Sorry for the late notice. |
Eh, I think it's cool, but I don't think it has broad enough appeal, and demonstrating it is tricky. |
This implements SP800-108 CTR HMAC as a package. In .NET 8, this is an inbox component. For down-level platforms,
Microsoft.Bcl.Cryptography
was introduced as a package for .NET Standard and .NET Framework.Some implementation notes.
byte[]
for inputs because ofIncrementalHash
. .NET Core prefers working with spans. Because of this, we avoid thebyte[]
APIs deferring to{ReadOnly}Span<byte>
APIs. Otherwise, we will go frombyte[]
-> span ->byte[]
. This is true not just for public APIs that accept input, but also for places we need to do conversions, like fromstring
tobyte[]
. In .NET Standard, we always rent from the pool and avoid doing work on the stack, whereas .NET Core can use the stack.ObjectDisposedException
. We get this for free with safe handles and the CNG implementation. For the managed implementation, the key is reference counted. When the reference count reaches zero, the key is zeroed and attempts to acquire the key afterward throw anObjectDisposedException
.label || 0x00 || context
. So the NIST test vectors are unusable for tests.Closes #65577