random

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2019 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package random provides a feedable CSPRNG.

CSPRNG used is fortuna: github.com/seehuhn/fortuna By default the CSPRNG is fed by two sources: - OS RNG - Entropy gathered by context switching

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.

func Start

func Start() (err error)

Start starts the RNG. Normally, this should be only called by the portbase/modules package.

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.

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 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 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 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 to the Feeder, but will not block if no entropy is currently needed.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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