Pure Elm implementation of the BLAKE2b cryptographic hash function (RFC 7693).
No kernel code, no ports, no JS FFI — just Elm.
elm install elm-cardano/blake2bpnpm install
pnpm test # run tests
pnpm review # run elm-review
pnpm format:check # check formatting
pnpm format # auto-formatimport Blake2b512
Blake2b512.fromString "hello" -- Digest
Blake2b512.fromBytes bytes -- Digest
Blake2b512.fromByteValues [0x68, 0x69] -- Digest
Blake2b512.toHex digest -- String
Blake2b512.toBase64 digest -- String
Blake2b512.toBytes digest -- Bytes
Blake2b512.toByteValues digest -- List IntThe same API is exposed by Blake2b224 and Blake2b256.
For custom digest lengths or keyed hashing, use the Blake2b module:
import Blake2b
import Bytes.Encode as Encode
Blake2b.fromString
{ digestLength = 48
, key = Encode.encode (Encode.string "secret")
}
"hello"
|> Blake2b.toHex64-bit arithmetic is emulated using pairs of 32-bit integers.
All intermediate values in the compression function are let bindings on raw Int pairs, which compile to plain JS variables with zero allocation.
This keeps garbage collection pressure low and makes the implementation practical for real use.
For details on the optimization journey, see docs/IMPLEMENTATION.md. Benchmarking infrastructure lives in the bench/ folder.
Tested against:
BLAKE2b-512(""), BLAKE2b-512("abc"))BSD-3-Clause