Conversation
|
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, 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. |
|
Tagging subscribers to this area: @dotnet/area-system-security, @bartonjs, @vcsjones Issue DetailsThis implements SHAKE128 and SHAKE256. Closes #20342
|
|
/azp run runtime-extra-platforms |
|
Azure Pipelines successfully started running 1 pipeline(s). |
src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EVP.cs
Outdated
Show resolved
Hide resolved
wfurt
left a comment
There was a problem hiding this comment.
LGTM. seems like boilerplate from other algorithms for most part, right?
For the most part, yes. A lot of the hashing capabilities that were needed were already defined. The "new" things were mostly different OpenSSL APIs to deal with the final "XOF" part of the hash. |
bartonjs
left a comment
There was a problem hiding this comment.
Minor feedback, no blockers.
src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/LiteHash.Windows.cs
Show resolved
Hide resolved
src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/Shake256.cs
Show resolved
Hide resolved
src/libraries/System.Security.Cryptography/tests/ShakeTestDriver.cs
Outdated
Show resolved
Hide resolved
| int32_t ret = EVP_DigestUpdate(ctx, source, (size_t)sourceSize); | ||
|
|
||
| if (ret != SUCCESS) | ||
| { | ||
| CryptoNative_EvpMdCtxDestroy(ctx); | ||
| return 0; | ||
| } |
There was a problem hiding this comment.
On failure does the managed caller try to use GetLastError to retrieve failure information? I'm wondering if the call to CryptoNative_EvpMdCtxDestroy will overwrite any error information from the EVP_DigestUpdate call.
There was a problem hiding this comment.
OpenSSL does this a bit differently than Win32. It maintains an error queue. Successful functions don't set the last error to "no error", they just don't add anything to the queue. So EVP_DigestUpdate error is still on the queue, then when we check the return value for failed we use ERR_peek_last_error to grab the error, then ERR_clear_error to clear the queue out.
|
There are some... odd... but probably relevant failures on Mono Linux ARM64. Will dig in to that. |
|
Memory issue is a bug in OpenSSL when handling zero length digests from FinalXOF. @bartonjs extremely grateful for you catching I didn't have a test for that initially. |
…inalXOF for some architectures
|
Looking at the new tests, I don't see one like const int TestOutputSize = 23 // or whatever
someData = any non-empty dataset
shake.AppendData(someData);
byte[] save = shake.GetCurrentHash(TestOutputSize);
byte[] empty = shake.GetCurrentHash(0);
// Assert.Equal(0, empty.Length), if desired.
byte[] check = shake.GetCurrentHash(TestOutputSize);
Assert.Equal(save, check);
// Could do it again with shake.GetCurrentHash(empty), if desired
shake.GetHashAndReset(empty);;
shake.GetCurrentHash(check);
Assert.NotEqual(save, check);
Assert.Equal(TShake.HashData(ReadOnlySpan<byte>.Empty, TestOutputSize), check);
shake.AppendData(someData);
shake.GetCurrentHash(check);
Assert.Equal(save, check);Where Assert.Equal is really hexified things, the AssertExtensions.SequenceEqual version, or a new crypto helper that does SequenceEqual, then on failure does an assert of the hex versions (at least I find the hex differences, and the context around them, easier to work with than both the built-in base10/ToString array version and the base10 diff report from the sequence equal one). |
Added a test that shows GetHashAndReset resets even when asking for a zero-length hash. |
src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/Helpers.cs
Show resolved
Hide resolved
|
Timeouts are being tracked by #76454. Tests pass locally and have passed in previous runs. Merging (with 👍 from @jeffhandley) |
|
@vcsjones: Thanks a lot for your work! Linked to: |
This implements SHAKE128 and SHAKE256.
Closes #20342