NAME

Digest::BLAKE3 - Perl extension for the BLAKE3 hash function

SYNOPSIS

use Digest::BLAKE3;

my $hasher = Digest::BLAKE3::->new();

$hasher->add($data);
$hasher->addfile($filehandle);

$hash = $hasher->digest();

DESCRIPTION

The Digest::BLAKE3 module is a Perl wrapper for the libblake3 library providing the BLAKE3 hash function, as found at https://blake3.io/.

Because building libblake3 can get finicky (especially if you don't have the latest and greatest compiler versions), it is not included with this module. You have to build and install it yourself first.

The module provides the usual Digest::* family object-oriented interface.

METHODS

$class->new()
$hasher->new()

An alias for the new_hash method;

$class->new_hash()
$hasher->new_hash()

As a class method, creates a new hasher in hash mode. As an object method, reinitialises an existing hasher to use hash mode.

$class->new_keyed_hash($key)
$hasher->new_keyed_hash($key)

As a class method, creates a new hasher in keyed hash mode. As an object method, reinitialises an existing hasher to use keyed hash mode.

The key must be a 32-byte string.

$class->new_derive_key($context)
$hasher->new_derive_key($context)

As a class method, creates a new hasher in key derivation mode. As an object method, reinitialises an existing hasher to use key derivation mode.

The context is a byte string of any length.

$hasher->clone()

Returns a new hasher with the same state, mode, and output size as the original.

$hasher->reset()

Resets an existing hasher without changing its mode.

$hasher->add($bytes, ...)

Updates the hasher state with each of the given byte strings.

$hasher->addfile($filehandle)

Updates the hasher with all the bytes read from the given file handle until end-of-file.

$hasher->addfile($filename)

Opens the named file in binary mode and updates the hasher with the contents.

$hasher->digest()

Returns the final hash value as a byte string and resets the hasher.

$hasher->hexdigest()

Returns the final hash value as a hexadecimal text string and resets the hasher.

$hasher->b64digest()

Returns the final hash value as a base-64 text string and resets the hasher.

$hasher->hashsize()
$hasher->hashsize($hashsize)

Returns the current output hash size and optionally sets a new output hash size. The value is given in bits and must be a positive multiple of 8. The default is 256 bits.

$hasher->mode()

Returns the current mode as a string; one of "hash", "keyed_hash", or "derive_key".

AUTHOR

Bo Lindbergh <blgl@stacken.kth.se>