Skip to main content

Overview

The BLAKE3 inline provides an optimized implementation of the BLAKE3 hash function with 256-bit output. BLAKE3 is significantly faster than BLAKE2, SHA-1, SHA-2, and SHA-3 while maintaining security. The current implementation is optimized for inputs up to 64 bytes (single block).

API Reference

Blake3

Main hasher struct supporting both streaming and one-shot hashing.

Methods

new() -> Self
Creates a new BLAKE3 hasher.
update(&mut self, input: &[u8])
Writes data to the hasher incrementally. Panics if total input exceeds 64 bytes.
finalize(self) -> [u8; 32]
Finalizes the hash and returns the 32-byte digest.
digest(input: &[u8]) -> [u8; 32]
Computes BLAKE3 hash in one call. Input must be ≤64 bytes.

AlignedHash32

8-byte aligned 32-byte hash/key type for efficient operations.

Methods

blake3_keyed64()

BLAKE3 keyed hash for 64-byte inputs (Merkle tree optimization).
This is equivalent to blake3::keyed_hash(key, left || right) but optimized for when left and right are in separate memory locations.

Usage Examples

Basic Hashing (≤64 bytes)

Merkle Tree Parent Node

Streaming API (≤64 bytes total)

Implementation Details

Compression Function

BLAKE3 uses a ChaCha-like compression function:
  • State: 8 × 32-bit words (256 bits)
  • Message block: 16 × 32-bit words (512 bits)
  • Counter: 2 × 32-bit words (64 bits)
  • Flags: 1 × 32-bit word (32 bits)
  • Rounds: 7 rounds

Custom Instructions

  1. BLAKE3_COMPRESS (funct3=0x00, funct7=0x03): Standard compression
  2. BLAKE3_KEYED64 (funct3=0x01, funct7=0x03): Keyed 64-byte hash for Merkle trees

BLAKE3 Flags

Initialization Vector

Message Scheduling

Constants

Input Size Limitation

The current implementation only supports inputs up to 64 bytes (single block):
This is sufficient for:
  • Merkle tree nodes (2 × 32-byte hashes)
  • Small messages
  • Hash-based signatures
For larger inputs, use BLAKE2 or SHA-256 inlines instead.

Performance Characteristics

  • Block size: 64 bytes per compression
  • Output size: 32 bytes (256 bits)
  • Speed: Fastest among all hash inlines
  • Optimization: Specialized blake3_keyed64() for Merkle trees

Alignment Requirements

The AlignedHash32 type ensures 8-byte alignment for efficient 64-bit load/store operations:
This is critical for RISC-V performance.

Feature Flags

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

Comparison with Standard Implementation

When compared to the official blake3 crate:
  • Cycle count: ~10-50x reduction for single-block inputs
  • Proving time: Proportionally faster proof generation
  • Compatibility: Identical output to blake3::hash()

Source Code Location

See Also