{"id":27759634,"url":"https://github.com/ssg/hashdepot","last_synced_at":"2025-11-14T03:00:52.918Z","repository":{"id":137297865,"uuid":"54429458","full_name":"ssg/HashDepot","owner":"ssg","description":".NET library for xxHash, FNV, MurmurHash3 and SipHash algorithms","archived":false,"fork":false,"pushed_at":"2025-04-29T04:20:49.000Z","size":211,"stargazers_count":143,"open_issues_count":1,"forks_count":16,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-29T11:59:20.846Z","etag":null,"topics":["c-sharp","fnv-1a","hashing","murmurhash3","nuget","siphash","xxhash"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ssg.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["ssg"]}},"created_at":"2016-03-21T23:09:26.000Z","updated_at":"2025-04-29T04:20:52.000Z","dependencies_parsed_at":null,"dependency_job_id":"6e43ef76-4f9c-4ab6-b2c8-b59f5766a61c","html_url":"https://github.com/ssg/HashDepot","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssg%2FHashDepot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssg%2FHashDepot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssg%2FHashDepot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssg%2FHashDepot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ssg","download_url":"https://codeload.github.com/ssg/HashDepot/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251498965,"owners_count":21598979,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-sharp","fnv-1a","hashing","murmurhash3","nuget","siphash","xxhash"],"created_at":"2025-04-29T11:59:28.374Z","updated_at":"2025-11-14T03:00:52.911Z","avatar_url":"https://github.com/ssg.png","language":"C#","funding_links":["https://github.com/sponsors/ssg"],"categories":[],"sub_categories":[],"readme":"# HashDepot\n[![NuGet Version](https://img.shields.io/nuget/v/HashDepot.svg)](https://www.nuget.org/packages/HashDepot/)\n![Build Status](https://github.com/ssg/HashDepot/actions/workflows/build.yml/badge.svg)\n\nI have been implementing various hash functions that are absent in .NET framework. \nI decided to converge them into a library. My primary goals are to provide well-tested and \nperformant implementations. The library currently supports [SipHash](https://131002.net/siphash/),\n[MurmurHash3](https://en.wikipedia.org/wiki/MurmurHash), [xxHash](http://cyan4973.github.io/xxHash/)\nand [FNV-1a](https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function#FNV-1a_hash). \n\nTo install it on NuGet:\n\n    Install-Package HashDepot\n\n# Supported Hash Algorithms\nI try to add anything that's not in C# runtime and quite popular. For instance,\nthere are multiple xxHash implementations for C# but they differentiate in terms of API\ncomplexity and performance. Although I didn't try out SIMD optimizations, the existing code\nis quite fast.\n\n## xxHash\nThis one claims to be one of the fastest hash functions and it's actually amazing. Even without any SIMD\noptimizations, it outperforms everything, even a plain checksum by a factor of two. The implementation\nassumes little endian machines. Example usage:\n\n```csharp\nvar buffer = Encoding.UTF8.GetBytes(\"some string\");\nuint result = XXHash.Hash32(buffer, seed: 123);\nulong result = XXHash.Hash64(buffer); // default seed is zero\n```\n\n## SipHash\nSipHash is resistant to hash-flood attacks against hashtables and uses\na key parameter to ensure HMAC-like authenticity yet faster. Unfortuantely a native \n.NET implementation does not exist. It is my take on it, and it is really fast for a \nmanaged environment. It's standard SipHash-2-4 implementation with 64-bit. To use it:\n\n```csharp\nvar buffer = Encoding.UTF8.GetBytes(\"some string\");\nvar key = new byte[16] { .. your random key here .. };\nulong result = SipHash24.Hash64(buffer, key);\n```\n\nIf you have a larger buffer than 2GB it's better to use streaming functions instead.\n\n## MurmurHash3\nMurmurHash3 provides a good balance between performance and homogenity but is \nessentially prone to hash-flood attacks (trivial to force collisions). HashDepot\nimplements its x86 flavor (not x64). An example use is:\n\n```csharp\nvar buffer = Encoding.UTF8.GetBytes(\"some string\");\nuint seed = // .. preferred seed value ...\nuint result = MurmurHash3.Hash32(buffer, seed);\n```\n\n## FNV-1a\nA straightforward implementation of FNV-1a hash algorithm for .NET. Usage is \nvery simple. For instance to calculate 32-bit FNV-1a hash of ASCII string \"some string\":\n\n```csharp\nvar buffer = Encoding.UTF8.GetBytes(\"some string\");\nuint result = Fnv1a.Hash32(buffer); // 32-bit hash\nulong result = Fnv1a.Hash64(buffer); // 64-bit hash\n```\n  \n## Streaming and Async functions\nAll hashes also provide stream-based (albeit slow) functions with their async variants too. In order to\nget the hash of a stream just call the function with a stream instead of a memory buffer:\n\n```csharp\nulong result = XXHash.Hash64(stream);\n```\n\nIf you'd like to run it asynchronously, use the async variant:\n\n```csharp\nuint result = await MurmurHash3.Hash32Async(stream);\n```\n\n# Benchmarks\nBenchmarks are performed on a 1MB buffer.\n\nBenchmarkDotNet v0.15.1, Windows 11 (10.0.26100.4202/24H2/2024Update/HudsonValley)\nAMD Ryzen 9 5950X 4.00GHz, 1 CPU, 32 logical and 16 physical cores\n.NET SDK 9.0.300\n  [Host]     : .NET 8.0.16 (8.0.1625.21506), X64 RyuJIT AVX2\n  DefaultJob : .NET 8.0.16 (8.0.1625.21506), X64 RyuJIT AVX2\n\n\n| Method          | Mean        | Error    | StdDev   | Allocated |\n|---------------- |------------:|---------:|---------:|----------:|\n| Checksum_32     |    95.80 us | 1.507 us | 1.336 us |         - |\n| XXHash_32       |   201.34 us | 1.353 us | 1.266 us |         - |\n| XXHash_64       |   185.41 us | 0.759 us | 0.634 us |         - |\n| MurmurHash3_x86 |   288.00 us | 0.820 us | 0.684 us |         - |\n| SipHash24_32    |   284.99 us | 0.881 us | 0.736 us |         - |\n| Fnv1a_32        | 1,009.49 us | 0.144 us | 0.121 us |       1 B |\n| Fnv1a_64        | 1,009.56 us | 0.136 us | 0.113 us |       1 B |\n\n# Contributing\nYou're more than welcome to contribute fixes or new hash algorithms. Please keep these in mind:\n\n- Make sure the code builds without warnings.\n- Include unit tests for the fixed bug, or the new feature.\n- If you're proposing a new hash algorithm, please make sure that it's not in C# runtime, there isn't an\n  existing library that is already tremendously popular, and HashDepot's simplistic approach would provide\n  a benefit over the alternatives.\n\n# License\nMIT License. See LICENSE file for details\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fssg%2Fhashdepot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fssg%2Fhashdepot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fssg%2Fhashdepot/lists"}