blob: 6b0890bed8dcfafcbe6a4e95e0a6476721116560 (
plain)
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
|
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Crypto.Random.Instances () where
import Prelude
import Crypto.Random
import System.Random
import qualified Data.ByteString as BS
import Data.Bits
instance RandomGen ChaChaDRG where
split = flip withDRG drgNew
genWord64 g = withRandomBytes g 8 $ \case
(map fromIntegral . BS.unpack -> [b1, b2, b3, b4, b5, b6, b7, b8])
-> b1 `shiftL` 56
.|. b2 `shiftL` 48
.|. b3 `shiftL` 40
.|. b4 `shiftL` 32
.|. b5 `shiftL` 24
.|. b6 `shiftL` 16
.|. b7 `shiftL` 8
.|. b8
_other -> error "withRandomBytes did not return correct number of bytes"
|