Search documentation of macula

# macula_blake3_nif (macula v4.4.9)

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(Data)

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

hash_hex(Data)

Hash binary data and return hex-encoded string.

hash_streaming(Chunks)

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

is_nif_loaded()

Check if NIF is loaded. Note: returns the LAST observed state — a `false` here may mean the NIF hasn't been triggered to load yet (its `-on_load` fires only on first module reference). Callers that NEED the NIF status to be definitive should use `ensure_crypto_nif_loaded/0` which forces module-load first.

verify(Data, ExpectedHash)

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. Note: returns the LAST observed state — a `false` here may mean the NIF hasn't been triggered to load yet (its `-on_load` fires only on first module reference). Callers that NEED the NIF status to be definitive should use `ensure_crypto_nif_loaded/0` which forces module-load first.

# verify(Data, ExpectedHash)

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

Verify that data matches an expected BLAKE3 hash.