React Native Quick Crypto
API Reference

BLAKE3

High-performance cryptographic hashing

BLAKE3 is a cryptographic hash function that is roughly 15x faster than SHA-2 on modern processors, while maintaining a high security margin.

Table of Contents

Theory

Unlike MD5 or SHA-2 which process data sequentially, BLAKE3 uses a Merkle Tree.

  • The data stream is cut into 1 KiB chunks.
  • Each chunk is hashed independently.
  • Each chunk is hashed independently.
  • The hashes are combined in a binary tree.

This structure allows massive parallelism (using SIMD instructions like AVX2/NEON), enabling multi-GB/s throughput.

It naturally supports:

  • Keyed Hashing: Acts as a MAC without HMAC construction overhead.
  • Key Derivation: Using "context strings" to separate domains.
  • XOF: Extendable Output Function (variable length output).

Class: Blake3

createBlake3([options])

Creates a Blake3 instance.

Parameters:

Prop

Type

Returns: Blake3

blake3.update(data)

Updates the hash state.

Parameters:

Prop

Type

blake3.digest([encoding])

Returns the standard 32-byte (256-bit) digest.

blake3.digestLength(length[, encoding])

Returns a digest of arbitrary length bytes (XOF).

Example:

const keyAndIV = hash.digestLength(44); // 32 byte key + 12 byte IV

blake3.reset()

Resets the hash state.


Real-World Examples

Key Derivation (KDF)

Using contexts to derive different keys from one master secret.

import { createBlake3 } from 'react-native-quick-crypto';
import { Buffer } from 'buffer';

const masterKey = Buffer.from('...'); // 32 bytes high-entropy

function deriveKeys(master: Buffer) {
    // Derive Encryption Key
    const enc = createBlake3({ context: 'my-app-v1-encryption' });
    enc.update(master);
    const encryptionKey = enc.digest();
    
    // Derive Signing Key
    const sign = createBlake3({ context: 'my-app-v1-signing' });
    sign.update(master);
    const signingKey = sign.digest();
    
    return { encryptionKey, signingKey };
}

On this page