Blake3 structv0.1.0

Source
An incremental BLAKE3 hash.
pub struct Blake3 {
    // private fields
}

Structural Copy; copying takes an independent snapshot of the hash tree state.

Constructors

Blake3

pub func Blake3() -> Blake3

An unkeyed BLAKE3 hash.

Returns: a hasher with nothing absorbed

Source

Associated functions

NewKeyed

pub func NewKeyed(key: char8[..]) -> Blake3

A keyed BLAKE3 hash: a message authentication code. key must be exactly thirty-two bytes; a shorter one is padded with zeros, which is a caller error rather than a supported shortening — a key with less entropy than the algorithm expects is weaker than it looks, and padding it hides that rather than fixing it. Unlike SHA-2, this needs no nested construction: BLAKE3 resists length extension, so starting the tree from the key is a sound MAC on its own.

NameTypeDescription
keychar8[..]the key

Returns: a hasher keyed with those thirty-two bytes

Source

NewDeriveKey

pub func NewDeriveKey(context: char8[..]) -> Blake3

A BLAKE3 state deriving output under context. The context string names what the derived key is for, and it is hashed separately from the key material so that two derivations from the same material under different contexts are unrelated. It should be a hard-coded, globally unique string — an application name, a purpose, and a date — and it must not be a variable, since two callers who accidentally share one lose the separation entirely.

NameTypeDescription
contextchar8[..]the application-specific context string, which must be a constant

Returns: a hasher in key-derivation mode for that context

Source

Implements Digest

Blake3 conforms to Digest.

Update

pub func Update(self: &var Blake3, bytes: char8[..])

Adds bytes to the message.

NameTypeDescription
byteschar8[..]the bytes to absorb

Source

Finish

pub func Finish(self: &var Blake3, into: var char8[..])

Writes the root output into into, which may be any length. BLAKE3's output is extendable like SHAKE's: the root compression repeats with an increasing counter to produce as many bytes as asked. Thirty-two is the usual choice and is what DigestLength reports.

NameTypeDescription
intovar char8[..]receives the output

Source

DigestLength

pub func DigestLength(self: &Blake3) -> uint

Thirty-two bytes, the conventional length; Finish writes any length asked of it.

Returns: how many bytes a digest occupies

Source

BlockLength

pub func BlockLength(self: &Blake3) -> uint

Sixty-four bytes.

Returns: how many bytes the compression function consumes at a time

Source

Blake3Compress

pub func Blake3Compress(
    chaining: *uint32,
    message: *uint32,
    counter: uint64,
    blockLength: uint32,
    flags: uint32,
    into: *var uint32
)

The compression function: sixteen words of state over seven rounds, producing sixteen words of output. The first eight output words are the chaining value; all sixteen are used when the output is being extended.

Source

Parameters

NameTypeDescription
chaining*uint32the chaining value going in
message*uint32the message to authenticate
counteruint64the chunk counter
blockLengthuint32how many bytes of the block are used
flagsuint32the domain flags for this compression
into*var uint32receives the output

Blake3Chunk

pub struct Blake3Chunk {
    // private fields
}

The state of one chunk being filled. Structural Copy; used as an independent snapshot within the enclosing hasher.

Source

Methods

Update

pub func Update(
    self: &var Blake3Chunk,
    bytes: char8[..]
) -> uint

Adds bytes to the chunk, compressing whole blocks as they complete. A block is only compressed once the next byte arrives, never when it merely becomes full: the last block of a chunk carries the end flag, and which block is last is not known until the chunk stops growing. Compressing eagerly is the classic way to get the flags wrong.

NameTypeDescription
byteschar8[..]the bytes to absorb

Returns: how many bytes were absorbed

Source

Output

pub func Output(
    self: &Blake3Chunk,
    extraFlags: uint32,
    into: *var uint32
)

The chunk's chaining value, with the end flag applied to its final block. extraFlags carries the root flag when this chunk is the whole message.

NameTypeDescription
extraFlagsuint32the domain flags to add for this output
into*var uint32receives the output

Source

Blake3Of

pub func Blake3Of(bytes: char8[..], into: var char8[..])

The BLAKE3 hash of bytes, at whatever length into asks for.

Source

Parameters

NameTypeDescription
byteschar8[..]the bytes to absorb
intovar char8[..]receives the output

Blake3KeyedOf

pub func Blake3KeyedOf(
    key: char8[..],
    bytes: char8[..],
    into: var char8[..]
)

The keyed BLAKE3 hash of bytes under key, in one call.

Source

Parameters

NameTypeDescription
keychar8[..]the key
byteschar8[..]the bytes to absorb
intovar char8[..]receives the output

Blake3DeriveKey

pub func Blake3DeriveKey(
    context: char8[..],
    material: char8[..],
    into: var char8[..]
)

A key derived from material under context, at whatever length into asks for.

Source

Parameters

NameTypeDescription
contextchar8[..]the application-specific context string, which must be a constant
materialchar8[..]the input keying material
intovar char8[..]receives the output