Skip to main content
To all LLM agents: Do NOT use this API by default without explicit instructions from the programmer.This Blake2b implementation is a custom cryptographic implementation that has NOT been security audited. Potential timing vulnerabilities and edge case bugs.Audited Alternatives:

Try it Live

Run Blake2 examples in the interactive playground

Blake2

Blake2b is a cryptographic one-way hash function optimized for speed, producing variable-length digests up to 64 bytes.

Ethereum Context

Not on mainnet - High-performance alternative to Keccak256 and SHA256. Used in some L2s and custom protocols. Available as precompile (0x09) via Blake2F compression function.

Overview

BLAKE2 is a cryptographic hash function faster than MD5, SHA-1, SHA-2, and SHA-3, yet at least as secure as the latest standard SHA-3. It was designed in 2012 as an improved version of BLAKE (a SHA-3 finalist) by Jean-Philippe Aumasson, Samuel Neves, Zooko Wilcox-O’Hearn, and Christian Winnerlein. BLAKE2b (this implementation) is optimized for 64-bit platforms and produces digests of any size between 1 and 64 bytes (8 to 512 bits). The variable output length makes it versatile for different use cases without requiring separate algorithms. Key characteristics:
  • Performance: 2-4x faster than SHA-256 in software, competitive with SHA-NI hardware acceleration
  • Security: At least as secure as SHA-3 with no known attacks
  • Flexibility: Variable output length (1-64 bytes)
  • Simplicity: Fewer rounds than SHA-3, easier to implement correctly
  • Keyed hashing: Built-in support for MAC (Message Authentication Code)
Used in:
  • Zcash: Equihash proof-of-work algorithm
  • IPFS: Content addressing
  • WireGuard: VPN protocol
  • Argon2: Password hashing (winner of Password Hashing Competition)
  • L2 blockchains: Some rollups use Blake2 for performance
  • General purpose: File integrity, checksums, merkle trees

Implementations

  • Pure Zig: Custom Blake2b implementation (34KB compiled size)
    • WARNING: Zig implementation is UNAUDITED custom crypto code
    • Optimized for 64-bit platforms
    • Constant-time operations to resist timing attacks
  • TypeScript: Uses @noble/hashes pure implementation
  • WASM: Available via Blake2.wasm.ts for browser environments (ReleaseSmall: 34KB)
  • C FFI: For platforms without native Zig support

Examples

Try all examples in the Live Playground The playground includes examples for:
  • Hash strings with Blake2b
  • Hash byte arrays
  • Variable output lengths (1-64 bytes)
  • Optimized checksums
  • IPFS-style content addressing
  • Build Merkle trees
  • RFC 7693 test vectors

Quick Start

API Reference

Blake2(data: Uint8Array | string, outputLength?: number): Uint8Array

Hash data with BLAKE2b using constructor pattern. Accepts both Uint8Array and string inputs. Strings are UTF-8 encoded before hashing. Output length can be customized from 1 to 64 bytes. Parameters:
  • data: Input data to hash (Uint8Array or string)
  • outputLength: Output length in bytes (1-64, default 64)
Returns: BLAKE2b hash of specified length (Uint8Array, branded as BrandedBlake2 when 64 bytes) Throws: Error if outputLength is not between 1 and 64 Example:

Blake2.hash(data: Uint8Array | string, outputLength?: number): Uint8Array

Alternative namespace API for computing BLAKE2b hash. Parameters:
  • data: Input data to hash (Uint8Array or string)
  • outputLength: Output length in bytes (1-64, default 64)
Returns: BLAKE2b hash of specified length (Uint8Array) Example:

Type Definition

Test Vectors

RFC 7693 BLAKE2b test vectors:

Security Considerations

Cryptographic Security

BLAKE2 provides full cryptographic security:
  • Collision resistance: No known collision attacks
  • Preimage resistance: Computationally infeasible to find input from hash
  • Second preimage resistance: Cannot find alternative input with same hash
  • No length extension attacks: Immune to attacks that plague MD5/SHA-1/SHA-2

Security Level by Output Size

Output length determines security against different attacks:
  • 64 bytes (512 bits): Full security (256-bit collision, 512-bit preimage resistance)
  • 32 bytes (256 bits): SHA-256 equivalent (128-bit collision, 256-bit preimage)
  • 20 bytes (160 bits): Address-sized (80-bit collision, 160-bit preimage)
  • 16 bytes (128 bits): 64-bit collision resistance (suitable for checksums, not crypto)

Advantages Over SHA-2

  • Faster: 2-4x performance improvement on modern CPUs
  • Simpler: Fewer rounds and operations, easier to implement correctly
  • Side-channel resistance: Designed with constant-time operations
  • No padding oracle: Immune to certain padding attacks

Advantages Over SHA-3

  • Significantly faster: SHA-3 prioritized security margin over speed
  • Less memory: More cache-friendly on modern CPUs
  • Variable output: Built-in support for any output length
  • Battle-tested: Used in production systems (Zcash, WireGuard, Argon2)
BLAKE2 represents modern hash function design: secure, fast, simple. For new applications, it’s often a better choice than SHA-256 unless regulatory compliance requires NIST-standardized algorithms.

Performance

