summaryrefslogtreecommitdiff
path: root/overlays/spm/server/Crypto/Random
diff options
context:
space:
mode:
Diffstat (limited to 'overlays/spm/server/Crypto/Random')
-rw-r--r--overlays/spm/server/Crypto/Random/Instances.hs27
1 files changed, 27 insertions, 0 deletions
diff --git a/overlays/spm/server/Crypto/Random/Instances.hs b/overlays/spm/server/Crypto/Random/Instances.hs
new file mode 100644
index 00000000..6b0890be
--- /dev/null
+++ b/overlays/spm/server/Crypto/Random/Instances.hs
@@ -0,0 +1,27 @@
1{-# OPTIONS_GHC -fno-warn-orphans #-}
2
3module Crypto.Random.Instances () where
4
5import Prelude
6import Crypto.Random
7import System.Random
8
9import qualified Data.ByteString as BS
10
11import Data.Bits
12
13
14instance RandomGen ChaChaDRG where
15 split = flip withDRG drgNew
16
17 genWord64 g = withRandomBytes g 8 $ \case
18 (map fromIntegral . BS.unpack -> [b1, b2, b3, b4, b5, b6, b7, b8])
19 -> b1 `shiftL` 56
20 .|. b2 `shiftL` 48
21 .|. b3 `shiftL` 40
22 .|. b4 `shiftL` 32
23 .|. b5 `shiftL` 24
24 .|. b6 `shiftL` 16
25 .|. b7 `shiftL` 8
26 .|. b8
27 _other -> error "withRandomBytes did not return correct number of bytes"