crypto-random-0.0.9: Simple cryptographic random related types

LicenseBSD-style
MaintainerVincent Hanquez <vincent@snarc.org>
Stabilityexperimental
PortabilityGood
Safe HaskellNone
LanguageHaskell98

Crypto.Random.API

Description

Deprecated interface for compatibility of crypto-random-api user with crypto-random

Synopsis

Documentation

class CPRG gen where Source

Cryptographic Pseudo Random Generator

Methods

cprgCreate :: EntropyPool -> gen Source

Create a new CPRG using an object of the CryptoGenerator class and with an explicit reference to an EntropyPool.

cprgSetReseedThreshold :: Int -> gen -> gen Source

Give the ability to set a threshold of byte generated that after being exceeded will result in a reseed with some stateful entropy after a call to cprgGenerate

If this threshold is exceeded during the set operation, the rng should be reseeded here.

If this value is set to 0, no reseeding will be done and the output will be completely predicable. This is not a recommended level except for debugging and testing purpose.

cprgFork :: gen -> (gen, gen) Source

Fork a CPRG into a new independent CPRG.

As entropy is mixed to generate safely a new generator, 2 calls with the same CPRG will not produce the same output.

cprgGenerate :: Int -> gen -> (ByteString, gen) Source

Generate a number of bytes using the CPRG.

Given one CPRG, the generated bytes will always be the same.

However the returned CPRG might have been reseeded with entropy bits, so 2 calls with the same CPRG will not necessarily result in the same next CPRG.

cprgGenerateWithEntropy :: Int -> gen -> (ByteString, gen) Source

Similar to cprgGenerate except that the random data is mixed with pure entropy, so the result is not reproducible after use, but it provides more guarantee, theorically speaking, in term of the randomness generated.

Instances

cprgGenBytes :: CPRG g => Int -> g -> (ByteString, g) Source

Generate bytes using the CPRG and the number specified.

For user of the API, it's recommended to use genRandomBytes instead of this method directly. the CPRG need to be able to supply at minimum 2^20 bytes at a time.

genRandomBytes Source

Arguments

:: CPRG g 
=> Int

number of bytes to return

-> g

CPRG to use

-> (ByteString, g) 

Deprecated: use cprgGenerate from Crypto.Random instead

Generate bytes using the cprg in parameter.

If the number of bytes requested is really high, it's preferable to use genRandomBytes for better memory efficiency.

genRandomBytes' Source

Arguments

:: CPRG g 
=> Int

number of bytes to return

-> g

CPRG to use

-> ([ByteString], g) 

Generate bytes using the cprg in parameter.

This is not tail recursive and an excessive len (>= 2^29) parameter would result in stack overflow.

withRandomBytes :: CPRG g => g -> Int -> (ByteString -> a) -> (a, g) Source

generate len random bytes and mapped the bytes to the function f.

This is equivalent to use Control.Arrow first with cprgGenerate