Skip to content

Conversation

@vcsjones
Copy link
Member

@vcsjones vcsjones commented Dec 4, 2021

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

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.
@ghost ghost added area-System.Security community-contribution Indicates that the PR has been added by a community member labels Dec 4, 2021
@ghost
Copy link

ghost commented Dec 4, 2021

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

Issue Details

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.

Contributes to #61417

Author: vcsjones
Assignees: -
Labels:

area-System.Security, community-contribution

Milestone: -

@vcsjones
Copy link
Member Author

vcsjones commented Dec 4, 2021

@bartonjs @GrabYourPitchforks this might be a reasonable candidate to backport to release/6.0.

@vcsjones
Copy link
Member Author

vcsjones commented Dec 4, 2021

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

@bartonjs bartonjs merged commit 85b75ba into dotnet:main Dec 4, 2021
@bartonjs
Copy link
Member

bartonjs commented Dec 4, 2021

/backport-to release/6.0

@bartonjs
Copy link
Member

bartonjs commented Dec 4, 2021

/backport to release/6.0

@github-actions
Copy link
Contributor

github-actions bot commented Dec 4, 2021

Started backporting to release/6.0: https://github.com/dotnet/runtime/actions/runs/1539711211

@vcsjones vcsjones deleted the fix-hash-reuse branch December 4, 2021 21:45
@ghost ghost locked as resolved and limited conversation to collaborators Jan 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.Security community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants