random

package
v0.0.0-...-2f25eea Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2016 License: BSD-3-Clause Imports: 5 Imported by: 15

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

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 NewSource

func NewSource(name string, seed []byte) Source

NewSource initializes a Source object with the given name and seed.

func (*Source) Dirichlet

func (rs *Source) Dirichlet(label []byte, length, sum int) []int

Dirichlet takes a (possibly public) label and produces the output of a uniform dirichlet distribution with `length` variables, summing to `sum`.

func (*Source) Matrix

func (rs *Source) Matrix(label []byte, size int) matrix.Matrix

Matrix takes a (possibly public) label and produces a random non-singular matrix.

func (*Source) Monotone

func (rs *Source) Monotone(label []byte, length, max int) []int

Monotone takes a (possibly public) label and produces a random monotone function which is `length` units long and maximizes at `max`.

func (*Source) SBox

func (rs *Source) SBox(label []byte) encoding.SBox

SBox takes a (possibly public) label and produces a random S-box.

func (*Source) Shuffle

func (rs *Source) Shuffle(label []byte) encoding.Shuffle

Shuffle takes a (possibly public) label and produces a random shuffle of the integers [0, 16).

func (*Source) Stream

func (rs *Source) Stream(label []byte) io.Reader

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.

Jump to

Keyboard shortcuts

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