b3

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 10 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

b3

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.

single-thread BLAKE3 hash throughput by input size on an AMD Threadripper 9980X, GB/s

single-thread hash/xof throughput results vs. the fastest tested other implementation

machine hash (geomean) xof
threadripper 9980x (zen5) +26% +35%
ryzen ai 9 hx 370 (zen5, w/zen4 avx-512) +14% +9%
m6 mac mini +28% +315%
graviton 5 (c9g.xlarge) +35% +192%
core ultra x9 388H -4% +205%
granite rapids xeon (c8i.xlarge) -4% +7%

reducing performance

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).

b3sum

0u.io/b3sum is an interface-compatible command-line tool with upstream b3sum using this library.

more details.

project website. contact (including security).

Documentation

Overview

Package b3 implements the BLAKE3 hash function: hashing, keyed hashing, key derivation, and extendable output.

on amd64 and arm64 it runs asm kernels. the purego build tag does not use asm; add GOEXPERIMENT=simd and that build vectorizes through simd/archsimd.

Index

Constants

View Source
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
)

Variables

This section is empty.

Functions

func DeriveKey

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

func Sum256(data []byte) [Size]byte

Sum256 returns the unkeyed BLAKE3 digest of data.

func Sum256Keyed

func Sum256Keyed(key [KeySize]byte, data []byte) [Size]byte

Sum256Keyed returns the keyed BLAKE3 digest of data.

Types

type Error

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 (Error) Error

func (e Error) Error() string

type Hasher

type Hasher struct {
	// contains filtered or unexported fields
}

Hasher is a hash.Hash for streaming BLAKE3 state.

func New

func New(opts ...Option) *Hasher

New returns a Hasher for the regular hash mode.

func NewDeriveKey

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

func NewKeyed(key []byte, opts ...Option) *Hasher

NewKeyed returns a Hasher that uses the 32-byte key. it panics on any other length.

func (*Hasher) BlockSize

func (h *Hasher) BlockSize() int

BlockSize returns the compression block length (64).

func (*Hasher) Clone

func (h *Hasher) Clone() (hash.Cloner, error)

Clone returns an independent copy of the state. it never fails.

func (*Hasher) Reset

func (h *Hasher) Reset()

Reset restores the state to as-created, including key and mode if applicable.

func (*Hasher) Size

func (h *Hasher) Size() int

Size returns the digest length (32).

func (*Hasher) Sum

func (h *Hasher) Sum(b []byte) []byte

Sum appends the digest of the data written to b and returns the resulting slice.

func (*Hasher) Write

func (h *Hasher) Write(p []byte) (int, error)

Write absorbs p. it never fails.

func (*Hasher) XOF

func (h *Hasher) XOF() *OutputReader

XOF returns a reader over the output of the data written. the reader is an independent snapshot.

type Option

type Option func(*Hasher)

Option configures a Hasher.

func WithParallelism

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

type OutputReader struct {
	// contains filtered or unexported fields
}

OutputReader streams the output of a finalized hash. it implements io.Reader and io.Seeker.

func (*OutputReader) Read

func (r *OutputReader) Read(p []byte) (int, error)

func (*OutputReader) Seek

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.

Source Files

  • avx2_amd64.go
  • avx512_amd64.go
  • b3.go
  • chain.go
  • engine_amd64.go
  • engine_simd.go
  • errors.go
  • parallel.go
  • scalar_amd64.go
  • vendor_amd64.go
  • xof.go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL