This pull request addresses the thread-unsafe use of a static ICryptoTransform field. The original code used a static instance of System.Security.Cryptography.SHA256, which is not thread-safe and could lead to potential issues when accessed concurrently by multiple threads. Code analysis
To resolve this, the static instance has been replaced with a method that creates a new instance of SHA256 whenever it is needed. This ensures that each thread operates on its own instance, thus maintaining thread safety.
Motivation and Context
This change is required to prevent potential thread safety issues that arise from the concurrent use of a shared SHA256 instance. By creating a new instance for each thread, we ensure the integrity and correctness of hash computations.
Fixes # (issue)
Type of change
[x] Bug fix (non-breaking change which fixes an issue)
How Has This Been Tested?
The changes have been tested by:
Verifying that hash computations produce the correct results.
Ensuring that there are no thread safety issues by simulating concurrent access in a multithreaded environment.
Confirming that the SHA256 instances are properly disposed of after use.
Screenshots (if appropriate):
Checklist:
[x] My code follows the style guidelines of this project
[x] I have commented my code, particularly in hard-to-understand areas
[x] I have made corresponding changes to the documentation
[x] I have added tests that prove my fix is effective or that my feature works
Description
This pull request addresses the thread-unsafe use of a static
ICryptoTransform
field. The original code used a static instance ofSystem.Security.Cryptography.SHA256
, which is not thread-safe and could lead to potential issues when accessed concurrently by multiple threads. Code analysisTo resolve this, the static instance has been replaced with a method that creates a new instance of
SHA256
whenever it is needed. This ensures that each thread operates on its own instance, thus maintaining thread safety.Motivation and Context
This change is required to prevent potential thread safety issues that arise from the concurrent use of a shared
SHA256
instance. By creating a new instance for each thread, we ensure the integrity and correctness of hash computations.Fixes # (issue)
Type of change
How Has This Been Tested?
The changes have been tested by:
SHA256
instances are properly disposed of after use.Screenshots (if appropriate):
Checklist: