Documentation ¶
Overview ¶
Package random implements the generation of random objects with controlled, cryptographically secure randomness.
Three parameters matter: the name and seed of the randomness source, and the label given when requesting an object. If all of these three parameters are the same, the objects returned will be the same--if they're different, the returned object will likely be different. To prevent an adversary from being able to predict what will be returned, the only parameter that needs to be kept secret is the seed of the randomness source.
Index ¶
- type Source
- func (rs *Source) Dirichlet(label []byte, length, sum int) []int
- func (rs *Source) Matrix(label []byte, size int) matrix.Matrix
- func (rs *Source) Monotone(label []byte, length, max int) []int
- func (rs *Source) SBox(label []byte) encoding.SBox
- func (rs *Source) Shuffle(label []byte) encoding.Shuffle
- func (rs *Source) Stream(label []byte) io.Reader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Source ¶
type Source struct { // The name of the randomness source--an arbitrary string. Name string // A 16-byte truly random seed. Seed []byte // contains filtered or unexported fields }
Source implements generators of random objects. It also maintains a cache to speed up generation, in cases where the same object may be requested many times.
func (*Source) Dirichlet ¶
Dirichlet takes a (possibly public) label and produces the output of a uniform dirichlet distribution with `length` variables, summing to `sum`.
func (*Source) Matrix ¶
Matrix takes a (possibly public) label and produces a random non-singular matrix.
func (*Source) Monotone ¶
Monotone takes a (possibly public) label and produces a random monotone function which is `length` units long and maximizes at `max`.
func (*Source) Shuffle ¶
Shuffle takes a (possibly public) label and produces a random shuffle of the integers [0, 16).
func (*Source) Stream ¶
Stream takes a (possibly public) label and produces an io.Reader giving random bytes, useful for deterministically generating random matrices/encodings, in place of (crypto/rand).Reader.
It does this by using the seed as an AES key and the label as the IV in CTR mode. The io.Reader is providing the AES-CTR encryption of /dev/null.