Blake3 structv0.1.0
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
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.
| Name | Type | Description |
|---|---|---|
key | char8[..] | the key |
Returns: a hasher keyed with those thirty-two bytes
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.
| Name | Type | Description |
|---|---|---|
context | char8[..] | the application-specific context string, which must be a constant |
Returns: a hasher in key-derivation mode for that context
Implements Digest
Blake3 conforms to Digest.
Update
pub func Update(self: &var Blake3, bytes: char8[..])
Adds bytes to the message.
| Name | Type | Description |
|---|---|---|
bytes | char8[..] | the bytes to absorb |
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.
| Name | Type | Description |
|---|---|---|
into | var char8[..] | receives the output |
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
BlockLength
pub func BlockLength(self: &Blake3) -> uint
Sixty-four bytes.
Returns: how many bytes the compression function consumes at a time
Related
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.
Parameters
| Name | Type | Description |
|---|---|---|
chaining | *uint32 | the chaining value going in |
message | *uint32 | the message to authenticate |
counter | uint64 | the chunk counter |
blockLength | uint32 | how many bytes of the block are used |
flags | uint32 | the domain flags for this compression |
into | *var uint32 | receives 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.
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.
| Name | Type | Description |
|---|---|---|
bytes | char8[..] | the bytes to absorb |
Returns: how many bytes were absorbed
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.
| Name | Type | Description |
|---|---|---|
extraFlags | uint32 | the domain flags to add for this output |
into | *var uint32 | receives the output |
Blake3Of
pub func Blake3Of(bytes: char8[..], into: var char8[..])
The BLAKE3 hash of bytes, at whatever length into asks for.
Parameters
| Name | Type | Description |
|---|---|---|
bytes | char8[..] | the bytes to absorb |
into | var 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.
Parameters
| Name | Type | Description |
|---|---|---|
key | char8[..] | the key |
bytes | char8[..] | the bytes to absorb |
into | var 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.
Parameters
| Name | Type | Description |
|---|---|---|
context | char8[..] | the application-specific context string, which must be a constant |
material | char8[..] | the input keying material |
into | var char8[..] | receives the output |