Skip to content
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

Avoid finalizable internal state for non-FIPS scenarios #67998

Closed
wants to merge 1 commit into from

Conversation

sharwell
Copy link
Member

Fixes #67995

Marked as draft since the current approach focuses exclusively on .NET Framework execution. Need to determine if this will result in a penalty for cases that were previously using IncrementalHash on .NET Core.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 27, 2023
@CyrusNajmabadi
Copy link
Member

yeah, my pref would be that thsi only be a fallback on netfx. :)

could we also get stephen to look?

@@ -206,7 +206,7 @@ internal static ImmutableArray<byte> ComputeHash(HashAlgorithmName algorithmName
internal static ImmutableArray<byte> ComputeSourceHash(ImmutableArray<byte> bytes, SourceHashAlgorithm hashAlgorithm = SourceHashAlgorithms.Default)
{
var algorithmName = GetAlgorithmName(hashAlgorithm);
using (var incrementalHash = IncrementalHash.CreateHash(algorithmName))
using (var incrementalHash = RoslynIncrementalHash.CreateHash(algorithmName))
{
incrementalHash.AppendData(bytes.ToArray());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yikes. feels like this should be better on Core as well, by using available hash functions that don't require tehse intermediary allocations.

@CyrusNajmabadi
Copy link
Member

Could you link to the difference in this and teh existing netfx impl that addresses the core problem? i want to understand the difference better. (would also be good if the code itself potentially had such a link. thanks!)

Comment on lines +142 to +165
if (hashAlgorithm == HashAlgorithmName.MD5)
{
return MD5.Create();
}

if (hashAlgorithm == HashAlgorithmName.SHA1)
{
return SHA1.Create();
}

if (hashAlgorithm == HashAlgorithmName.SHA256)
{
return SHA256.Create();
}

if (hashAlgorithm == HashAlgorithmName.SHA384)
{
return SHA384.Create();
}

if (hashAlgorithm == HashAlgorithmName.SHA512)
{
return SHA512.Create();
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 The change relative to the reference implementation is here. .NET Framework creates instances of SHA256CryptoServiceProvider instead of calling SHA256.Create() (likewise for each of the others).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 In theory, we could also address this by modifying the way we create our pool of IncrementalHash objects to use reflection to reset the _hash field.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and it's hte provider that was causing the problem before?

@sharwell
Copy link
Member Author

Closing this in favor of #67999

@sharwell sharwell closed this Apr 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Checksum's usage of a native hash algorithm resulting in thread starvation
2 participants