StreamHash 1.11.2
dotnet add package StreamHash --version 1.11.2
NuGet\Install-Package StreamHash -Version 1.11.2
<PackageReference Include="StreamHash" Version="1.11.2" />
<PackageVersion Include="StreamHash" Version="1.11.2" />
<PackageReference Include="StreamHash" />
paket add StreamHash --version 1.11.2
#r "nuget: StreamHash, 1.11.2"
#:package StreamHash@1.11.2
#addin nuget:?package=StreamHash&version=1.11.2
#tool nuget:?package=StreamHash&version=1.11.2
StreamHash
StreamHash is a high-performance, memory-efficient streaming hash library for .NET 10+. All 70 hash algorithms are implemented natively in pure C# with zero heavy dependencies β just one lightweight package (System.IO.Hashing) for CRC/xxHash acceleration.
π― Why StreamHash?
- Single package, all algorithms: One NuGet install gives you 70 hash algorithms β no BouncyCastle, no native binaries, no transitive dependency hell
- Streaming everything: Many popular algorithms (MurmurHash, CityHash, SpookyHash, etc.) lack streaming APIs. Hashing a 10GB file normally requires 10GB of RAM! StreamHash processes data in chunks using ~16MB regardless of file size
- Competitive performance: Native C# implementations match or beat external libraries for most algorithms β see benchmarks
β¨ Features
- π Memory Efficient: Hash multi-gigabyte files with minimal memory footprint
- β‘ High Performance: Optimized implementations with SIMD where available (GrΓΈstl AES-NI, JH SSSE3, HighwayHash AVX2, BLAKE2b AVX2, CRC-32C SSE4.2)
- π Streaming API: Process data incrementally with
Update()andFinalize() - π¦ Zero Allocations: Hot paths are allocation-free using
Span<T> - π― Unified API:
HashFacadeprovides access to all 70 algorithms through a single interface - π All-Native Crypto: Every cryptographic algorithm implemented in pure C# β no BouncyCastle dependency
- β‘ Batch Streaming: Process 70 algorithms in parallel with
CreateAllStreaming() - π§ͺ Thoroughly Tested: 1853+ tests validating against official test vectors
- π¦ Minimal Dependencies: Only
System.IO.Hashingβ no large transitive dependency chains
π Quick Start
Installation
dotnet add package StreamHash --version 1.11.2
One-Shot Hashing (Simplest)
using StreamHash.Core;
byte[] data = File.ReadAllBytes("file.bin");
// Compute a single hash
string hex = HashFacade.ComputeHashHex(HashAlgorithm.Sha256, data);
byte[] hash = HashFacade.ComputeHash(HashAlgorithm.XxHash64, data);
// Get algorithm info
var info = HashFacade.GetInfo(HashAlgorithm.Sha256);
Console.WriteLine($"{info.DisplayName}: {info.DigestSize} bytes, Crypto: {info.IsCryptographic}");
Streaming a Single Algorithm
For large files that don't fit in memory:
using StreamHash.Core;
using var hasher = HashFacade.CreateStreaming(HashAlgorithm.MurmurHash3_128);
using var stream = File.OpenRead("large-file.bin");
byte[] buffer = new byte[1024 * 1024]; // 1MB buffer
int bytesRead;
while ((bytesRead = stream.Read(buffer)) > 0) {
hasher.Update(buffer.AsSpan(0, bytesRead));
}
byte[] result = hasher.FinalizeBytes();
string hex = hasher.FinalizeHex();
Batch Streaming β All 70 Algorithms at Once
Hash a file with all 70 algorithms in parallel, in a single pass:
using StreamHash.Core;
using var multi = HashFacade.CreateAllStreaming();
using var stream = File.OpenRead("large-file.bin");
byte[] buffer = new byte[16 * 1024 * 1024]; // 16MB buffer recommended
int read;
while ((read = stream.Read(buffer, 0, buffer.Length)) > 0) {
multi.Update(buffer.AsSpan(0, read));
}
Dictionary<string, string> results = multi.FinalizeAll();
// results["SHA256"] = "abc123..."
// results["MD5"] = "def456..."
// ... all 70 algorithms
Basic Hashes β The 4 Most Common
For the common case of verifying files with CRC32, MD5, SHA-1, and SHA-256:
using StreamHash.Core;
using var basicHasher = HashFacade.CreateBasicHashesStreaming();
using var stream = File.OpenRead("download.zip");
var buffer = new byte[16 * 1024 * 1024];
int bytesRead;
while ((bytesRead = stream.Read(buffer)) > 0) {
basicHasher.Update(buffer.AsSpan(0, bytesRead));
}
var results = basicHasher.FinalizeAll();
Console.WriteLine($"CRC32: {results[HashAlgorithmNames.Crc32]}");
Console.WriteLine($"MD5: {results[HashAlgorithmNames.Md5]}");
Console.WriteLine($"SHA-1: {results[HashAlgorithmNames.Sha1]}");
Console.WriteLine($"SHA-256: {results[HashAlgorithmNames.Sha256]}");
Tip: Use HashAlgorithmNames constants instead of string literals to avoid typos!
Direct Type API
You can also instantiate algorithm types directly:
using StreamHash.Core;
using var hasher = new MurmurHash3_128();
hasher.Update(chunk1);
hasher.Update(chunk2);
UInt128 hash = hasher.Finalize();
π Algorithm Support (70 Algorithms)
| Category | Count | Algorithms |
|---|---|---|
| Checksums | 9 | CRC32, CRC32C, CRC64, CRC-16 (CCITT/MODBUS/USB), Adler-32, Fletcher-16, Fletcher-32 |
| Fast Non-Crypto | 22 | xxHash (32/64/3/128), MurmurHash3 (32/128), CityHash (64/128), FarmHash64, SpookyV2, SipHash, HighwayHash64, MetroHash (64/128), wyhash64, FNV-1a (32/64), DJB2, DJB2a, SDBM, LoseLose |
| MD Family | 3 | MD2, MD4, MD5 |
| SHA-1/2 Family | 9 | SHA-0, SHA-1, SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224, SHA-512/256 |
| SHA-3 & Keccak | 6 | SHA3-224, SHA3-256, SHA3-384, SHA3-512, Keccak-256, Keccak-512 |
| BLAKE Family | 5 | BLAKE-256, BLAKE-512, BLAKE2b, BLAKE2s, BLAKE3 |
| RIPEMD Family | 4 | RIPEMD-128, RIPEMD-160, RIPEMD-256, RIPEMD-320 |
| Other Crypto | 12 | Whirlpool, Tiger-192, GOST-94, Streebog-256/512, Skein-256/512/1024, GrΓΈstl-256/512, JH-256/512, KangarooTwelve, SM3 |
All algorithms are implemented in pure native C# with zero true unsafe code.
β‘ Performance Highlights
StreamHash's native C# matches or beats external libraries for most algorithms:
- 4.9x faster: Whirlpool vs BouncyCastle
- 2.5x faster: SHA-1 (.NET hardware acceleration)
- 1.8x faster: RIPEMD-128, Streebog-256
- At parity: BLAKE3 (matches Rust native!), SHA3 family, CRC, xxHash
- 20 algorithms faster than BouncyCastle, only 2 meaningfully slower (BLAKE2b/2s with AVX2 SIMD)
Full benchmark data with detailed comparisons at all data sizes: Performance Benchmarks
π Documentation
- π Algorithm Reference β all 70 algorithms documented
- π Performance Benchmarks β detailed comparisons vs BouncyCastle, System.IO.Hashing, Blake2Fast
- π Reference Hash Values β test vectors and expected outputs
- π¦ NuGet Publishing β package build and release process
- π Changelog β version history and release notes
Algorithm Documentation
| Category | Docs |
|---|---|
| BLAKE2b/2s | blake2.md |
| BLAKE3 | blake3.md |
| Keccak/SHA-3 | keccak-sha3.md |
| SHA-0/224/512t | sha-family.md |
| MD2/MD4/MD5 | md-family.md |
| RIPEMD family | ripemd.md |
| Skein family | skein.md |
| Whirlpool | Whirlpool.md |
| Tiger-192 | tiger.md |
| SM3 | sm3.md |
| GrΓΈstl | groestl.md |
| JH | jh.md |
| KangarooTwelve | kangarootwelve.md |
| Streebog | streebog.md |
| GOST-94 | gost94.md |
| xxHash family | xxhash.md |
| MetroHash | metrohash.md |
| wyhash | wyhash.md |
| FNV-1a | fnv1a.md |
| CRC-16 | crc16.md |
| MurmurHash3 | murmurhash3.md |
| CityHash | cityhash.md |
| FarmHash | farmhash.md |
| SipHash | siphash.md |
| SpookyHash | spookyhash.md |
| HighwayHash | highwayhash.md |
ποΈ Building
git clone https://github.com/TheAnsarya/StreamHash.git
cd StreamHash
dotnet build StreamHash.slnx
dotnet test # 1853+ tests
π License
This project is released into the public domain under The Unlicense. Do whatever you want with it.
π Acknowledgments & References
As of v1.11.0, all 70 algorithms are implemented natively in StreamHash with no external hash library dependencies. The following projects were invaluable as reference implementations and inspiration:
Reference Implementations
- BouncyCastle.Cryptography β Reference for MD2, MD4, SHA-224, SHA-512/224, SHA-512/256, RIPEMD-256/320, GOST-94, Streebog-256/512, Skein-256/512/1024, SM3, BLAKE2b/2s. MIT License.
- acryptohashnet β Reference for Keccak-256/512, RIPEMD-128/160, Tiger-192, SHA-0. MIT License.
- SauceControl.Blake2Fast β BLAKE2 SIMD reference with SSE2-AVX512. MIT License.
- Blake3.NET β BLAKE3 reference (Rust SIMD). Apache 2.0/MIT License.
- nebulae.dotSHA3 β SHA-3 XKCP reference with AVX2/NEON. MIT License.
Algorithm References
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Blake3 (>= 2.2.1)
- System.IO.Hashing (>= 10.0.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
v1.11.2: Fixed benchmark chunk sizes to use realistic I/O sizes. Added chunk-size matrix benchmarks for optimal performance analysis. All 70 algorithms benchmarked with realistic 1MB chunks instead of unrealistic 16MB chunks.