Documentation ¶
Index ¶
- func CalculateModuloBias(maxValue *big.Int, requiredBytes int) *big.Int
- func GenerateSecureRandom(keySize int) ([]byte, error)
- func PRF(h hash.Hash, seed []byte) []byte
- func RandInInterval(max *big.Int, seed []byte, h hash.Hash) *big.Int
- func ReadRangeUint32(start, end uint32, rng io.Reader) uint32
- func ReadUint32(rng io.Reader) uint32
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalculateModuloBias ¶
To remove modulo bias, we must calculate RAND_MAX - (RAND_MAX % N) Since we use a PRF that outputs a specific number of bytes (requiredBytes) RAND_MAX = ((2**(8*requiredBytes)) - 1) N = maxValue CalculateModuloBias returns those two values and returns the upper bound to avoid modulo bias
func GenerateSecureRandom ¶
GenerateSecureRandom receives the number of desired randomness bytes and returns a slice of that size from Crypto.Rand
func RandInInterval ¶
RandInInterval receives a seed and returns a random value (using a PRF) between [0, max-1]
func ReadRangeUint32 ¶
ReadRangeUint32 reduces a random integer from 0, MaxUint32 to greater than or equal to start and less than end
The reason start is inclusive and end is not is that this function is meant to work with lists (i.e., get random element inside the list, except for the first 3)
func ReadUint32 ¶
ReadUint32 reads an integer from an io.Reader (which should be a CSPRNG).
Types ¶
This section is empty.