Skip to content
FutureBlitz

    Install

    Import std.crypto.blake3

    Blake3

    std.crypto.blake3

    class

    Public Class Blake3 Implements Hasher

    BLAKE3's hash of what's added in turn, of any length, for checksums, keys, and anything else a fast cryptographic hash fits.

    Examples

    Local hash = Blake3.Hash("abc")
    Expect(hash.Count == 32)
    Local hasher = Blake3()
    hasher.Add("a")
    hasher.Add("bc")
    Expect(hasher.Finish() == hash)
    Expect(Blake3.Hash("abc", 64).Count == 64)

    std/crypto/blake3.fb, line 31

    • Public New() constructor #

      A plain hash.

    • @PanicsAtCaller Public Static Method Keyed(key: UInt8[]): Blake3 static method #

      A hasher whose hash is a MAC with key, 32 bytes. Panics unless key is 32 bytes.

    • Public Static Method DerivingKey(context: String): Blake3 static method #

      A hasher whose hash is a key for context, from the material added: context, fixed in the program, says what the key is for, like "example.com save files, version 1", so keys for different uses differ.

    • @PanicsAtCaller Public Static Method Hash(data: UInt8[], length: Int = 32): UInt8[] static method #

      data's hash, length bytes long. Panics when length is negative.

    • @PanicsAtCaller Public Static Method Hash(text: String, length: Int = 32): UInt8[] static method #

      The hash of text's UTF-8 bytes, length bytes long. Panics when length is negative.

    • @PanicsAtCaller Public Static Method KeyedHash(key: UInt8[], data: UInt8[], length: Int = 32): UInt8[] static method #

      data's MAC with key, 32 bytes. Panics unless key is 32 bytes, or when length is negative.

    • @PanicsAtCaller Public Static Method DeriveKey(context: String, material: UInt8[], length: Int = 32): UInt8[] static method #

      A key for context from material. Panics when length is negative.

      Examples

      Local material = SecureRandom.Bytes(32)
      Local saves = Blake3.DeriveKey("example.com save files, version 1", material)
      Local tokens = Blake3.DeriveKey("example.com session tokens, version 1", material)
      Expect(saves.Count == 32 && saves != tokens)
    • Public Method Add(data: UInt8[]) method #

      Adds data to what it hashes.

    • Public Method Add(text: String) method #

      Adds text's UTF-8 bytes to what it hashes.

    • Public Method Finish(): UInt8[] method #

      The 32-byte hash of what was added, after which the hasher starts again, empty.

    • @PanicsAtCaller Public Method Finish(length: Int): UInt8[] method #

      The same, length bytes long, the first 32 of which are the 32-byte hash. Panics when length is negative.

    Report an issue with this page or with FutureBlitz on GitHub.