Blake3.Managed 1.5.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Blake3.Managed --version 1.5.0
                    
NuGet\Install-Package Blake3.Managed -Version 1.5.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Blake3.Managed" Version="1.5.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Blake3.Managed" Version="1.5.0" />
                    
Directory.Packages.props
<PackageReference Include="Blake3.Managed" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Blake3.Managed --version 1.5.0
                    
#r "nuget: Blake3.Managed, 1.5.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Blake3.Managed@1.5.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Blake3.Managed&version=1.5.0
                    
Install as a Cake Addin
#tool nuget:?package=Blake3.Managed&version=1.5.0
                    
Install as a Cake Tool

Blake3.Managed: BLAKE3 hash function for .NET

A pure managed C# implementation of the BLAKE3 cryptographic hash function for .NET. Uses hardware intrinsics (AVX2, SSE/SSSE3, ARM NEON) for high performance with automatic scalar fallback. Faster than SHA-256 and MD5, with zero native dependencies and no P/Invoke.

BLAKE3 is a modern, secure hash ideal for file checksums, content addressing, deduplication, data integrity, message authentication (keyed MAC) and key derivation (KDF). This library brings it to C# / .NET as a single fully managed, Native AOT-friendly NuGet package that runs everywhere .NET runs.

NuGet NuGet Downloads CI License Buy Me A Coffee

Features

  • Pure managed C# - no native libraries, no P/Invoke, runs everywhere .NET runs
  • Hardware accelerated - AVX2 8-way parallel hashing, SSE/SSSE3 vectorized compression, ARM NEON 4-way parallel hashing, automatic scalar fallback
  • Multi-threaded - one-shot Hash(), Blake3HashAlgorithm and Blake3Stream hash 64-chunk subtrees on the thread pool for inputs above ~72 KiB
  • Split hashing - hash pieces of one file or download on different threads, machines, or at different times, then combine the pieces into the same hash you would get from hashing the whole thing at once (Blake3SubtreeContext)
  • Zero allocation for small inputs - one-shot Hasher.Hash() uses stack allocation
  • All BLAKE3 modes - default hashing, keyed hashing, and key derivation
  • XOF support - extendable output with seekable byte stream
  • API compatible - similar API to the Blake3 Rust API and mirrors Blake3.NET API surface
  • Targets net6.0, net8.0 and net10.0 (with hardware intrinsics)

How this compares to the other BLAKE3 packages

Blake3.NET by Alexandre Mutel is a very polished BLAKE3 library for .NET, and some ideas and code examples here are borrowed from it. As of 3.x it ships as two packages: Blake3 is now a pure managed SIMD implementation, and Blake3.Native is the P/Invoke binding to the official Rust code. Both are excellent.

So "managed versus native" is no longer the interesting distinction - there are several good managed options. What this library offers instead:

  • A multithreaded one-shot path. Hasher.Hash splits large inputs into balanced subtrees and hashes them on the thread pool, so above roughly 72 KB it finishes sooner than any single-threaded implementation, including the Rust binding. That is wall-clock latency bought with more cores, not better per-core efficiency, which is worth knowing if you are already saturating every core with other work.
  • net6.0 support, which Blake3 3.x dropped.
  • No native dependency, so deployment stays simple and Native AOT and trimming work without extra care.

On short inputs it is the fastest of the three: 4 bytes and 128 bytes both beat the Rust binding and Blake3 3.x outright. Between 1 KB and 64 KB, where the work is single-threaded, it runs at 1.0x to 1.8x the Rust implementation depending on size. See the numbers below.

Installation

dotnet add package Blake3.Managed

Quick Start

using Blake3.Managed;

// One-shot hash
var hash = Hasher.Hash("Hello, World!"u8);
Console.WriteLine(hash); // 288a86a79f20a3d6dccdca1c47c4c4726cddf1ae8c3ae5bdddf8f57a76a3a02e

// Incremental hashing
using var hasher = Hasher.New();
hasher.Update("Hello, "u8);
hasher.Update("World!"u8);
var result = hasher.Finalize();

// Keyed hash (32-byte key)
byte[] key = new byte[32]; // your key here
using var keyedHasher = Hasher.NewKeyed(key);
keyedHasher.Update(data);
var mac = keyedHasher.Finalize();

// Key derivation
using var kdf = Hasher.NewDeriveKey("my-session-key");
kdf.Update(inputKeyMaterial);
var derivedKey = kdf.Finalize();

// Extended output (XOF)
using var xof = Hasher.New();
xof.Update(data);
var extendedOutput = new byte[1024];
xof.Finalize(extendedOutput); // arbitrary length output

// Parallel hashing for large data
using var parallel = Hasher.New();
parallel.UpdateWithJoin(largeData); // uses thread pool above ~72 KiB
var parallelHash = parallel.Finalize();

// Capping how many threads the one-shot Hasher.Hash may use
// (process-wide; does not affect UpdateWithJoin, and never changes the digest)
Hasher.MaxDegreeOfParallelism = 4;  // at most 4 threads
Hasher.MaxDegreeOfParallelism = 1;  // caller's thread only; use when you are
                                    // already parallelising over many inputs
Hasher.MaxDegreeOfParallelism = -1; // default: let the thread pool decide

