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)
- 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
Interactive examples in the Voltaire Playground:- Basic Hashing - Hash strings with Blake2b
- Hash Bytes - Hash byte arrays
- Variable Length - Variable output lengths (1-64 bytes)
- Fast Checksums - Optimized checksums
- Content Addressing - IPFS-style content addressing
- Merkle Tree - Build Merkle trees
- Test Vectors - RFC 7693 test vectors
Quick Start
- Basic Hashing
- String Hashing
- Variable Output
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)
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)
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)
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
Performance vs Keccak256 and SHA256
- 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
- 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 viaBlake2.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
BLAKE2 vs BLAKE3
- BLAKE2: Established, widely used, proven security
- BLAKE3: Even faster (parallelizable), unlimited output, released 2020
Constants
Test Vectors
RFC 7693 Official Test Vectors
Empty input (64-byte output):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
Performance
Speed Comparison
Blake2b is significantly faster than MD5, SHA-1, SHA-2, and SHA-3: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
- ✅ NIST standardized
- ✅ Hardware acceleration (SHA-NI)
- ✅ Regulatory compliance
- ❌ Slower in software
- ❌ Fixed 32-byte output
- Maximum software performance
- Variable output length needed
- No compliance requirements
- Regulatory compliance needed
- Hardware acceleration available
- Standard conformance required
Blake2 vs Keccak-256
Blake2:- ✅ 3-4x faster than Keccak
- ✅ Variable output length
- ✅ Simpler design
- ✅ Ethereum compatibility
- ✅ SHA-3 family
- ❌ Slower
Blake2 vs SHA-3
Blake2:- ✅ Significantly faster (4-5x)
- ✅ Less memory usage
- ✅ Variable output length
- ✅ 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
Related
- SHA256 - Industry standard, hardware accelerated
- Keccak256 - Ethereum’s hash function
- RIPEMD160 - Legacy 160-bit hash
- Keccak256Hash - 32-byte hash type
- RFC 7693 - Blake2 specification

