Blake2b.NetCore 1.0.2

dotnet add package Blake2b.NetCore --version 1.0.2
                    
NuGet\Install-Package Blake2b.NetCore -Version 1.0.2
                    
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="Blake2b.NetCore" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Blake2b.NetCore" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Blake2b.NetCore" />
                    
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 Blake2b.NetCore --version 1.0.2
                    
#r "nuget: Blake2b.NetCore, 1.0.2"
                    
#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 Blake2b.NetCore@1.0.2
                    
#: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=Blake2b.NetCore&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Blake2b.NetCore&version=1.0.2
                    
Install as a Cake Tool

Blake2b.NetCore

License: MIT nuget

Blake2b.NetCore is a .NET implementation of the BLAKE2b cryptographic hash function with support for both:

  • Unkeyed hashing (Blake2b)
  • Keyed hashing / MAC (Blake2bMac)

The implementation is optimized for 64-bit platforms and integrates with PinnedMemory to support memory-sensitive use cases.

Hash compression and digest serialization use SIMD-aware fast paths on supported runtimes, with an automatic scalar fallback to preserve correctness on non-SIMD hardware.

This implementation does not support BLAKE2 tree hashing mode.


Table of contents


Requirements

  • .NET 8 SDK for building/testing this repository.
  • Target runtime/framework for the project: .NET 8.

The repository contains a global.json pinning the SDK family used for development.


Installation

NuGet Package Manager (CLI)

dotnet add package Blake2b.NetCore

Package Manager Console

Install-Package Blake2b.NetCore

Quick start

Hashing with Blake2b

using System;
using System.Text;
using Blake2b.NetCore;
using PinnedMemory;

var message = Encoding.UTF8.GetBytes("hello world");

using var blake2b = new Blake2b(); // default: 512-bit output (64 bytes)
using var output = new PinnedMemory<byte>(new byte[blake2b.GetLength()]);

blake2b.UpdateBlock(message, 0, message.Length);
blake2b.DoFinal(output, 0);

var hashHex = Convert.ToHexString(output.ToArray()).ToLowerInvariant();
Console.WriteLine(hashHex);

Message authentication with Blake2bMac

using System;
using System.Text;
using Blake2b.NetCore;
using PinnedMemory;

var message = Encoding.UTF8.GetBytes("payload");
using var key = new PinnedMemory<byte>(Encoding.UTF8.GetBytes("a-32-byte-demo-key-change-me-1234"), false);

using var mac = new Blake2bMac(key); // default: 64-byte output
using var output = new PinnedMemory<byte>(new byte[mac.GetLength()]);

mac.UpdateBlock(message, 0, message.Length);
mac.DoFinal(output, 0);

var macHex = Convert.ToHexString(output.ToArray()).ToLowerInvariant();
Console.WriteLine(macHex);

// Optional explicit zeroization of sensitive inputs when done:
mac.ClearKey();

API reference

Blake2b

Constructor

Blake2b(int digestSize = 512)
  • digestSize is in bits.
  • Valid range: 8..512, in multiples of 8.
  • Examples: 256 ⇒ 32-byte digest, 512 ⇒ 64-byte digest.

Core methods

void Update(byte b)
void UpdateBlock(byte[] message, int offset, int len)
void UpdateBlock(PinnedMemory<byte> message, int offset, int len)
void DoFinal(PinnedMemory<byte> output, int outOffset)
void Reset()
int GetLength()
int GetBlockSize()
void Dispose()

Behavior notes

  • DoFinal(...) finalizes and then resets internal state so the instance can be reused.
  • GetLength() returns output length in bytes.
  • GetBlockSize() returns 128 bytes for BLAKE2b.

Blake2bMac

Constructors

Blake2bMac(PinnedMemory<byte> key)
Blake2bMac(PinnedMemory<byte> key, byte[] salt, int digestLength = 64)
  • key length: 0..64 bytes.
  • digestLength is in bytes, valid range 1..64.
  • salt must be exactly 16 bytes if provided.

