File: RNG.hs

package info (click to toggle)
haskell-tls 2.1.8-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,056 kB
  • sloc: haskell: 15,695; makefile: 3
file content (30 lines) | stat: -rw-r--r-- 560 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
{-# LANGUAGE GeneralizedNewtypeDeriving #-}

module Network.TLS.RNG (
    StateRNG (..),
    Seed,
    seedNew,
    seedToInteger,
    seedFromInteger,
    withTLSRNG,
    newStateRNG,
    MonadRandom,
    getRandomBytes,
) where

import Crypto.Random

newtype StateRNG = StateRNG ChaChaDRG
    deriving (DRG)

instance Show StateRNG where
    show _ = "rng[..]"

withTLSRNG
    :: StateRNG
    -> MonadPseudoRandom StateRNG a
    -> (a, StateRNG)
withTLSRNG rng f = withDRG rng f

newStateRNG :: Seed -> StateRNG
newStateRNG seed = StateRNG $ drgNewSeed seed