{-# 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"