hashprf

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package hashprf builds keyed pseudo-random functions over six hash-based ITB registry primitives, exposing each as a fixed-output-width PRF.

The six primitives split into two families:

  • Areion family ("areion256", "areion512") — keyed via the ITB registry HashFunc factories (hashes.Areion256PairWithKey / hashes.Areion512PairWithKey). The PRF hashes the input under a zero seed and serialises the resulting uint64 words little-endian.
  • BLAKE family ("blake2b256", "blake2s", "blake3", "blake2b512") — keyed via the upstream keyed-hash mode. The PRF output is the leading blockSize bytes of the keyed digest over the input.

The Areion family additionally exposes a 4-wide batched PRF via NewBatch: it hashes four inputs in one SIMD batch (bit-exact with the single-input PRF), which the ctr keystream uses to amortise per-block dispatch. The BLAKE family has no batch path, and NewBatch reports none for those names.

The package is a shared dependency of the ctr and kdf packages, which import it for their keyed-PRF and SP 800-108 counter-mode constructions respectively. It imports the BLAKE upstream packages and the ITB hashes package; it does not import ctr or kdf, so no import cycle arises.

Index

Constants

View Source
const (
	Areion256  = "areion256"
	Areion512  = "areion512"
	BLAKE2b256 = "blake2b256"
	BLAKE2b512 = "blake2b512"
	BLAKE2s    = "blake2s"
	BLAKE3     = "blake3"
)

Registry names accepted by New, NewBatch, KeySize, and BlockSize.

Variables

This section is empty.

Functions

func BlockSize

func BlockSize(name string) (int, error)

BlockSize returns the PRF output width in bytes for the named primitive.

func KeySize

func KeySize(name string) (int, error)

KeySize returns the byte length of the key for the named primitive.

func New

func New(name string, key []byte) (prf func(dst, in []byte), blockSize int, err error)

New returns a keyed PRF for one of the six hash-based primitives and its output block size. The key length must equal the primitive's key size; a mismatched length or an unknown name is an error.

The returned prf writes exactly blockSize bytes into dst[:blockSize], so dst must have len(dst) >= blockSize. The returned prf is not safe for concurrent use; it reuses internal hasher state and is intended for serial, single-stream use.

func NewBatch

func NewBatch(name string, key []byte) (batch func(dst, in *[4][]byte), blockSize int, ok bool, err error)

NewBatch returns a 4-wide batched keyed PRF for the primitives that expose a SIMD batch path, together with the per-lane output block size. ok reports whether a batch path exists for name: only the Areion family does (via the registry BatchHashFunc factories, which are bit-exact with the single-input HashFunc), so a batched keystream over those primitives produces output byte-identical to the single-block PRF. ok is false for the BLAKE family, whose registry factories expose no 4-wide batch; callers fall back to New.

The returned batch closure fills dst[0..3] (each at least blockSize bytes) from in[0..3]. It is bound to one keystream / KDF instance and driven sequentially, like the New closures.

Types

This section is empty.

Jump to

Keyboard shortcuts

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