sampling

package
v5.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2023 License: Apache-2.0 Imports: 6 Imported by: 1

Documentation

Overview

Package sampling implements secure sampling of bytes and integers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RandComplex128

func RandComplex128(min, max float64) complex128

RandComplex128 returns a random complex with the real and imaginary part between min and max.

func RandFloat64

func RandFloat64(min, max float64) float64

RandFloat64 returns a random float between min and max.

func RandInt

func RandInt(max *big.Int) (n *big.Int)

RandInt generates a random Int in [0, max-1].

func RandUint64

func RandUint64() uint64

RandUint64 return a random value between 0 and 0xFFFFFFFFFFFFFFFF.

Types

type KeyedPRNG

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

KeyedPRNG is a structure storing the parameters used to securely and deterministically generate shared sequences of random bytes among different parties using the hash function blake2b. Backward sequence security (given the digest i, compute the digest i-1) is ensured by default, however forward sequence security (given the digest i, compute the digest i+1) is only ensured if the KeyedPRNG is keyed.

func NewKeyedPRNG

func NewKeyedPRNG(key []byte) (*KeyedPRNG, error)

NewKeyedPRNG creates a new instance of KeyedPRNG. Accepts an optional key, else set key=nil which is treated as key=[]byte{} WARNING: A PRNG INITIALISED WITH key=nil IS INSECURE!

func NewPRNG

func NewPRNG() (*KeyedPRNG, error)

NewPRNG creates KeyedPRNG keyed from rand.Read for instances were no key should be provided by the user

func (*KeyedPRNG) Key

func (prng *KeyedPRNG) Key() (key []byte)

Key returns a copy of the key used to seed the PRNG. This value can be used with `NewKeyedPRNG` to instantiate a new PRNG that will produce the same stream of bytes.

func (*KeyedPRNG) Read

func (prng *KeyedPRNG) Read(sum []byte) (n int, err error)

Read reads bytes from the KeyedPRNG on sum.

func (*KeyedPRNG) Reset

func (prng *KeyedPRNG) Reset()

Reset resets the PRNG to its initial state.

type PRNG

type PRNG interface {
	io.Reader
}

PRNG is an interface for secure (keyed) deterministic generation of random bytes

Jump to

Keyboard shortcuts

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