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