macula_blake3_nif (macula v3.13.0)

View Source

BLAKE3 hashing with NIF acceleration and Erlang fallback.

This module provides BLAKE3 cryptographic hashing with automatic fallback to a pure Erlang implementation when NIFs are not available.

BLAKE3 is the primary hash algorithm for Macula content-addressed storage due to its speed (faster than SHA-256) and security.

Performance

The NIF implementation (via Rust blake3 crate) is approximately 10-20x faster than the pure Erlang fallback, especially for large inputs.

Usage

   %% Hash binary data
   Hash = macula_blake3_nif:hash(Data).
  
   %% Hash multiple chunks (streaming)
   Hash = macula_blake3_nif:hash_streaming([Chunk1, Chunk2, Chunk3]).
  
   %% Verify a hash
   true = macula_blake3_nif:verify(Data, ExpectedHash).
  
   %% Get hex-encoded hash
   HexHash = macula_blake3_nif:hash_hex(Data).

Summary

Functions

Hash binary data using BLAKE3. Returns a 32-byte hash.

Hash binary data and return hex-encoded string.

Hash multiple chunks using BLAKE3. Streaming hash - processes chunks without concatenating them.

Check if NIF is loaded.

Verify that data matches an expected BLAKE3 hash.

Functions

hash(Data)

-spec hash(binary()) -> binary().

Hash binary data using BLAKE3. Returns a 32-byte hash.

hash_hex(Data)

-spec hash_hex(binary()) -> binary().

Hash binary data and return hex-encoded string.

hash_streaming(Chunks)

-spec hash_streaming([binary()]) -> binary().

Hash multiple chunks using BLAKE3. Streaming hash - processes chunks without concatenating them.

is_nif_loaded()

-spec is_nif_loaded() -> boolean().

Check if NIF is loaded.

verify(Data, ExpectedHash)

-spec verify(binary(), binary()) -> boolean().

Verify that data matches an expected BLAKE3 hash.