// Hashing pieces of one input on your own threads, in any order, and folding
// them into the digest a whole-input hash would produce
using var ctx = Blake3SubtreeContext.Create(pieceSize: 1024 * 1024, totalLength: file.Length);
var pieces = new Blake3Subtree[ctx.PieceCount];
Parallel.For(0, ctx.PieceCount, i =>
{
    var piece = ReadPiece(file, ctx.GetPieceOffset(i), ctx.GetPieceLength(i));
    pieces[i] = ctx.HashSubtree(piece, i);
});
var fileHash = ctx.Finalize(pieces); // equals Hasher.Hash(wholeFile)

// The same, feeding each piece in parts as it arrives (a download, say),
// so a piece never has to be in memory at once and may exceed 2 GB
using var pieceHasher = ctx.CreateSubtreeHasher(pieceIndex);
while ((n = await stream.ReadAsync(buffer)) > 0)
    pieceHasher.Update(buffer.AsSpan(0, n));
pieces[pieceIndex] = pieceHasher.Finish();

Public API

Type Description
Hasher Main hasher struct. Factory methods: New(), NewKeyed(), NewDeriveKey(). Static Hash() for one-shot. Incremental via Update()/UpdateWithJoin()/Finalize(). Static MaxDegreeOfParallelism caps the fan-out used by Hash().
Hash Fixed 32-byte output struct with constant-time equality and allocation-free ToString().
Blake3Stream Stream wrapper that hashes data as it flows through.
Blake3HashAlgorithm System.Security.Cryptography.HashAlgorithm adapter for interop with existing APIs.
Blake3SubtreeContext Hashes fixed-size pieces of one input independently, on any threads and in any order, and folds them into the whole-input digest (32 bytes or XOF). Piece size must be a power-of-two multiple of 1024; it is a long, so pieces larger than 2 GB are allowed.
Blake3SubtreeHasher Hashes one piece incrementally through Update calls and Finish, for pieces that arrive in parts or are too large for one span. Created by Blake3SubtreeContext.CreateSubtreeHasher.
Blake3Subtree Opaque result of hashing one piece, stored at its piece index and passed to Finalize.

Performance

Benchmarks

One-shot hashing (Hasher.Hash(data)) against the Rust implementation via P/Invoke (Blake3.Native), the managed Blake3 3.x package, and System.Security.Cryptography.SHA256. Above roughly 72 KB, Hasher.Hash spreads the work across cores; every other column is single-threaded.

BenchmarkDotNet v0.15.8, Windows 11 (10.0.26200)
AMD Ryzen 7 PRO 7840U w/ Radeon 780M Graphics, 1 CPU, 16 logical and 8 physical cores
.NET SDK 10.0.303, .NET 10.0.11, X64 RyuJIT AVX-512

Mean time per hash, and the ratio against the Rust implementation (lower is better):

Input Blake3.Native (Rust) Blake3 3.x (managed) Blake3.Managed SHA256
4 B 78.5 ns 78.4 ns (1.00) 51.9 ns (0.66) 148.6 ns (1.89)
128 B 128.7 ns 117.7 ns (0.91) 111.6 ns (0.87) 202.7 ns (1.57)
1 KB 855.6 ns 935.8 ns (1.09) 868.5 ns (1.02) 595.4 ns (0.70)
4 KB 1.21 us 3.90 us (3.22) 1.44 us (1.18) 1.94 us (1.60)
8 KB 1.38 us 1.81 us (1.32) 1.74 us (1.27) 3.78 us (2.75)
16 KB 2.31 us 3.29 us (1.42) 3.22 us (1.39) 7.46 us (3.23)
64 KB 8.87 us 11.35 us (1.28) 12.54 us (1.41) 29.16 us (3.29)
128 KB 16.89 us 23.51 us (1.39) 8.24 us (0.49) 57.81 us (3.42)
1 MB 141.2 us 260.5 us (1.84) 45.2 us (0.32) 518.5 us (3.67)
10 MB 2.78 ms 3.91 ms (1.40) 0.50 ms (0.18) 5.66 ms (2.03)

BLAKE3 throughput on .NET

Hardware Intrinsics Tiering

The implementation automatically selects the best available instruction set at runtime:

Tier Instructions Parallelism
AVX2 256-bit vectors 8 chunks simultaneously, plus 8-way parent-node hashing for the merge tree
SSE/SSSE3 128-bit vectors + shuffle 4 chunks simultaneously, single-lane SIMD fallback
ARM NEON 128-bit vectors 4 chunks simultaneously
Scalar Pure C# Portable fallback

Building from Source

# Requires .NET 10 SDK
dotnet build src -c Release

# Run tests
dotnet test src/Blake3.Managed.Tests -c Release

# Run benchmarks
dotnet run --project src/Blake3.Managed.Benchmarks -c Release

# Create NuGet package
dotnet pack src/Blake3.Managed -c Release

Acknowledgments

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net6.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.10.0 37,790 10/14/2026
1.9.0 227 10/9/2026
1.8.0 2,268 9/24/2026
1.7.4 404 9/22/2026
1.7.3 125 9/21/2026
1.7.2 141 9/20/2026
1.7.1 130 9/20/2026
1.7.0 128 9/20/2026
1.6.0 231 9/14/2026
1.5.2 1,127 9/9/2026
1.5.1 251 9/4/2026
1.5.0 173 9/3/2026
1.4.0 237 9/2/2026
1.3.0 6,090 7/31/2026
1.2.1 3,083 6/10/2026
1.2.0 153 6/10/2026
1.1.0 819 2/27/2026
1.0.0 172 2/26/2026
0.1.0-rc.1 108 2/26/2026