The hashing subsystem in GrindCore.net provides a high-performance, unified interface for a wide variety of cryptographic and non-cryptographic hash functions. By extending the standard .NET System.Security.Cryptography.HashAlgorithm, the library ensures full compatibility with framework components like CryptoStream while offering optimized native implementations via P/Invoke.
The hashing architecture is built around the HashAlgorithmGC base class and a centralized HashFactory. This design allows developers to switch between algorithms (e.g., MD5 to SHA3 or XXHash) by simply changing a HashType enum value.
The following diagram illustrates how the HashType enum maps to concrete implementation classes via the HashFactory.
Hash Implementation Registry
Sources: src/HashAlgorithmGC.cs9-10 tests/GrindCore.Tests/HashTests.cs58-63 tests/GrindCore.Tests/HashTests.cs7-10
All hashing algorithms in GrindCore.net derive from HashAlgorithmGC. This base class maintains compatibility with the standard .NET HashAlgorithm while adding the HashAsType<T>() method. This method allows for zero-allocation retrieval of numeric hashes (like uint for XXHash32) without converting them to byte arrays first, provided the derived class supports the type.
For details, see HashAlgorithmGC Base & HashFactory.
The HashFactory is the primary entry point for creating hash instances. It uses a non-reflection-based dispatch mechanism to instantiate the correct class based on the HashType provided. It also provides static Compute methods for one-shot hashing of byte arrays, as demonstrated in the test suite.
For details, see HashAlgorithmGC Base & HashFactory.
Entity Association Diagram
Sources: src/HashAlgorithmGC.cs24-34 tests/GrindCore.Tests/HashTests.cs58-63 tests/GrindCore.Tests/HashTests.cs4-6
GrindCore.net categorizes its hashing algorithms into several families based on their cryptographic properties and performance characteristics.
| Family | Supported Types | Primary Use Case |
|---|---|---|
| Blake | Blake2sp, Blake3 | High-speed cryptographic hashing. |
| XXHash | XXH32, XXH64 | Non-cryptographic integrity checks (fastest). |
| MD | MD2, MD4, MD5 | Legacy compatibility and checksums. |
| SHA | SHA1, SHA2 (256/384/512), SHA3 (224-512) | Standard cryptographic security. |
These algorithms provide modern cryptographic security with performance that often exceeds non-cryptographic hashes on modern CPUs. They are frequently tested against large payloads (512MiB) to ensure stability. For details, see Blake2sp & Blake3.
XXHash is the primary mechanism used within the GrindCore.net test suite to verify data integrity due to its extreme speed. It is used extensively in CompressionBlockTests to validate compressed and decompressed data buffers.
For details, see XXHash (XXH32 & XXH64).
These legacy algorithms are provided for backward compatibility. The implementations interface with native libraries to ensure performance parity across different .NET versions and platforms. For details, see MD2, MD4 & MD5.
The library supports the full Secure Hash Algorithm family, including the Keccak-based SHA3 variants. These are the recommended choices for high-security applications requiring standard compliance. For details, see SHA1, SHA2 & SHA3.
Sources: tests/GrindCore.Tests/HashTests.cs37-51 tests/GrindCore.Tests/CompressionBlockTests.cs91-92 tests/GrindCore.Tests/HashTests.cs52-64