Expand description
BLAKE3 extendable output function (XOF) implementation
This module provides a pure Rust implementation of the BLAKE3 cryptographic hash function in XOF (eXtendable Output Function) mode, allowing for arbitrary-length output generation.
§Overview
BLAKE3 is a cryptographic hash function that is:
- Fast: Optimized for modern CPUs with SIMD instructions
- Secure: Based on the well-analyzed ChaCha permutation
- Versatile: Supports hashing, keyed hashing, and key derivation
- Parallelizable: Can process multiple chunks simultaneously
- Incremental: Supports streaming/incremental hashing
§Security Properties
- Security Level: 256 bits (128-bit collision resistance)
- Output Size: Variable (unlimited in XOF mode)
- Key Size: 256 bits (32 bytes) for keyed variants
§Features
This implementation provides three modes of operation:
- Standard XOF: Variable-length output from input data
- Keyed XOF: HMAC-like keyed hashing with variable output
- Key Derivation: Derive keys from a context string and input data
§Implementation Notes
This implementation prioritizes correctness and security over performance:
- Uses secure memory handling with
SecretBuffer
for sensitive data - Implements proper zeroization of sensitive values
- Based directly on the BLAKE3 reference implementation
- Does not include SIMD optimizations
§Example Usage
ⓘ
use dcrypt_algorithms::xof::{Blake3Xof, ExtendableOutputFunction};
// Standard hashing with variable output
let data = b"Hello, BLAKE3!";
let output = Blake3Xof::generate(data, 64)?; // 64 bytes output
// Incremental hashing
let mut xof = Blake3Xof::new();
xof.update(b"Hello, ")?;
xof.update(b"BLAKE3!")?;
let mut output = vec![0u8; 64];
xof.squeeze(&mut output)?;
// Keyed hashing
let key = b"this is a 32-byte key for BLAKE3";
let output = Blake3Xof::keyed_generate(key, data, 32)?;
// Key derivation
let context = b"MyApp v1.0.0 session key";
let output = Blake3Xof::derive_key(context, data, 32)?;
§References
Structs§
- Blake3
Xof - BLAKE3 extendable output function