module Crypto.PubKey.Internal
( and'
, (&&!)
, dsaTruncHash
, dsaTruncHashDigest
) where
import Data.Bits (shiftR)
import Data.List (foldl')
import Crypto.Hash
import Crypto.Internal.ByteArray (ByteArrayAccess)
import Crypto.Number.Basic (numBits)
import Crypto.Number.Serialize
and' :: [Bool] -> Bool
and' :: [Bool] -> Bool
and' l :: [Bool]
l = (Bool -> Bool -> Bool) -> Bool -> [Bool] -> Bool
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' Bool -> Bool -> Bool
(&&!) Bool
True [Bool]
l
(&&!) :: Bool -> Bool -> Bool
True &&! :: Bool -> Bool -> Bool
&&! True = Bool
True
True &&! False = Bool
False
False &&! True = Bool
False
False &&! False = Bool
False
dsaTruncHash :: (ByteArrayAccess msg, HashAlgorithm hash) => hash -> msg -> Integer -> Integer
dsaTruncHash :: hash -> msg -> Integer -> Integer
dsaTruncHash hashAlg :: hash
hashAlg = Digest hash -> Integer -> Integer
forall hash.
HashAlgorithm hash =>
Digest hash -> Integer -> Integer
dsaTruncHashDigest (Digest hash -> Integer -> Integer)
-> (msg -> Digest hash) -> msg -> Integer -> Integer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. hash -> msg -> Digest hash
forall ba alg.
(ByteArrayAccess ba, HashAlgorithm alg) =>
alg -> ba -> Digest alg
hashWith hash
hashAlg
dsaTruncHashDigest :: HashAlgorithm hash => Digest hash -> Integer -> Integer
dsaTruncHashDigest :: Digest hash -> Integer -> Integer
dsaTruncHashDigest digest :: Digest hash
digest n :: Integer
n
| Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 0 = Integer -> Int -> Integer
forall a. Bits a => a -> Int -> a
shiftR Integer
e Int
d
| Bool
otherwise = Integer
e
where e :: Integer
e = Digest hash -> Integer
forall ba. ByteArrayAccess ba => ba -> Integer
os2ip Digest hash
digest
d :: Int
d = hash -> Int
forall a. HashAlgorithm a => a -> Int
hashDigestSize (Digest hash -> hash
forall hash. Digest hash -> hash
getHashAlg Digest hash
digest) Int -> Int -> Int
forall a. Num a => a -> a -> a
* 8 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Integer -> Int
numBits Integer
n
getHashAlg :: Digest hash -> hash
getHashAlg :: Digest hash -> hash
getHashAlg _ = hash
forall a. HasCallStack => a
undefined