prng

package
v0.3.8 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrInvalid = Error("invalid value")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error string

func (Error) Error

func (e Error) Error() string

type HMAC

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

HMAC is a deterministic HMAC-DRBG (NIST SP800-90A). It produces reproducible output for a given seed — used both for deterministic derivations (KDFs, ratchets, protocol-instance UIDs) and, wrapped in a Service, as the periodically-reseeded process entropy source.

func NewHMAC

func NewHMAC(h func() hash.Hash, seed, nonce []byte, info string) (hm *HMAC, err error)

the NIST Document specify a nonce, XXX TODO: check seed sizes and fail initialization if not enough..

func (*HMAC) Int

func (hm *HMAC) Int(n *big.Int) (a *big.Int, err error)

Int returns a uniform random value in [0, max). It panics if max <= 0.

func (*HMAC) Read

func (hm *HMAC) Read(p []byte) (n int, err error)

that's the generating algorithm mising the additionnal input thinggy

func (*HMAC) Update

func (hm *HMAC) Update(data []byte)

type PRNG

type PRNG interface {
	// equivalent to .bytes(l) -> r
	io.Reader
	// BigInt(n)
	Int(n *big.Int) (a *big.Int, err error)
}

this is the abstract type in the spec :)

func NewSync added in v0.2.0

func NewSync(inner PRNG) PRNG

NewSync returns a concurrency-safe wrapper around inner. Wrapping an already-synced PRNG is harmless.

type Service

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

Service is the process entropy source: a thread-safe HMAC-DRBG that periodically reseeds itself from the OS CSPRNG for prediction resistance (reference PRNGServiceHmacSHA256). Every reseedFrequency reads it mixes fresh crypto/rand entropy into the DRBG state, so a one-time state compromise cannot predict future output. Use NewHMAC directly (no reseed) where deterministic output is required — KDFs, ratchets, protocol-instance UIDs.

func NewService

func NewService(h func() hash.Hash) (*Service, error)

NewService creates a reseeding DRBG service seeded from crypto/rand, using hash h (e.g. sha256.New).

func (*Service) Int

func (s *Service) Int(n *big.Int) (*big.Int, error)

Int returns a uniform random value in [0, n). Reads go through the (locked, reseeding) DRBG.

func (*Service) Read

func (s *Service) Read(p []byte) (int, error)

Read fills p with DRBG output and, every reseedFrequency reads, mixes in fresh OS entropy.

Jump to

Keyboard shortcuts

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