Browse the docs

silk.crypto.blake2b.

Portable BLAKE2b-512 state for the unkeyed 64-byte cryptographic digest of RFC 7693.

When to use#

Use Blake2b512 where a format names BLAKE2b with a 64-byte digest, such as prehashed minisign signatures. Use silk.crypto.sha2 where a protocol names SHA-2. Use silk.collections.hash only for collection keys. It is not a cryptographic hash.

Details#

The state supports incremental input through update, consuming finalization through finish, and one-shot input through hash. It uses only inline storage and allocates no memory. The digest is the little-endian encoding of the final state words, as RFC 7693 specifies.

Gotchas#

Keyed hashing, salts, personalization and digest lengths other than 64 bytes are not supported. If an update makes the message longer than 2^128 - 1 bytes, the program traps. finish consumes its state, so the program cannot update or finish that state again.

Examples#

Hash a short message#

silk
import silk.crypto.blake2b {Blake2b512}

pub fn main() -> i32 {
  let message: [u8; 3] = [97, 98, 99]
  let digest = Blake2b512.hash(&message)
  if digest[0] != 186 || digest[63] != 35 {
    return 1
  }
  return 0
}

Import as Blake2b512 with import silk.crypto.blake2b { Blake2b512 }.

Public declarations: 1.

Blake2b512#

silk
pub struct Blake2b512

An incremental unkeyed BLAKE2b state with a 64-byte digest (RFC 7693).

When to use#

Use it where a format names BLAKE2b with a 64-byte digest, such as prehashed minisign signatures. Use silk.crypto.sha2 where a protocol names SHA-2. Use silk.collections.hash only for collection keys. It is not a cryptographic hash.

Details#

Give input in parts with Blake2b512.update and get the digest with Blake2b512.finish, or hash one slice with Blake2b512.hash. The state uses only inline storage and allocates no memory. The digest is the little-endian encoding of the final state words.

Gotchas#

Keyed hashing, salts, personalization and digest lengths other than 64 bytes are not supported. If an update makes the message longer than 2^128 - 1 bytes, the program traps.

Implementation Blake2b512#

silk
impl Blake2b512

Associated function make#

silk
pub fn make() -> Blake2b512

Creates an empty BLAKE2b-512 state.

Method update#

silk
pub fn update(self: &mut Self, bytes: &[u8]) -> ()

Adds bytes to this state in source order. An empty slice does not change the state.

Details#

A full block is compressed only when more input follows it, because the final block is compressed with the finalization flag. It allocates no memory.

Gotchas#

If an update makes the message longer than 2^128 - 1 bytes, the program traps.

Method finish#

silk
pub fn finish(self: Self) -> [u8; 64]

Consumes this state and returns its 64-byte digest.

Gotchas#

The state is consumed, so the program cannot update or finish it again. Use Blake2b512.hash for one slice.

Associated function hash#

silk
pub fn hash(bytes: &[u8]) -> [u8; 64]

Returns the 64-byte BLAKE2b digest of bytes.

Category: Cryptography.

Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2.

View the source of this page