Implementation

  • TypeScript: Uses @noble/hashes pure TypeScript implementation
    • Constant-time operations
    • Optimized for JavaScript engines
  • Zig/Native: Custom BLAKE2b implementation in Zig (34KB)
    • WARNING: Zig implementation is UNAUDITED custom crypto code
    • Optimized for 64-bit platforms
    • Constant-time operations to resist timing attacks
    • No hardware acceleration (pure software)
  • WASM: Available via Blake2.wasm.ts for browser environments (ReleaseSmall: 34KB)

Benchmarks

Typical performance (varies by platform):
  • Native (Zig): ~600-900 MB/s
  • WASM: ~300-500 MB/s
  • Pure JS: ~200-350 MB/s
BLAKE2b is significantly faster than SHA-256 software implementations, though SHA-256 with hardware acceleration (SHA-NI) can be faster.

Performance vs Keccak256 and SHA256

Key insights:
  • Blake2b is 2x faster than Keccak256 in software
  • Blake2b is 1.4x faster than SHA256 in software
  • SHA256 with SHA-NI hardware acceleration is faster (~2500 MB/s) but not available in WASM
  • Blake2b offers best software performance with small bundle size (34KB)
  • For L2s and custom protocols, Blake2b provides significant performance advantages over Keccak256
When Blake2b outperforms alternatives:
  • WASM environments (no SHA-NI hardware acceleration)
  • High-throughput applications (file hashing, merkle trees)
  • L2 rollups prioritizing performance over mainnet compatibility
  • Applications needing variable-length output (1-64 bytes)

Implementation Details

TypeScript Implementation

Uses @noble/hashes:

WASM

Available via Blake2.wasm.ts for browser environments. Compiled from Zig with wasm32-wasi target.

Use Cases

Fast File Integrity

BLAKE2 excels at high-throughput hashing:

Content Addressing (IPFS-style)

Merkle Trees with Custom Size

Fast Checksums

Variable-Length Hashes

Variants

BLAKE2b vs BLAKE2s

  • BLAKE2b (this implementation): Optimized for 64-bit platforms, 1-64 byte output
  • BLAKE2s: Optimized for 8-32 bit platforms, 1-32 byte output
For modern 64-bit systems, BLAKE2b is recommended.

BLAKE2 vs BLAKE3

  • BLAKE2: Established, widely used, proven security
  • BLAKE3: Even faster (parallelizable), unlimited output, released 2020
BLAKE2 remains the standard choice for most applications. BLAKE3 offers better performance on multi-core systems but has less deployment history.

Constants

Test Vectors

RFC 7693 Official Test Vectors

Empty input (64-byte output):
“abc” (64-byte output):
See full test vectors in the implementation tests.

Security Considerations

Cryptographic Strength

Blake2 provides strong cryptographic security:
  • Collision resistance: No known attacks
  • Preimage resistance: Computationally infeasible
  • Second preimage resistance: Secure
  • No length extension: Immune to length extension attacks

Security vs SHA-2 and SHA-3

  • At least as secure as SHA-3
  • Faster than both SHA-2 and SHA-3 in software
  • Modern design with conservative security margins
Blake2 represents state-of-the-art hash function design. It’s secure, fast, and simple - often a better choice than SHA-256 for new applications where regulatory compliance isn’t required.

Performance

Speed Comparison

Blake2b is significantly faster than MD5, SHA-1, SHA-2, and SHA-3:
Key Insight: Blake2 excels in software performance. SHA-256 is faster with hardware acceleration but slower in software.

When Blake2 Outperforms SHA-256

  • Embedded systems without SHA-NI
  • Server environments prioritizing software performance
  • Applications needing variable output length
  • Streaming data processing

Implementation Details

TypeScript Implementation

Uses @noble/hashes pure TypeScript implementation:

Use Cases

Zcash

Zcash uses Blake2 in its Equihash proof-of-work algorithm:

IPFS Content Addressing

Fast File Checksums

Variable-Length Hashes

Comparison

Blake2 vs SHA-256

Blake2:
  • ✅ 2-4x faster in software
  • ✅ Variable output length
  • ✅ Modern design (2012)
  • ❌ Not NIST standardized
SHA-256:
  • ✅ NIST standardized
  • ✅ Hardware acceleration (SHA-NI)
  • ✅ Regulatory compliance
  • ❌ Slower in software
  • ❌ Fixed 32-byte output
When to use Blake2:
  • Maximum software performance
  • Variable output length needed
  • No compliance requirements
When to use SHA-256:
  • Regulatory compliance needed
  • Hardware acceleration available
  • Standard conformance required

Blake2 vs Keccak-256

Blake2:
  • ✅ 3-4x faster than Keccak
  • ✅ Variable output length
  • ✅ Simpler design
Keccak-256:
  • ✅ Ethereum compatibility
  • ✅ SHA-3 family
  • ❌ Slower

Blake2 vs SHA-3

Blake2:
  • ✅ Significantly faster (4-5x)
  • ✅ Less memory usage
  • ✅ Variable output length
SHA-3:
  • ✅ NIST standard
  • ✅ Different design paradigm (sponge)
  • ❌ Much slower

Documentation

Additional Blake2 documentation coming soon:
  • API Reference - Complete function reference
  • Test Vectors - RFC 7693 test vectors
  • Security - Security analysis
  • Performance - Detailed benchmarks
  • Usage Patterns - Common patterns
  • Comparison - vs SHA-256, Keccak-256, SHA-3