StreamHash 1.3.0
See the version list below for details.
dotnet add package StreamHash --version 1.3.0
NuGet\Install-Package StreamHash -Version 1.3.0
<PackageReference Include="StreamHash" Version="1.3.0" />
<PackageVersion Include="StreamHash" Version="1.3.0" />
<PackageReference Include="StreamHash" />
paket add StreamHash --version 1.3.0
#r "nuget: StreamHash, 1.3.0"
#:package StreamHash@1.3.0
#addin nuget:?package=StreamHash&version=1.3.0
#tool nuget:?package=StreamHash&version=1.3.0
StreamHash
StreamHash is a high-performance, memory-efficient streaming hash library for .NET 10+. It provides incremental/streaming implementations of popular hash algorithms and a unified HashFacade API supporting 62 algorithms.
๐ฏ Why StreamHash?
Many popular hash algorithms (MurmurHash, CityHash, SpookyHash, etc.) don't have official streaming APIs. This means hashing a 10GB file requires 10GB of RAM! StreamHash solves this by providing streaming implementations that process data in chunks, using only ~1MB of memory regardless of file size.
โจ Features
- ๐ Memory Efficient: Hash multi-gigabyte files with minimal memory footprint
- โก High Performance: SIMD-optimized implementations where available
- ๐ Streaming API: Process data incrementally with
Update()andFinalize() - ๐ฆ Zero Allocations: Hot paths are allocation-free using
Span<T> - ๐ฏ Unified API:
HashFacadeprovides access to 62 algorithms through a single interface - ๐งช Thoroughly Tested: 619+ tests validating against official test vectors
- ๐ Fully Documented: XML docs, examples, and algorithm references
๐ Algorithm Support
Streaming Implementations (16 native)
| Algorithm | Digest Size | Status |
|---|---|---|
| MurmurHash3-32/128 | 32/128-bit | โ Complete |
| CityHash64/128 | 64/128-bit | โ Complete |
| SpookyHash V2 | 128-bit | โ Complete |
| SipHash-2-4 | 64-bit | โ Complete |
| FarmHash64 | 64-bit | โ Complete |
| HighwayHash64 | 64-bit | โ Complete |
| KangarooTwelve | Variable (XOF) | โ Complete |
| MetroHash64/128 | 64/128-bit | โ Complete |
| wyhash64 | 64-bit | โ Complete |
| xxHash32/64/3/128* | 32-128 bit | โ Complete |
HashFacade Unified API (62 algorithms)
The HashFacade class provides one-shot and streaming access to:
- Checksums (6): CRC32, CRC32C, CRC64, Adler-32, Fletcher-16, Fletcher-32
- Fast Non-Crypto (16): xxHash, MurmurHash3, CityHash, FarmHash, SpookyHash, SipHash, HighwayHash, MetroHash, wyhash
- Cryptographic (26): MD family, SHA family, SHA-3, Keccak, BLAKE family, RIPEMD family
- Other (14): Whirlpool, Tiger, GOST, Streebog, Skein, SM3
Note: Cryptographic algorithms (SHA-3, BLAKE, etc.) require BouncyCastle. StreamHash.Core provides fast non-crypto hashes natively.
๐ Quick Start
Installation
dotnet add package StreamHash --version 1.3.0
HashFacade API (Recommended)
using StreamHash.Core;
// One-shot hashing
byte[] data = File.ReadAllBytes("file.bin");
byte[] hash = HashFacade.ComputeHash(HashAlgorithm.XxHash64, data);
string hex = HashFacade.ComputeHashHex(HashAlgorithm.Sha256, data);
// Streaming hashing
using var hasher = HashFacade.CreateStreaming(HashAlgorithm.MurmurHash3_128);
hasher.Update(chunk1);
hasher.Update(chunk2);
byte[] result = hasher.FinalizeBytes();
// Algorithm info
var info = HashFacade.GetInfo(HashAlgorithm.Sha256);
Console.WriteLine($"{info.DisplayName}: {info.DigestSize} bytes, Crypto: {info.IsCryptographic}");
Direct Streaming API
using StreamHash.Core;
// Hash a file incrementally
using var hasher = new MurmurHash3_128();
using var stream = File.OpenRead("large-file.bin");
byte[] buffer = new byte[1024 * 1024]; // 1MB buffer
int bytesRead;
while ((bytesRead = await stream.ReadAsync(buffer)) > 0) {
hasher.Update(buffer.AsSpan(0, bytesRead));
}
UInt128 hash = hasher.Finalize();
Console.WriteLine($"Hash: {hasher.FinalizeHex()}");
๐ Documentation
๐๏ธ Building
# Clone the repository
git clone https://github.com/TheAnsarya/StreamHash.git
cd StreamHash
# Build
dotnet build StreamHash.sln
# Run tests (619+ tests)
dotnet test
# Run benchmarks
dotnet run -c Release --project benchmarks/StreamHash.Benchmarks
๐ Benchmarks
Benchmarks comparing StreamHash to reference implementations:
| Method | File Size | Memory | Throughput |
|---------------------|-----------|-----------|------------|
| MurmurHash3 (ref) | 1 GB | 1,024 MB | 3.2 GB/s |
| MurmurHash3 (stream)| 1 GB | 1 MB | 3.1 GB/s |
| CityHash (ref) | 1 GB | 1,024 MB | 4.5 GB/s |
| CityHash (stream) | 1 GB | 1 MB | 4.3 GB/s |
๐ค Contributing
Contributions are welcome! Please read our Contributing Guide for details.
๐ License
This project is released into the public domain under The Unlicense. Do whatever you want with it.
๐ Acknowledgments
- SMHasher - MurmurHash reference implementation
- CityHash - Google's CityHash
- SpookyHash - Bob Jenkins' SpookyHash
- SipHash - Reference SipHash implementation
| 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
- System.IO.Hashing (>= 9.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
v1.3.0: Added unified HashFacade API with 62 algorithm support (checksums, fast hashes, crypto). IStreamingHashBytes interface for consistent byte[] output. 619 tests.