rng

package
v1.6.24 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2024 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package rng provides a feedable CSPRNG.

CSPRNG used is fortuna: github.com/seehuhn/fortuna By default the CSPRNG is fed by two sources: - It starts with a seed from `crypto/rand` and periodically reseeds from there - A really simple tickfeeder which extracts entropy from the internal go scheduler using goroutines and is meant to be used under load.

The RNG can also be easily fed with additional sources.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Reader provides a global instance to read from the RNG.
	Reader io.Reader
)

Functions

func Bytes

func Bytes(n int) ([]byte, error)

Bytes allocates a new byte slice of given length and fills it with random data.

func Number

func Number(max uint64) (uint64, error)

Number returns a random number from 0 to (incl.) max.

func Read

func Read(b []byte) (n int, err error)

Read reads random bytes into the supplied byte slice.

Types

type Feeder

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

The Feeder is used to feed entropy to the RNG.

func NewFeeder

func NewFeeder() *Feeder

NewFeeder returns a new entropy Feeder.

func (*Feeder) CloseFeeder

func (f *Feeder) CloseFeeder()

CloseFeeder stops the feed processing - the responsible goroutine exits. The input channel is closed and the feeder may not be used anymore in any way.

func (*Feeder) NeedsEntropy

func (f *Feeder) NeedsEntropy() bool

NeedsEntropy returns whether the feeder is currently gathering entropy.

func (*Feeder) SupplyEntropy

func (f *Feeder) SupplyEntropy(data []byte, entropy int)

SupplyEntropy supplies entropy to the Feeder, it will block until the Feeder has read from it.

func (*Feeder) SupplyEntropyAsInt

func (f *Feeder) SupplyEntropyAsInt(n int64, entropy int)

SupplyEntropyAsInt supplies entropy to the Feeder, it will block until the Feeder has read from it.

func (*Feeder) SupplyEntropyAsIntIfNeeded

func (f *Feeder) SupplyEntropyAsIntIfNeeded(n int64, entropy int)

SupplyEntropyAsIntIfNeeded supplies entropy to the Feeder, but will not block if no entropy is currently needed.

func (*Feeder) SupplyEntropyIfNeeded

func (f *Feeder) SupplyEntropyIfNeeded(data []byte, entropy int)

SupplyEntropyIfNeeded supplies entropy to the Feeder, but will not block if no entropy is currently needed.

type Rng

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

Rng is a random number generator.

func New

func New(instance instance) (*Rng, error)

New returns a new rng.

func (*Rng) Manager

func (r *Rng) Manager() *mgr.Manager

Manager returns the module manager.

func (*Rng) Start

func (r *Rng) Start() error

Start starts the module.

func (*Rng) Stop

func (r *Rng) Stop() error

Stop stops the module.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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