Skip to main content

Overview

The BLAKE2 inline provides an optimized implementation of the BLAKE2b hash function with 512-bit output. BLAKE2 is faster than MD5, SHA-1, SHA-2, and SHA-3, while being at least as secure as SHA-3.

API Reference

Constants

Initialization Vector

Usage Examples

Basic Hashing

Keyed Hashing (MAC)

File Integrity Verification

Implementation Details

Compression Function

BLAKE2b uses a compression function similar to ChaCha20:
  • State: 8 × 64-bit words (512 bits)
  • Message block: 16 × 64-bit words (1024 bits)
  • Rounds: 12 rounds using the SIGMA permutation table

SIGMA Permutation Table

The message schedule uses a 12-round permutation pattern:

Custom Instruction

  • BLAKE2_COMPRESS (funct3=0x00, funct7=0x02): Performs BLAKE2b compression

Memory Layout

  • Input block: 128 bytes (16 × 64-bit words)
  • State: 64 bytes (8 × 64-bit words)
  • Output: 64 bytes

Performance Characteristics

  • Block size: 128 bytes per compression
  • Output size: 64 bytes (512 bits)
  • Speed: Faster than SHA-2 and SHA-3 on modern hardware
  • Security: 512-bit security level

BLAKE2 Variants

The inline implements BLAKE2b (64-bit optimized). Other variants:
  • BLAKE2b: Optimized for 64-bit platforms (this implementation)
  • BLAKE2s: Optimized for 8-32 bit platforms (not included)
  • BLAKE2bp: Parallel variant (not included)
  • BLAKE2sp: Parallel variant for smaller platforms (not included)

Feature Flags

  • host: Enables reference implementation for host-side execution
    • Guest code: Compile WITHOUT this feature
    • Prover code: Compile WITH this feature

Constants Reference

Comparison with Standard Implementation

  • Cycle count: ~10-50x reduction compared to pure Rust implementation
  • Proving time: Proportionally faster proof generation
  • Compatibility: Standard BLAKE2b output format

Security Properties

  • Collision resistance: 512 bits
  • Pre-image resistance: 512 bits
  • MAC security: Full key size (up to 64 bytes)

Source Code Location

See Also