Crypto.Random.AESCtr

cprng-aes-0.2.3: Crypto Pseudo Random Number Generator using AES in counter mode.

Portability | unknown
Stability | stable
Maintainer | Vincent Hanquez <vincent@snarc.org>

Crypto.Random.AESCtr

Description

this CPRNG is an AES based counter system.

the internal size of fields are: 16 bytes IV, 16 bytes counter, 32 bytes key

each block are generated the following way: aes (IV `xor` counter) -> 16 bytes output

Synopsis

- data AESRNG
- make :: ByteString -> Either GenError AESRNG
- makeSystem :: IO AESRNG
- genRandomBytes :: AESRNG -> Int -> (ByteString, AESRNG)

# Documentation

data AESRNG

An opaque object containing an AES CPRNG

Instances

Show AESRNG |
CryptoRandomGen AESRNG |
RandomGen AESRNG |

make :: ByteString -> Either GenError AESRNG

make an AES RNG from a bytestring seed. the bytestring need to be at least 64 bytes. if the bytestring is longer, the extra bytes will be ignored and will not take part in the initialization.

use `makeSystem` to not have to deal with the generator seed.

makeSystem :: IO AESRNG

Initialize a new AES RNG using the system entropy.

genRandomBytes :: AESRNG -> Int -> (ByteString, AESRNG)

get a Random number of bytes from the RNG. it generate randomness by block of 16 bytes, but will truncate to the number of bytes required, and lose the truncated bytes.