go implementation of BLAKE3. it's dependency-free (golang.org/x/sys doesn't count). it focuses on high performance on modern platforms; it has AVX2, NEON, SVE2, SME (on apple silicon), and AVX-512 kernels. of note, the AVX-512 kernels interleave two 16-chunk groups to keep the vector ports busy; this is a win everywhere, but in particular on full-width (server/desktop) zen5 (which has 2-cycle vector integer ops) this is responsible for about a 37% improvement in the leaf kernel.
golang.org/x/sys
one thread · AMD Ryzen Threadripper 9980X 64-Cores · linux/amd64
input size (K = KiB, M = MiB), log scale
AMD Ryzen Threadripper 9980X 64-Cores · linux/amd64
default thread count · AMD Ryzen Threadripper 9980X 64-Cores · linux/amd64
input size
one thread · AMD Ryzen AI 9 HX 370 w/ Radeon 890M · linux/amd64
AMD Ryzen AI 9 HX 370 w/ Radeon 890M · linux/amd64
default thread count · AMD Ryzen AI 9 HX 370 w/ Radeon 890M · linux/amd64
one thread · Intel(R) Core(TM) Ultra X9 388H · linux/amd64
Intel(R) Core(TM) Ultra X9 388H · linux/amd64
default thread count · Intel(R) Core(TM) Ultra X9 388H · linux/amd64
one thread · Intel(R) Xeon(R) 6975P-C · linux/amd64
Intel(R) Xeon(R) 6975P-C · linux/amd64
default thread count · Intel(R) Xeon(R) 6975P-C · linux/amd64
one thread · Apple M6 · darwin/arm64
Apple M6 · darwin/arm64
default thread count · Apple M6 · darwin/arm64
one thread · Neoverse V3 (part 0xd84) · linux/arm64
Neoverse V3 (part 0xd84) · linux/arm64
default thread count · Neoverse V3 (part 0xd84) · linux/arm64
Command b3sum computes and checks BLAKE3 checksums, compatible with the upstream b3sum.
go install 0u.io/b3sum@latest
b3sum --tag *.tar.zst > SUMS
b3sum --check SUMS
0u.io/b3 is cgo-free but uses liberal amounts of asm everywhere; it does support the purego build tag to fall back to the scalar implementation. it also supports GOEXPERIMENT=simd (in conjunction with purego).
0u.io/b3
purego
GOEXPERIMENT=simd
import "0u.io/b3"
const ( // Size is the default digest length in bytes. Size = 32 // BlockSize is the compression block length in bytes. BlockSize = 64 // KeySize is the key length for NewKeyed in bytes. KeySize = 32 )
func DeriveKey(context string, material []byte) [Size]byte
DeriveKey returns the 32-byte key derived from material in the given context. context should be a hardcoded, globally unique application string.
func Sum256(data []byte) [Size]byte
Sum256 returns the unkeyed BLAKE3 digest of data.
func Sum256Keyed(key [KeySize]byte, data []byte) [Size]byte
Sum256Keyed returns the keyed BLAKE3 digest of data.
type Error string
Error is the type of every error this package returns.
const ( ErrXOFSeekEnd Error = "cannot seek from end of xof" ErrXOFSeekWhence Error = "bad seek whence" ErrXOFSeekNegative Error = "negative xof offset" ErrXOFSeekOverflow Error = "xof position exceeds int64" )
func (e Error) Error() string
type Hasher struct { // contains filtered or unexported fields }
Hasher is a hash.Hash for streaming BLAKE3 state.
func New(opts ...Option) *Hasher
New returns a Hasher for the regular hash mode.
func NewDeriveKey(context string, opts ...Option) *Hasher
NewDeriveKey returns a Hasher for the key derivation mode: write the key material, read the derived key out. context should be a hardcoded, globally unique application string.
func NewKeyed(key []byte, opts ...Option) *Hasher
NewKeyed returns a Hasher that uses the 32-byte key. it panics on any other length.
func (h *Hasher) BlockSize() int
BlockSize returns the compression block length (64).
func (h *Hasher) Clone() (hash.Cloner, error)
Clone returns an independent copy of the state. it never fails.
func (h *Hasher) Reset()
Reset restores the state to as-created, including key and mode if applicable.
func (h *Hasher) Size() int
Size returns the digest length (32).
func (h *Hasher) Sum(b []byte) []byte
Sum appends the digest of the data written to b and returns the resulting slice.
func (h *Hasher) Write(p []byte) (int, error)
Write absorbs p. it never fails.
func (h *Hasher) XOF() *OutputReader
XOF returns a reader over the output of the data written. the reader is an independent snapshot.
type Option func(*Hasher)
Option configures a Hasher.
func WithParallelism(n int) Option
WithParallelism enables multi-goroutine hashing of large writes, with at most n workers; n <= 0 picks automatically. applying it to a live Hasher between Writes is supported.
type OutputReader struct { // contains filtered or unexported fields }
OutputReader streams the output of a finalized hash. it implements io.Reader and io.Seeker.
func (r *OutputReader) Read(p []byte) (int, error)
func (r *OutputReader) Seek(offset int64, whence int) (int64, error)
Seek repositions the stream. offsets past 2^63-1 are rejected because io.Seeker returns an int64, and io.SeekEnd is rejected outright.