botan-low-0.0.1.0: Low-level Botan bindings
Copyright(c) Leo D 2023
LicenseBSD-3-Clause
Maintainerleo@apotheca.io
Stabilityexperimental
PortabilityPOSIX
Safe HaskellSafe-Inferred
LanguageHaskell2010

Botan.Low.RNG

Description

Pseudo-random number generation.

Synopsis

Random number generators

A `random number generator` is used to generate uniform samples of pseudorandom bytes.

Usage

You can always use the system RNG:

import Botan.Low.RNG
randomBytes <- systemRNGGet 16

Unless you need a specific RNG, it is strongly recommended that you use the autoseeded user RNG.

import Botan.Low.RNG
rng <- rngInit "user"
randomBytes <- rngGet rng 16

You can reseed a generator using the system generator:

rngReseed rng 64

You can also reseed a generator using a specific generator:

systemRNG <- rngInit "system"
rngReseedFromRNG rng systemRNG 64

You can also seed it with your own entropy; this is safe and can never *decrease* the amount of entropy in the generator.

rngAddEntropy rng "Fee fi fo fum!"

newtype RNG Source #

Constructors

MkRNG 

Fields

withRNG :: RNG -> (BotanRNG -> IO a) -> IO a Source #

rngInit Source #

Arguments

:: RNGType

rng_type: type of the rng

-> IO RNG

rng

Initialize a random number generator object

rng_type has the possible values:

  • "system": system RNG
  • "user": userspace RNG
  • "user-threadsafe": userspace RNG, with internal locking
  • "rdrand": directly read RDRAND

Set rng_type to null to let the library choose some default.

rngDestroy :: RNG -> IO () Source #

Destroy a random number generator object immediately

rngGet Source #

Arguments

:: RNG

rng: rng object

-> Int

out_len: number of requested bytes

-> IO ByteString

out: output buffer of size out_len

Get random bytes from a random number generator

systemRNGGet Source #

Arguments

:: Int

out_len: number of requested bytes

-> IO ByteString

out: output buffer of size out_len

Get random bytes from system random number generator

rngReseed Source #

Arguments

:: RNG

rng: rng object

-> Int

bits: number of bits to reseed with

-> IO () 

Reseed a random number generator

Uses the System_RNG as a seed generator.

rngReseedFromRNG Source #

Arguments

:: RNG

rng: rng object

-> RNG

source_rng: the rng that will be read from

-> Int

bits: number of bits to reseed with

-> IO () 

Reseed a random number generator

rngAddEntropy Source #

Arguments

:: RNG

rng: rng object

-> ByteString

entropy: the data to add

-> IO () 

Add some seed material to a random number generator

RNG Types

pattern UserRNG :: RNGType Source #