-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Fix re-initialization of hash objects on CNG. #62397
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
In .NET 6, we added "real" support for Initialize on hash objects. However, the Reset call would create a new hash object without the CNG "resuable" flag. This led to the HashProvider's "_reusable" field and the actual reusability of the hash instance to disagree.
|
Tagging subscribers to this area: @dotnet/area-system-security, @vcsjones, @krwq Issue DetailsIn .NET 6, we added "real" support for Initialize on hash objects. However, the Reset call would create a new hash object without the CNG "resuable" flag. This led to the HashProvider's "_reusable" field and Contributes to #61417
|
|
@bartonjs @GrabYourPitchforks this might be a reasonable candidate to backport to |
|
For sake of documenting, the test failure before the fix is applied: Failed System.Security.Cryptography.Tests.Sha1ManagedTests.Initialize_DoubleInitialize_Works [13 ms]
Error Message:
Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException : Unknown error (0xc1000008)
Stack Trace:
at Internal.Cryptography.HashProviderCng.AppendHashData(ReadOnlySpan`1 source) in D:\code\personal\runtime\src\libraries\Common\src\Internal\Cryptography\HashProviderCng.cs:line 69
at Internal.Cryptography.HashProvider.AppendHashData(Byte[] data, Int32 offset, Int32 count) in D:\code\personal\runtime\src\libraries\Common\src\Internal\Cryptography\HashProvider.cs:line 31
at System.Security.Cryptography.SHA1Managed.HashCore(Byte[] array, Int32 ibStart, Int32 cbSize) in D:\code\personal\runtime\src\libraries\System.Security.Cryptography\src\System\Security\Cryptography\SHA1Managed.cs:line 23
at System.Security.Cryptography.HashAlgorithm.TransformFinalBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount) in D:\code\personal\runtime\src\libraries\System.Security.Cryptography\src\System\Security\Cryptography\HashAlgorithm.cs:line 224
at System.Security.Cryptography.Tests.HashAlgorithmTestDriver.Initialize_DoubleInitialize_Works() in D:\code\personal\runtime\src\libraries\System.Security.Cryptography\tests\HashAlgorithmTestDriver.cs:line 509
|
|
/backport-to release/6.0 |
|
/backport to release/6.0 |
|
Started backporting to release/6.0: https://github.com/dotnet/runtime/actions/runs/1539711211 |
In .NET 6, we added real support for Initialize on hash objects, prior to that it was a no-op. However, the Reset call would create a new hash object without the CNG "resuable" flag. This led to the HashProvider's "_reusable" field and the actual reusability of the hash instance to disagree.
Contributes to #61417