From fc6cf6169868e60c189e4b243330c3717ff159f3 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Thu, 26 May 2022 13:58:07 +0200 Subject: ... --- overlays/spm/server/Crypto/JOSE/JWK/Instances.hs | 9 ++++++++ overlays/spm/server/Crypto/Random/Instances.hs | 27 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 overlays/spm/server/Crypto/JOSE/JWK/Instances.hs create mode 100644 overlays/spm/server/Crypto/Random/Instances.hs (limited to 'overlays/spm/server/Crypto') diff --git a/overlays/spm/server/Crypto/JOSE/JWK/Instances.hs b/overlays/spm/server/Crypto/JOSE/JWK/Instances.hs new file mode 100644 index 00000000..44a5cfe0 --- /dev/null +++ b/overlays/spm/server/Crypto/JOSE/JWK/Instances.hs @@ -0,0 +1,9 @@ +{-# LANGUAGE TemplateHaskell #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} + +module Crypto.JOSE.JWK.Instances () where + +import Control.Lens.TH +import Crypto.JOSE.JWK + +makeWrapped ''JWKSet 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 @@ +{-# 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" -- cgit v1.2.3