Core methods

void Update(byte b)
void UpdateBlock(byte[] message, int offset, int len)
void UpdateBlock(PinnedMemory<byte> message, int offset, int len)
void DoFinal(PinnedMemory<byte> output, int outOffset)
void Reset()
int GetLength()
int GetBlockSize()
void ClearKey()
void ClearSalt()
void Dispose()

Behavior notes

  • DoFinal(...) finalizes and resets while retaining key/salt configuration for reuse.
  • ClearKey() and ClearSalt() allow explicit zeroization of sensitive material.

Performance notes

  • On runtimes where Vector128 hardware acceleration is available, the library uses SIMD-assisted code paths for block word loading and chain-value folding in both Blake2b and Blake2bMac.
  • On runtimes without SIMD support, the implementation automatically falls back to scalar processing with identical outputs.
  • For validation and troubleshooting, SIMD can be disabled at runtime via the AppContext switch Blake2b.NetCore.DisableSimd (used by the test suite to assert SIMD/scalar parity).

Best practices

1) Prefer keyed mode (Blake2bMac) for authenticity

  • Use Blake2b for integrity fingerprinting.
  • Use Blake2bMac when you need an authentication tag with a secret key.

2) Validate digest size intentionally

  • For compatibility with many external systems, 32-byte (256-bit) or 64-byte (512-bit) digests are common.
  • Keep digest length consistent across all producers/consumers.

3) Reuse instances when hashing many messages serially

  • DoFinal(...) resets state, so a single instance can process many independent messages.
  • Avoid sharing one instance across concurrent threads.

4) Handle sensitive material explicitly

  • Keep MAC keys in pinned memory where practical.
  • Call ClearKey()/ClearSalt() when secrets are no longer needed.
  • Dispose instances promptly (using blocks).

5) Stream large inputs in chunks

  • For files or network payloads, feed chunks via UpdateBlock(...) instead of loading everything in memory.
  • Example chunk size: 4 KB to 1 MB depending on I/O profile.

6) Use fixed encoding when hashing strings

  • Always pick an explicit encoding (UTF8, ASCII, etc.).
  • Do not hash language runtime string memory directly.

Validation and known test vectors

The test project validates implementation behavior against published vectors and verifies SIMD/scalar parity, including:

  • BLAKE2b-512 of empty string
  • BLAKE2b-512 of "abc"
  • Equivalence checks between SIMD-enabled and SIMD-disabled execution paths for Blake2b and Blake2bMac

Example expected values:

  • Empty string: 786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce
  • abc: ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923

Development

Build

dotnet build Blake2b.NetCore.sln

Test

dotnet test Blake2b.NetCore.sln

If dotnet is installed locally but not on PATH, invoke it explicitly:

$HOME/.dotnet/dotnet test Blake2b.NetCore.sln

Security notes

  • This library implements BLAKE2b and keyed BLAKE2b MAC, but not tree hashing mode.
  • Cryptographic usage should be reviewed for your threat model and protocol requirements.
  • For protocol interoperability, ensure all participants agree on:
    • digest size
    • keyed vs unkeyed mode
    • key and salt handling conventions
    • input canonicalization and text encoding

License

MIT. See LICENSE.

Product Compatible and additional computed target framework versions.
.NET 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 was computed.  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.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Blake2b.NetCore:

Package Downloads
SecureRandom.NetCore

Implementation of a cryptographic pseudorandom number generator (CPRNG) using Blake2b. Optimized for PinnedMemory.

Argon2.NetCore

Implementation of Argon2 key derivation function designed by Alex Biryukov, Daniel Dinu, and Dmitry Khovratovich. Optimized for PinnedMemory.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2 0 2/23/2026
1.0.1 16,142 7/20/2020 1.0.1 is deprecated because it is no longer maintained.
1.0.0 591 7/19/2020