From 0fb8a73d3b1513ba50832fce1dc86465bc60ee1f Mon Sep 17 00:00:00 2001 From: Crockett Date: Sun, 3 Feb 2019 16:06:05 -0800 Subject: [PATCH 1/2] Fixed compiler warnings --- Crypto/Cipher/AES.hs | 2 -- Crypto/Cipher/ChaCha.hs | 2 +- Crypto/Cipher/Salsa.hs | 2 +- Crypto/Cipher/Twofish.hs | 1 - Crypto/Cipher/Twofish/Primitive.hs | 7 ++----- Crypto/Cipher/Types/Block.hs | 3 +-- Crypto/Cipher/Utils.hs | 1 - Crypto/Cipher/XSalsa.hs | 6 ++---- Crypto/Data/AFIS.hs | 2 +- Crypto/ECC.hs | 19 +++++++++---------- Crypto/ECC/Edwards25519.hs | 5 +---- Crypto/ECC/Simple/Prim.hs | 1 - Crypto/ECC/Simple/Types.hs | 12 ++++++------ Crypto/Error/Types.hs | 5 ++--- Crypto/Hash.hs | 3 +-- Crypto/Hash/Blake2.hs | 11 +++++------ Crypto/Hash/Blake2b.hs | 11 +++++------ Crypto/Hash/Blake2bp.hs | 3 +-- Crypto/Hash/Blake2s.hs | 7 +++---- Crypto/Hash/Blake2sp.hs | 5 ++--- Crypto/Hash/Keccak.hs | 9 ++++----- Crypto/Hash/MD2.hs | 3 +-- Crypto/Hash/MD4.hs | 3 +-- Crypto/Hash/MD5.hs | 3 +-- Crypto/Hash/RIPEMD160.hs | 3 +-- Crypto/Hash/SHA1.hs | 3 +-- Crypto/Hash/SHA224.hs | 3 +-- Crypto/Hash/SHA256.hs | 3 +-- Crypto/Hash/SHA3.hs | 9 ++++----- Crypto/Hash/SHA384.hs | 3 +-- Crypto/Hash/SHA512.hs | 3 +-- Crypto/Hash/SHA512t.hs | 5 ++--- Crypto/Hash/SHAKE.hs | 5 ++--- Crypto/Hash/Skein256.hs | 5 ++--- Crypto/Hash/Skein512.hs | 9 ++++----- Crypto/Hash/Tiger.hs | 3 +-- Crypto/Hash/Whirlpool.hs | 3 +-- Crypto/Internal/Nat.hs | 22 +++++++++++----------- Crypto/KDF/Argon2.hs | 2 +- Crypto/KDF/PBKDF2.hs | 4 ++-- Crypto/MAC/HMAC.hs | 3 +-- Crypto/Number/F2m.hs | 1 - Crypto/Number/ModArithmetic.hs | 3 +-- Crypto/Number/Prime.hs | 2 -- Crypto/OTP.hs | 9 ++++----- Crypto/PubKey/Curve25519.hs | 2 +- Crypto/PubKey/Curve448.hs | 1 - Crypto/PubKey/DH.hs | 2 +- Crypto/PubKey/DSA.hs | 10 +++++----- Crypto/PubKey/ECC/ECDSA.hs | 8 ++++---- Crypto/PubKey/ECC/Types.hs | 12 ++++++------ Crypto/PubKey/ECIES.hs | 1 - Crypto/PubKey/RSA.hs | 1 - Crypto/PubKey/RSA/Types.hs | 6 +++--- Crypto/PubKey/Rabin/Basic.hs | 9 ++++----- Crypto/PubKey/Rabin/Modified.hs | 8 +++----- Crypto/PubKey/Rabin/RW.hs | 7 +++---- Crypto/Random/ChaChaDRG.hs | 2 +- Crypto/Random/SystemDRG.hs | 1 - Crypto/Random/Types.hs | 5 ++--- stack.yaml | 2 +- tests/BlockCipher.hs | 4 ++-- tests/KAT_CAST5.hs | 1 - tests/KAT_HKDF.hs | 5 +---- tests/KAT_MiyaguchiPreneel.hs | 1 - tests/KAT_OTP.hs | 6 +++--- tests/Padding.hs | 1 - 67 files changed, 132 insertions(+), 192 deletions(-) diff --git a/Crypto/Cipher/AES.hs b/Crypto/Cipher/AES.hs index 97a1801..8ba303f 100644 --- a/Crypto/Cipher/AES.hs +++ b/Crypto/Cipher/AES.hs @@ -19,8 +19,6 @@ import Crypto.Cipher.Types.Block import Crypto.Cipher.AES.Primitive import Crypto.Internal.Imports -import Data.ByteArray as BA - -- | AES with 128 bit key newtype AES128 = AES128 AES deriving (NFData) diff --git a/Crypto/Cipher/ChaCha.hs b/Crypto/Cipher/ChaCha.hs index cd5c511..4dd70ad 100644 --- a/Crypto/Cipher/ChaCha.hs +++ b/Crypto/Cipher/ChaCha.hs @@ -48,7 +48,7 @@ initialize nbRounds key nonce stPtr <- B.alloc 132 $ \stPtr -> B.withByteArray nonce $ \noncePtr -> B.withByteArray key $ \keyPtr -> - ccryptonite_chacha_init stPtr (fromIntegral nbRounds) kLen keyPtr nonceLen noncePtr + ccryptonite_chacha_init stPtr nbRounds kLen keyPtr nonceLen noncePtr return $ State stPtr where kLen = B.length key nonceLen = B.length nonce diff --git a/Crypto/Cipher/Salsa.hs b/Crypto/Cipher/Salsa.hs index b6b188b..7d05e6c 100644 --- a/Crypto/Cipher/Salsa.hs +++ b/Crypto/Cipher/Salsa.hs @@ -40,7 +40,7 @@ initialize nbRounds key nonce stPtr <- B.alloc 132 $ \stPtr -> B.withByteArray nonce $ \noncePtr -> B.withByteArray key $ \keyPtr -> - ccryptonite_salsa_init stPtr (fromIntegral nbRounds) kLen keyPtr nonceLen noncePtr + ccryptonite_salsa_init stPtr nbRounds kLen keyPtr nonceLen noncePtr return $ State stPtr where kLen = B.length key nonceLen = B.length nonce diff --git a/Crypto/Cipher/Twofish.hs b/Crypto/Cipher/Twofish.hs index 40428ec..7fedd0e 100644 --- a/Crypto/Cipher/Twofish.hs +++ b/Crypto/Cipher/Twofish.hs @@ -7,7 +7,6 @@ module Crypto.Cipher.Twofish import Crypto.Cipher.Twofish.Primitive import Crypto.Cipher.Types import Crypto.Cipher.Utils -import Crypto.Internal.Imports newtype Twofish128 = Twofish128 Twofish diff --git a/Crypto/Cipher/Twofish/Primitive.hs b/Crypto/Cipher/Twofish/Primitive.hs index e998a5e..30c260d 100644 --- a/Crypto/Cipher/Twofish/Primitive.hs +++ b/Crypto/Cipher/Twofish/Primitive.hs @@ -8,15 +8,12 @@ module Crypto.Cipher.Twofish.Primitive ) where import Crypto.Error -import Crypto.Internal.ByteArray (ByteArrayAccess, ByteArray, Bytes) +import Crypto.Internal.ByteArray (ByteArray) import qualified Crypto.Internal.ByteArray as B import Crypto.Internal.WordArray -import Crypto.Internal.Words import Data.Word -import Data.Int import Data.Bits import Data.List -import Control.Monad -- Based on the Golang referance implementation -- https://github.com/golang/crypto/blob/master/twofish/twofish.go @@ -206,7 +203,7 @@ sWords key = sWord data Column = Zero | One | Two | Three deriving (Show, Eq, Enum, Bounded) -genSboxes :: ByteArray ba => KeyPackage ba -> [Word8] -> (Array32, Array32, Array32, Array32) +genSboxes :: KeyPackage ba -> [Word8] -> (Array32, Array32, Array32, Array32) genSboxes keyPackage ws = (mkArray b0', mkArray b1', mkArray b2', mkArray b3') where range = [0..255] mkArray = array32 256 diff --git a/Crypto/Cipher/Types/Block.hs b/Crypto/Cipher/Types/Block.hs index 290b67b..a2ac2d2 100644 --- a/Crypto/Cipher/Types/Block.hs +++ b/Crypto/Cipher/Types/Block.hs @@ -37,7 +37,6 @@ module Crypto.Cipher.Types.Block ) where import Data.Word -import Data.Monoid import Crypto.Error import Crypto.Cipher.Types.Base import Crypto.Cipher.Types.GF @@ -164,7 +163,7 @@ nullIV = toIV undefined -- | Increment an IV by a number. -- -- Assume the IV is in Big Endian format. -ivAdd :: BlockCipher c => IV c -> Int -> IV c +ivAdd :: IV c -> Int -> IV c ivAdd (IV b) i = IV $ copy b where copy :: ByteArray bs => bs -> bs copy bs = B.copyAndFreeze bs $ loop i (B.length bs - 1) diff --git a/Crypto/Cipher/Utils.hs b/Crypto/Cipher/Utils.hs index e6c0c76..24e2e0a 100644 --- a/Crypto/Cipher/Utils.hs +++ b/Crypto/Cipher/Utils.hs @@ -4,7 +4,6 @@ module Crypto.Cipher.Utils import Crypto.Error import Crypto.Cipher.Types -import Crypto.Internal.Imports import Data.ByteArray as BA diff --git a/Crypto/Cipher/XSalsa.hs b/Crypto/Cipher/XSalsa.hs index 494760e..db8b919 100644 --- a/Crypto/Cipher/XSalsa.hs +++ b/Crypto/Cipher/XSalsa.hs @@ -17,13 +17,11 @@ module Crypto.Cipher.XSalsa , State ) where -import Crypto.Internal.ByteArray (ByteArrayAccess, ByteArray, ScrubbedBytes) +import Crypto.Internal.ByteArray (ByteArrayAccess) import qualified Crypto.Internal.ByteArray as B import Crypto.Internal.Compat import Crypto.Internal.Imports import Foreign.Ptr -import Foreign.Storable -import Foreign.C.Types import Crypto.Cipher.Salsa hiding (initialize) -- | Initialize a new XSalsa context with the number of rounds, @@ -41,7 +39,7 @@ initialize nbRounds key nonce stPtr <- B.alloc 132 $ \stPtr -> B.withByteArray nonce $ \noncePtr -> B.withByteArray key $ \keyPtr -> - ccryptonite_xsalsa_init stPtr (fromIntegral nbRounds) kLen keyPtr nonceLen noncePtr + ccryptonite_xsalsa_init stPtr nbRounds kLen keyPtr nonceLen noncePtr return $ State stPtr where kLen = B.length key nonceLen = B.length nonce diff --git a/Crypto/Data/AFIS.hs b/Crypto/Data/AFIS.hs index bcf95cf..2312e9c 100644 --- a/Crypto/Data/AFIS.hs +++ b/Crypto/Data/AFIS.hs @@ -77,7 +77,7 @@ split hashAlg rng expandTimes src diffuse hashAlg lastBlock blockSize fillRandomBlock g blockPtr = do let (rand :: Bytes, g') = randomBytesGenerate blockSize g - B.withByteArray rand $ \randPtr -> memCopy blockPtr randPtr (fromIntegral blockSize) + B.withByteArray rand $ \randPtr -> memCopy blockPtr randPtr blockSize return g' -- | Merge previously diffused data back to the original data. diff --git a/Crypto/ECC.hs b/Crypto/ECC.hs index a272cd5..34a911f 100644 --- a/Crypto/ECC.hs +++ b/Crypto/ECC.hs @@ -38,10 +38,9 @@ import qualified Crypto.Internal.ByteArray as B import Crypto.Number.Serialize (i2ospOf_, os2ip) import qualified Crypto.PubKey.Curve25519 as X25519 import qualified Crypto.PubKey.Curve448 as X448 -import Data.Function (on) import Data.ByteArray (convert) import Data.Data (Data()) -import Data.Typeable (Typeable()) +import Data.Kind (Type) -- | An elliptic curve key pair composed of the private part (a scalar), and -- the associated point. @@ -55,10 +54,10 @@ newtype SharedSecret = SharedSecret ScrubbedBytes class EllipticCurve curve where -- | Point on an Elliptic Curve - type Point curve :: * + type Point curve :: Type -- | Scalar in the Elliptic Curve domain - type Scalar curve :: * + type Scalar curve :: Type -- | Generate a new random scalar on the curve. -- The scalar will represent a number between 1 and the order of the curve non included @@ -116,7 +115,7 @@ class EllipticCurve curve => EllipticCurveArith curve where -- -- also known as P256 data Curve_P256R1 = Curve_P256R1 - deriving (Show,Data,Typeable) + deriving (Show,Data) instance EllipticCurve Curve_P256R1 where type Point Curve_P256R1 = P256.Point @@ -150,7 +149,7 @@ instance EllipticCurveDH Curve_P256R1 where ecdh prx s p = checkNonZeroDH (ecdhRaw prx s p) data Curve_P384R1 = Curve_P384R1 - deriving (Show,Data,Typeable) + deriving (Show,Data) instance EllipticCurve Curve_P384R1 where type Point Curve_P384R1 = Simple.Point Simple.SEC_p384r1 @@ -173,7 +172,7 @@ instance EllipticCurveDH Curve_P384R1 where prx = Proxy :: Proxy Simple.SEC_p384r1 data Curve_P521R1 = Curve_P521R1 - deriving (Show,Data,Typeable) + deriving (Show,Data) instance EllipticCurve Curve_P521R1 where type Point Curve_P521R1 = Simple.Point Simple.SEC_p521r1 @@ -196,7 +195,7 @@ instance EllipticCurveDH Curve_P521R1 where prx = Proxy :: Proxy Simple.SEC_p521r1 data Curve_X25519 = Curve_X25519 - deriving (Show,Data,Typeable) + deriving (Show,Data) instance EllipticCurve Curve_X25519 where type Point Curve_X25519 = X25519.PublicKey @@ -215,7 +214,7 @@ instance EllipticCurveDH Curve_X25519 where ecdh prx s p = checkNonZeroDH (ecdhRaw prx s p) data Curve_X448 = Curve_X448 - deriving (Show,Data,Typeable) + deriving (Show,Data) instance EllipticCurve Curve_X448 where type Point Curve_X448 = X448.PublicKey @@ -234,7 +233,7 @@ instance EllipticCurveDH Curve_X448 where ecdh prx s p = checkNonZeroDH (ecdhRaw prx s p) data Curve_Edwards25519 = Curve_Edwards25519 - deriving (Show,Data,Typeable) + deriving (Show,Data) instance EllipticCurve Curve_Edwards25519 where type Point Curve_Edwards25519 = Edwards25519.Point diff --git a/Crypto/ECC/Edwards25519.hs b/Crypto/ECC/Edwards25519.hs index ebba8ca..92a0516 100644 --- a/Crypto/ECC/Edwards25519.hs +++ b/Crypto/ECC/Edwards25519.hs @@ -73,15 +73,12 @@ module Crypto.ECC.Edwards25519 , pointsMulVarTime ) where -import Data.Bits import Data.Word import Foreign.C.Types import Foreign.Ptr -import Foreign.Storable import Crypto.Error -import Crypto.Internal.ByteArray (ByteArrayAccess, Bytes, - ScrubbedBytes, withByteArray) +import Crypto.Internal.ByteArray (Bytes, ScrubbedBytes, withByteArray) import qualified Crypto.Internal.ByteArray as B import Crypto.Internal.Compat import Crypto.Internal.Imports diff --git a/Crypto/ECC/Simple/Prim.hs b/Crypto/ECC/Simple/Prim.hs index 7eebb4e..25d8fe1 100644 --- a/Crypto/ECC/Simple/Prim.hs +++ b/Crypto/ECC/Simple/Prim.hs @@ -17,7 +17,6 @@ module Crypto.ECC.Simple.Prim ) where import Data.Maybe -import Crypto.Internal.Imports import Crypto.Internal.Proxy import Crypto.Number.ModArithmetic import Crypto.Number.F2m diff --git a/Crypto/ECC/Simple/Types.hs b/Crypto/ECC/Simple/Types.hs index 814c256..b4984a5 100644 --- a/Crypto/ECC/Simple/Types.hs +++ b/Crypto/ECC/Simple/Types.hs @@ -84,28 +84,28 @@ data CurveParameters curve = CurveParameters , curveEccG :: Point curve -- ^ base point , curveEccN :: Integer -- ^ order of G , curveEccH :: Integer -- ^ cofactor - } deriving (Show,Eq,Data,Typeable) + } deriving (Show,Eq,Data) newtype CurveBinaryParam = CurveBinaryParam Integer - deriving (Show,Read,Eq,Data,Typeable) + deriving (Show,Read,Eq,Data) newtype CurvePrimeParam = CurvePrimeParam Integer - deriving (Show,Read,Eq,Data,Typeable) + deriving (Show,Read,Eq,Data) data CurveType = CurveBinary CurveBinaryParam | CurvePrime CurvePrimeParam - deriving (Show,Read,Eq,Data,Typeable) + deriving (Show,Read,Eq,Data) -- | ECC Private Number newtype Scalar curve = Scalar Integer - deriving (Show,Read,Eq,Data,Typeable,NFData) + deriving (Show,Read,Eq,Data,NFData) -- | Define a point on a curve. data Point curve = Point Integer Integer | PointO -- ^ Point at Infinity - deriving (Show,Read,Eq,Data,Typeable) + deriving (Show,Read,Eq,Data) instance NFData (Point curve) where rnf (Point x y) = x `seq` y `seq` () diff --git a/Crypto/Error/Types.hs b/Crypto/Error/Types.hs index 685e506..b72efad 100644 --- a/Crypto/Error/Types.hs +++ b/Crypto/Error/Types.hs @@ -23,7 +23,6 @@ import qualified Control.Exception as E import Data.Data import Basement.Monad (MonadFailure(..)) -import Crypto.Internal.Imports -- | Enumeration of all possible errors that can be found in this library data CryptoError = @@ -53,7 +52,7 @@ data CryptoError = | CryptoError_SaltTooSmall | CryptoError_OutputLengthTooSmall | CryptoError_OutputLengthTooBig - deriving (Show,Eq,Enum,Data,Typeable) + deriving (Show,Eq,Enum,Data) instance E.Exception CryptoError @@ -83,7 +82,7 @@ instance Applicative CryptoFailable where pure a = CryptoPassed a (<*>) fm m = fm >>= \p -> m >>= \r2 -> return (p r2) instance Monad CryptoFailable where - return a = CryptoPassed a + return = pure (>>=) m1 m2 = do case m1 of CryptoPassed a -> m2 a diff --git a/Crypto/Hash.hs b/Crypto/Hash.hs index f8b9637..37e6f9f 100644 --- a/Crypto/Hash.hs +++ b/Crypto/Hash.hs @@ -44,7 +44,6 @@ module Crypto.Hash import Basement.Types.OffsetSize (CountOf (..)) import Basement.Block (Block, unsafeFreeze) import Basement.Block.Mutable (copyFromPtr, new) -import Control.Monad import Crypto.Internal.Compat (unsafeDoIO) import Crypto.Hash.Types import Crypto.Hash.Algorithms @@ -110,7 +109,7 @@ hashWith _ = hash digestFromByteString :: forall a ba . (HashAlgorithm a, ByteArrayAccess ba) => ba -> Maybe (Digest a) digestFromByteString = from undefined where - from :: HashAlgorithm a => a -> ba -> Maybe (Digest a) + from :: a -> ba -> Maybe (Digest a) from alg bs | B.length bs == (hashDigestSize alg) = Just $ Digest $ unsafeDoIO $ copyBytes bs | otherwise = Nothing diff --git a/Crypto/Hash/Blake2.hs b/Crypto/Hash/Blake2.hs index 59769e2..1e06c40 100644 --- a/Crypto/Hash/Blake2.hs +++ b/Crypto/Hash/Blake2.hs @@ -42,9 +42,8 @@ module Crypto.Hash.Blake2 import Crypto.Hash.Types import Foreign.Ptr (Ptr) import Data.Data -import Data.Typeable import Data.Word (Word8, Word32) -import GHC.TypeLits (Nat, KnownNat, natVal) +import GHC.TypeLits (Nat, KnownNat) import Crypto.Internal.Nat -- | Fast and secure alternative to SHA1 and HMAC-SHA1 @@ -58,7 +57,7 @@ import Crypto.Internal.Nat -- * Blake2s 256 -- data Blake2s (bitlen :: Nat) = Blake2s - deriving (Show, Typeable) + deriving (Show) instance (IsDivisibleBy8 bitlen, KnownNat bitlen, IsAtLeast bitlen 8, IsAtMost bitlen 256) => HashAlgorithm (Blake2s bitlen) @@ -93,7 +92,7 @@ foreign import ccall unsafe "cryptonite_blake2s_finalize" -- * Blake2b 512 -- data Blake2b (bitlen :: Nat) = Blake2b - deriving (Show, Typeable) + deriving (Show) instance (IsDivisibleBy8 bitlen, KnownNat bitlen, IsAtLeast bitlen 8, IsAtMost bitlen 512) => HashAlgorithm (Blake2b bitlen) @@ -116,7 +115,7 @@ foreign import ccall unsafe "cryptonite_blake2b_finalize" c_blake2b_finalize :: Ptr (Context a) -> Word32 -> Ptr (Digest a) -> IO () data Blake2sp (bitlen :: Nat) = Blake2sp - deriving (Show, Typeable) + deriving (Show) instance (IsDivisibleBy8 bitlen, KnownNat bitlen, IsAtLeast bitlen 8, IsAtMost bitlen 256) => HashAlgorithm (Blake2sp bitlen) @@ -139,7 +138,7 @@ foreign import ccall unsafe "cryptonite_blake2sp_finalize" c_blake2sp_finalize :: Ptr (Context a) -> Word32 -> Ptr (Digest a) -> IO () data Blake2bp (bitlen :: Nat) = Blake2bp - deriving (Show, Typeable) + deriving (Show) instance (IsDivisibleBy8 bitlen, KnownNat bitlen, IsAtLeast bitlen 8, IsAtMost bitlen 512) => HashAlgorithm (Blake2bp bitlen) diff --git a/Crypto/Hash/Blake2b.hs b/Crypto/Hash/Blake2b.hs index 6d81274..788db0b 100644 --- a/Crypto/Hash/Blake2b.hs +++ b/Crypto/Hash/Blake2b.hs @@ -19,13 +19,12 @@ module Crypto.Hash.Blake2b import Crypto.Hash.Types import Foreign.Ptr (Ptr) import Data.Data -import Data.Typeable import Data.Word (Word8, Word32) -- | Blake2b (160 bits) cryptographic hash algorithm data Blake2b_160 = Blake2b_160 - deriving (Show,Data,Typeable) + deriving (Show,Data) instance HashAlgorithm Blake2b_160 where type HashBlockSize Blake2b_160 = 128 @@ -40,7 +39,7 @@ instance HashAlgorithm Blake2b_160 where -- | Blake2b (224 bits) cryptographic hash algorithm data Blake2b_224 = Blake2b_224 - deriving (Show,Data,Typeable) + deriving (Show,Data) instance HashAlgorithm Blake2b_224 where type HashBlockSize Blake2b_224 = 128 @@ -55,7 +54,7 @@ instance HashAlgorithm Blake2b_224 where -- | Blake2b (256 bits) cryptographic hash algorithm data Blake2b_256 = Blake2b_256 - deriving (Show,Data,Typeable) + deriving (Show,Data) instance HashAlgorithm Blake2b_256 where type HashBlockSize Blake2b_256 = 128 @@ -70,7 +69,7 @@ instance HashAlgorithm Blake2b_256 where -- | Blake2b (384 bits) cryptographic hash algorithm data Blake2b_384 = Blake2b_384 - deriving (Show,Data,Typeable) + deriving (Show,Data) instance HashAlgorithm Blake2b_384 where type HashBlockSize Blake2b_384 = 128 @@ -85,7 +84,7 @@ instance HashAlgorithm Blake2b_384 where -- | Blake2b (512 bits) cryptographic hash algorithm data Blake2b_512 = Blake2b_512 - deriving (Show,Data,Typeable) + deriving (Show,Data) instance HashAlgorithm Blake2b_512 where type HashBlockSize Blake2b_512 = 128 diff --git a/Crypto/Hash/Blake2bp.hs b/Crypto/Hash/Blake2bp.hs index fbd4eeb..35e556c 100644 --- a/Crypto/Hash/Blake2bp.hs +++ b/Crypto/Hash/Blake2bp.hs @@ -19,13 +19,12 @@ module Crypto.Hash.Blake2bp import Crypto.Hash.Types import Foreign.Ptr (Ptr) import Data.Data -import Data.Typeable import Data.Word (Word8, Word32) -- | Blake2bp (512 bits) cryptographic hash algorithm data Blake2bp_512 = Blake2bp_512 - deriving (Show,Data,Typeable) + deriving (Show,Data) instance HashAlgorithm Blake2bp_512 where type HashBlockSize Blake2bp_512 = 128 diff --git a/Crypto/Hash/Blake2s.hs b/Crypto/Hash/Blake2s.hs index 7106eb5..c7426b0 100644 --- a/Crypto/Hash/Blake2s.hs +++ b/Crypto/Hash/Blake2s.hs @@ -19,13 +19,12 @@ module Crypto.Hash.Blake2s import Crypto.Hash.Types import Foreign.Ptr (Ptr) import Data.Data -import Data.Typeable import Data.Word (Word8, Word32) -- | Blake2s (160 bits) cryptographic hash algorithm data Blake2s_160 = Blake2s_160 - deriving (Show,Data,Typeable) + deriving (Show,Data) instance HashAlgorithm Blake2s_160 where type HashBlockSize Blake2s_160 = 64 @@ -40,7 +39,7 @@ instance HashAlgorithm Blake2s_160 where -- | Blake2s (224 bits) cryptographic hash algorithm data Blake2s_224 = Blake2s_224 - deriving (Show,Data,Typeable) + deriving (Show,Data) instance HashAlgorithm Blake2s_224 where type HashBlockSize Blake2s_224 = 64 @@ -55,7 +54,7 @@ instance HashAlgorithm Blake2s_224 where -- | Blake2s (256 bits) cryptographic hash algorithm data Blake2s_256 = Blake2s_256 - deriving (Show,Data,Typeable) + deriving (Show,Data) instance HashAlgorithm Blake2s_256 where type HashBlockSize Blake2s_256 = 64 diff --git a/Crypto/Hash/Blake2sp.hs b/Crypto/Hash/Blake2sp.hs index 0931eb0..1a659f2 100644 --- a/Crypto/Hash/Blake2sp.hs +++ b/Crypto/Hash/Blake2sp.hs @@ -19,13 +19,12 @@ module Crypto.Hash.Blake2sp import Crypto.Hash.Types import Foreign.Ptr (Ptr) import Data.Data -import Data.Typeable import Data.Word (Word8, Word32) -- | Blake2sp (224 bits) cryptographic hash algorithm data Blake2sp_224 = Blake2sp_224 - deriving (Show,Data,Typeable) + deriving (Show,Data) instance HashAlgorithm Blake2sp_224 where type HashBlockSize Blake2sp_224 = 64 @@ -40,7 +39,7 @@ instance HashAlgorithm Blake2sp_224 where -- | Blake2sp (256 bits) cryptographic hash algorithm data Blake2sp_256 = Blake2sp_256 - deriving (Show,Data,Typeable) + deriving (Show,Data) instance HashAlgorithm Blake2sp_256 where type HashBlockSize Blake2sp_256 = 64 diff --git a/Crypto/Hash/Keccak.hs b/Crypto/Hash/Keccak.hs index 234e3cf..371e284 100644 --- a/Crypto/Hash/Keccak.hs +++ b/Crypto/Hash/Keccak.hs @@ -19,13 +19,12 @@ module Crypto.Hash.Keccak import Crypto.Hash.Types import Foreign.Ptr (Ptr) import Data.Data -import Data.Typeable import Data.Word (Word8, Word32) -- | Keccak (224 bits) cryptographic hash algorithm data Keccak_224 = Keccak_224 - deriving (Show,Data,Typeable) + deriving (Show,Data) instance HashAlgorithm Keccak_224 where type HashBlockSize Keccak_224 = 144 @@ -40,7 +39,7 @@ instance HashAlgorithm Keccak_224 where -- | Keccak (256 bits) cryptographic hash algorithm data Keccak_256 = Keccak_256 - deriving (Show,Data,Typeable) + deriving (Show,Data) instance HashAlgorithm Keccak_256 where type HashBlockSize Keccak_256 = 136 @@ -55,7 +54,7 @@ instance HashAlgorithm Keccak_256 where -- | Keccak (384 bits) cryptographic hash algorithm data Keccak_384 = Keccak_384 - deriving (Show,Data,Typeable) + deriving (Show,Data) instance HashAlgorithm Keccak_384 where type HashBlockSize Keccak_384 = 104 @@ -70,7 +69,7 @@ instance HashAlgorithm Keccak_384 where -- | Keccak (512 bits) cryptographic hash algorithm data Keccak_512 = Keccak_512 - deriving (Show,Data,Typeable) + deriving (Show,Data) instance HashAlgorithm Keccak_512 where type HashBlockSize Keccak_512 = 72 diff --git a/Crypto/Hash/MD2.hs b/Crypto/Hash/MD2.hs index f1919ce..c878662 100644 --- a/Crypto/Hash/MD2.hs +++ b/Crypto/Hash/MD2.hs @@ -17,12 +17,11 @@ module Crypto.Hash.MD2 ( MD2 (..) ) where import Crypto.Hash.Types import Foreign.Ptr (Ptr) import Data.Data -import Data.Typeable import Data.Word (Word8, Word32) -- | MD2 cryptographic hash algorithm data MD2 = MD2 - deriving (Show,Data,Typeable) + deriving (Show,Data) instance HashAlgorithm MD2 where type HashBlockSize MD2 = 16 diff --git a/Crypto/Hash/MD4.hs b/Crypto/Hash/MD4.hs index 543dd3b..0f39d58 100644 --- a/Crypto/Hash/MD4.hs +++ b/Crypto/Hash/MD4.hs @@ -17,12 +17,11 @@ module Crypto.Hash.MD4 ( MD4 (..) ) where import Crypto.Hash.Types import Foreign.Ptr (Ptr) import Data.Data -import Data.Typeable import Data.Word (Word8, Word32) -- | MD4 cryptographic hash algorithm data MD4 = MD4 - deriving (Show,Data,Typeable) + deriving (Show,Data) instance HashAlgorithm MD4 where type HashBlockSize MD4 = 64 diff --git a/Crypto/Hash/MD5.hs b/Crypto/Hash/MD5.hs index dc94a91..17a09ef 100644 --- a/Crypto/Hash/MD5.hs +++ b/Crypto/Hash/MD5.hs @@ -17,12 +17,11 @@ module Crypto.Hash.MD5 ( MD5 (..) ) where import Crypto.Hash.Types import Foreign.Ptr (Ptr) import Data.Data -import Data.Typeable import Data.Word (Word8, Word32) -- | MD5 cryptographic hash algorithm data MD5 = MD5 - deriving (Show,Data,Typeable) + deriving (Show,Data) instance HashAlgorithm MD5 where type HashBlockSize MD5 = 64 diff --git a/Crypto/Hash/RIPEMD160.hs b/Crypto/Hash/RIPEMD160.hs index 13334a3..ba2d413 100644 --- a/Crypto/Hash/RIPEMD160.hs +++ b/Crypto/Hash/RIPEMD160.hs @@ -17,12 +17,11 @@ module Crypto.Hash.RIPEMD160 ( RIPEMD160 (..) ) where import Crypto.Hash.Types import Foreign.Ptr (Ptr) import Data.Data -import Data.Typeable import Data.Word (Word8, Word32) -- | RIPEMD160 cryptographic hash algorithm data RIPEMD160 = RIPEMD160 - deriving (Show,Data,Typeable) + deriving (Show,Data) instance HashAlgorithm RIPEMD160 where type HashBlockSize RIPEMD160 = 64 diff --git a/Crypto/Hash/SHA1.hs b/Crypto/Hash/SHA1.hs index 8d1ed84..87e44a3 100644 --- a/Crypto/Hash/SHA1.hs +++ b/Crypto/Hash/SHA1.hs @@ -17,12 +17,11 @@ module Crypto.Hash.SHA1 ( SHA1 (..) ) where import Crypto.Hash.Types import Foreign.Ptr (Ptr) import Data.Data -import Data.Typeable import Data.Word (Word8, Word32) -- | SHA1 cryptographic hash algorithm data SHA1 = SHA1 - deriving (Show,Data,Typeable) + deriving (Show,Data) instance HashAlgorithm SHA1 where type HashBlockSize SHA1 = 64 diff --git a/Crypto/Hash/SHA224.hs b/Crypto/Hash/SHA224.hs index 9801a33..a609d57 100644 --- a/Crypto/Hash/SHA224.hs +++ b/Crypto/Hash/SHA224.hs @@ -17,12 +17,11 @@ module Crypto.Hash.SHA224 ( SHA224 (..) ) where import Crypto.Hash.Types import Foreign.Ptr (Ptr) import Data.Data -import Data.Typeable import Data.Word (Word8, Word32) -- | SHA224 cryptographic hash algorithm data SHA224 = SHA224 - deriving (Show,Data,Typeable) + deriving (Show,Data) instance HashAlgorithm SHA224 where type HashBlockSize SHA224 = 64 diff --git a/Crypto/Hash/SHA256.hs b/Crypto/Hash/SHA256.hs index d9102f9..eacd502 100644 --- a/Crypto/Hash/SHA256.hs +++ b/Crypto/Hash/SHA256.hs @@ -17,12 +17,11 @@ module Crypto.Hash.SHA256 ( SHA256 (..) ) where import Crypto.Hash.Types import Foreign.Ptr (Ptr) import Data.Data -import Data.Typeable import Data.Word (Word8, Word32) -- | SHA256 cryptographic hash algorithm data SHA256 = SHA256 - deriving (Show,Data,Typeable) + deriving (Show,Data) instance HashAlgorithm SHA256 where type HashBlockSize SHA256 = 64 diff --git a/Crypto/Hash/SHA3.hs b/Crypto/Hash/SHA3.hs index 9dada07..a5ca6a7 100644 --- a/Crypto/Hash/SHA3.hs +++ b/Crypto/Hash/SHA3.hs @@ -19,13 +19,12 @@ module Crypto.Hash.SHA3 import Crypto.Hash.Types import Foreign.Ptr (Ptr) import Data.Data -import Data.Typeable import Data.Word (Word8, Word32) -- | SHA3 (224 bits) cryptographic hash algorithm data SHA3_224 = SHA3_224 - deriving (Show,Data,Typeable) + deriving (Show,Data) instance HashAlgorithm SHA3_224 where type HashBlockSize SHA3_224 = 144 @@ -40,7 +39,7 @@ instance HashAlgorithm SHA3_224 where -- | SHA3 (256 bits) cryptographic hash algorithm data SHA3_256 = SHA3_256 - deriving (Show,Data,Typeable) + deriving (Show,Data) instance HashAlgorithm SHA3_256 where type HashBlockSize SHA3_256 = 136 @@ -55,7 +54,7 @@ instance HashAlgorithm SHA3_256 where -- | SHA3 (384 bits) cryptographic hash algorithm data SHA3_384 = SHA3_384 - deriving (Show,Data,Typeable) + deriving (Show,Data) instance HashAlgorithm SHA3_384 where type HashBlockSize SHA3_384 = 104 @@ -70,7 +69,7 @@ instance HashAlgorithm SHA3_384 where -- | SHA3 (512 bits) cryptographic hash algorithm data SHA3_512 = SHA3_512 - deriving (Show,Data,Typeable) + deriving (Show,Data) instance HashAlgorithm SHA3_512 where type HashBlockSize SHA3_512 = 72 diff --git a/Crypto/Hash/SHA384.hs b/Crypto/Hash/SHA384.hs index 4bcc5fc..2b19f52 100644 --- a/Crypto/Hash/SHA384.hs +++ b/Crypto/Hash/SHA384.hs @@ -17,12 +17,11 @@ module Crypto.Hash.SHA384 ( SHA384 (..) ) where import Crypto.Hash.Types import Foreign.Ptr (Ptr) import Data.Data -import Data.Typeable import Data.Word (Word8, Word32) -- | SHA384 cryptographic hash algorithm data SHA384 = SHA384 - deriving (Show,Data,Typeable) + deriving (Show,Data) instance HashAlgorithm SHA384 where type HashBlockSize SHA384 = 128 diff --git a/Crypto/Hash/SHA512.hs b/Crypto/Hash/SHA512.hs index 14b82f2..20449b3 100644 --- a/Crypto/Hash/SHA512.hs +++ b/Crypto/Hash/SHA512.hs @@ -17,12 +17,11 @@ module Crypto.Hash.SHA512 ( SHA512 (..) ) where import Crypto.Hash.Types import Foreign.Ptr (Ptr) import Data.Data -import Data.Typeable import Data.Word (Word8, Word32) -- | SHA512 cryptographic hash algorithm data SHA512 = SHA512 - deriving (Show,Data,Typeable) + deriving (Show,Data) instance HashAlgorithm SHA512 where type HashBlockSize SHA512 = 128 diff --git a/Crypto/Hash/SHA512t.hs b/Crypto/Hash/SHA512t.hs index be88d3a..e1bd6e0 100644 --- a/Crypto/Hash/SHA512t.hs +++ b/Crypto/Hash/SHA512t.hs @@ -19,13 +19,12 @@ module Crypto.Hash.SHA512t import Crypto.Hash.Types import Foreign.Ptr (Ptr) import Data.Data -import Data.Typeable import Data.Word (Word8, Word32) -- | SHA512t (224 bits) cryptographic hash algorithm data SHA512t_224 = SHA512t_224 - deriving (Show,Data,Typeable) + deriving (Show,Data) instance HashAlgorithm SHA512t_224 where type HashBlockSize SHA512t_224 = 128 @@ -40,7 +39,7 @@ instance HashAlgorithm SHA512t_224 where -- | SHA512t (256 bits) cryptographic hash algorithm data SHA512t_256 = SHA512t_256 - deriving (Show,Data,Typeable) + deriving (Show,Data) instance HashAlgorithm SHA512t_256 where type HashBlockSize SHA512t_256 = 128 diff --git a/Crypto/Hash/SHAKE.hs b/Crypto/Hash/SHAKE.hs index 63d19d8..3298816 100644 --- a/Crypto/Hash/SHAKE.hs +++ b/Crypto/Hash/SHAKE.hs @@ -26,7 +26,6 @@ import Foreign.Ptr (Ptr, castPtr) import Foreign.Storable (Storable(..)) import Data.Bits import Data.Data -import Data.Typeable import Data.Word (Word8, Word32) import Data.Proxy (Proxy(..)) @@ -40,7 +39,7 @@ import Crypto.Internal.Nat -- correlated (one being a prefix of the other). Results are unrelated to -- 'SHAKE256' results. data SHAKE128 (bitlen :: Nat) = SHAKE128 - deriving (Show, Data, Typeable) + deriving (Show, Data) instance KnownNat bitlen => HashAlgorithm (SHAKE128 bitlen) where type HashBlockSize (SHAKE128 bitlen) = 168 @@ -60,7 +59,7 @@ instance KnownNat bitlen => HashAlgorithm (SHAKE128 bitlen) where -- correlated (one being a prefix of the other). Results are unrelated to -- 'SHAKE128' results. data SHAKE256 (bitlen :: Nat) = SHAKE256 - deriving (Show, Data, Typeable) + deriving (Show, Data) instance KnownNat bitlen => HashAlgorithm (SHAKE256 bitlen) where type HashBlockSize (SHAKE256 bitlen) = 136 diff --git a/Crypto/Hash/Skein256.hs b/Crypto/Hash/Skein256.hs index 9871d47..8e3bddc 100644 --- a/Crypto/Hash/Skein256.hs +++ b/Crypto/Hash/Skein256.hs @@ -19,13 +19,12 @@ module Crypto.Hash.Skein256 import Crypto.Hash.Types import Foreign.Ptr (Ptr) import Data.Data -import Data.Typeable import Data.Word (Word8, Word32) -- | Skein256 (224 bits) cryptographic hash algorithm data Skein256_224 = Skein256_224 - deriving (Show,Data,Typeable) + deriving (Show,Data) instance HashAlgorithm Skein256_224 where type HashBlockSize Skein256_224 = 32 @@ -40,7 +39,7 @@ instance HashAlgorithm Skein256_224 where -- | Skein256 (256 bits) cryptographic hash algorithm data Skein256_256 = Skein256_256 - deriving (Show,Data,Typeable) + deriving (Show,Data) instance HashAlgorithm Skein256_256 where type HashBlockSize Skein256_256 = 32 diff --git a/Crypto/Hash/Skein512.hs b/Crypto/Hash/Skein512.hs index 75d2407..a666d5d 100644 --- a/Crypto/Hash/Skein512.hs +++ b/Crypto/Hash/Skein512.hs @@ -19,13 +19,12 @@ module Crypto.Hash.Skein512 import Crypto.Hash.Types import Foreign.Ptr (Ptr) import Data.Data -import Data.Typeable import Data.Word (Word8, Word32) -- | Skein512 (224 bits) cryptographic hash algorithm data Skein512_224 = Skein512_224 - deriving (Show,Data,Typeable) + deriving (Show,Data) instance HashAlgorithm Skein512_224 where type HashBlockSize Skein512_224 = 64 @@ -40,7 +39,7 @@ instance HashAlgorithm Skein512_224 where -- | Skein512 (256 bits) cryptographic hash algorithm data Skein512_256 = Skein512_256 - deriving (Show,Data,Typeable) + deriving (Show,Data) instance HashAlgorithm Skein512_256 where type HashBlockSize Skein512_256 = 64 @@ -55,7 +54,7 @@ instance HashAlgorithm Skein512_256 where -- | Skein512 (384 bits) cryptographic hash algorithm data Skein512_384 = Skein512_384 - deriving (Show,Data,Typeable) + deriving (Show,Data) instance HashAlgorithm Skein512_384 where type HashBlockSize Skein512_384 = 64 @@ -70,7 +69,7 @@ instance HashAlgorithm Skein512_384 where -- | Skein512 (512 bits) cryptographic hash algorithm data Skein512_512 = Skein512_512 - deriving (Show,Data,Typeable) + deriving (Show,Data) instance HashAlgorithm Skein512_512 where type HashBlockSize Skein512_512 = 64 diff --git a/Crypto/Hash/Tiger.hs b/Crypto/Hash/Tiger.hs index de74a75..dd69476 100644 --- a/Crypto/Hash/Tiger.hs +++ b/Crypto/Hash/Tiger.hs @@ -17,12 +17,11 @@ module Crypto.Hash.Tiger ( Tiger (..) ) where import Crypto.Hash.Types import Foreign.Ptr (Ptr) import Data.Data -import Data.Typeable import Data.Word (Word8, Word32) -- | Tiger cryptographic hash algorithm data Tiger = Tiger - deriving (Show,Data,Typeable) + deriving (Show,Data) instance HashAlgorithm Tiger where type HashBlockSize Tiger = 64 diff --git a/Crypto/Hash/Whirlpool.hs b/Crypto/Hash/Whirlpool.hs index 3780565..8246176 100644 --- a/Crypto/Hash/Whirlpool.hs +++ b/Crypto/Hash/Whirlpool.hs @@ -17,12 +17,11 @@ module Crypto.Hash.Whirlpool ( Whirlpool (..) ) where import Crypto.Hash.Types import Foreign.Ptr (Ptr) import Data.Data -import Data.Typeable import Data.Word (Word8, Word32) -- | Whirlpool cryptographic hash algorithm data Whirlpool = Whirlpool - deriving (Show,Data,Typeable) + deriving (Show,Data) instance HashAlgorithm Whirlpool where type HashBlockSize Whirlpool = 64 diff --git a/Crypto/Internal/Nat.hs b/Crypto/Internal/Nat.hs index 3698a6b..dfa3a4d 100644 --- a/Crypto/Internal/Nat.hs +++ b/Crypto/Internal/Nat.hs @@ -22,7 +22,7 @@ integralNatVal :: (KnownNat bitlen, Num a) => proxy bitlen -> a integralNatVal = fromInteger . natVal type family IsLE (bitlen :: Nat) (n :: Nat) (c :: Bool) where - IsLE bitlen n 'True = 'True + IsLE _ _ 'True = 'True #if MIN_VERSION_base(4,9,0) IsLE bitlen n 'False = TypeError ( ('Text "bitlen " ':<>: 'ShowType bitlen ':<>: 'Text " is greater than " ':<>: 'ShowType n) @@ -37,7 +37,7 @@ type family IsLE (bitlen :: Nat) (n :: Nat) (c :: Bool) where type IsAtMost (bitlen :: Nat) (n :: Nat) = IsLE bitlen n (bitlen <=? n) ~ 'True type family IsGE (bitlen :: Nat) (n :: Nat) (c :: Bool) where - IsGE bitlen n 'True = 'True + IsGE _ _ 'True = 'True #if MIN_VERSION_base(4,9,0) IsGE bitlen n 'False = TypeError ( ('Text "bitlen " ':<>: 'ShowType bitlen ':<>: 'Text " is lesser than " ':<>: 'ShowType n) @@ -120,7 +120,7 @@ type family Div8 (bitLen :: Nat) where Div8 n = 8 + Div8 (n - 64) type family IsDiv8 (bitLen :: Nat) (n :: Nat) where - IsDiv8 bitLen 0 = 'True + IsDiv8 _ 0 = 'True #if MIN_VERSION_base(4,9,0) IsDiv8 bitLen 1 = TypeError ('Text "bitLen " ':<>: 'ShowType bitLen ':<>: 'Text " is not divisible by 8") IsDiv8 bitLen 2 = TypeError ('Text "bitLen " ':<>: 'ShowType bitLen ':<>: 'Text " is not divisible by 8") @@ -130,15 +130,15 @@ type family IsDiv8 (bitLen :: Nat) (n :: Nat) where IsDiv8 bitLen 6 = TypeError ('Text "bitLen " ':<>: 'ShowType bitLen ':<>: 'Text " is not divisible by 8") IsDiv8 bitLen 7 = TypeError ('Text "bitLen " ':<>: 'ShowType bitLen ':<>: 'Text " is not divisible by 8") #else - IsDiv8 bitLen 1 = 'False - IsDiv8 bitLen 2 = 'False - IsDiv8 bitLen 3 = 'False - IsDiv8 bitLen 4 = 'False - IsDiv8 bitLen 5 = 'False - IsDiv8 bitLen 6 = 'False - IsDiv8 bitLen 7 = 'False + IsDiv8 _ 1 = 'False + IsDiv8 _ 2 = 'False + IsDiv8 _ 3 = 'False + IsDiv8 _ 4 = 'False + IsDiv8 _ 5 = 'False + IsDiv8 _ 6 = 'False + IsDiv8 _ 7 = 'False #endif - IsDiv8 bitLen n = IsDiv8 n (Mod8 n) + IsDiv8 _ n = IsDiv8 n (Mod8 n) type family Mod8 (n :: Nat) where Mod8 0 = 0 diff --git a/Crypto/KDF/Argon2.hs b/Crypto/KDF/Argon2.hs index 53a8f89..044ba00 100644 --- a/Crypto/KDF/Argon2.hs +++ b/Crypto/KDF/Argon2.hs @@ -25,7 +25,7 @@ module Crypto.KDF.Argon2 , hash ) where -import Crypto.Internal.ByteArray (ScrubbedBytes, ByteArray, ByteArrayAccess) +import Crypto.Internal.ByteArray (ByteArray, ByteArrayAccess) import qualified Crypto.Internal.ByteArray as B import Crypto.Error import Control.Monad (when) diff --git a/Crypto/KDF/PBKDF2.hs b/Crypto/KDF/PBKDF2.hs index b18cc1a..7a3337c 100644 --- a/Crypto/KDF/PBKDF2.hs +++ b/Crypto/KDF/PBKDF2.hs @@ -24,7 +24,7 @@ import Data.Word import Data.Bits import Foreign.Marshal.Alloc import Foreign.Ptr (plusPtr, Ptr) -import Foreign.C.Types (CUInt(..), CInt(..), CSize(..)) +import Foreign.C.Types (CUInt(..), CSize(..)) import Crypto.Hash (HashAlgorithm) import qualified Crypto.MAC.HMAC as HMAC @@ -54,7 +54,7 @@ data Parameters = Parameters } -- | generate the pbkdf2 key derivation function from the output -generate :: (ByteArrayAccess password, ByteArrayAccess salt, ByteArray ba) +generate :: (ByteArrayAccess salt, ByteArray ba) => PRF password -> Parameters -> password diff --git a/Crypto/MAC/HMAC.hs b/Crypto/MAC/HMAC.hs index f44008a..4582703 100644 --- a/Crypto/MAC/HMAC.hs +++ b/Crypto/MAC/HMAC.hs @@ -24,11 +24,10 @@ module Crypto.MAC.HMAC import Crypto.Hash hiding (Context) import qualified Crypto.Hash as Hash (Context) import Crypto.Hash.IO -import Crypto.Internal.ByteArray (ScrubbedBytes, ByteArray, ByteArrayAccess) +import Crypto.Internal.ByteArray (ScrubbedBytes, ByteArrayAccess) import qualified Crypto.Internal.ByteArray as B import Data.Memory.PtrMethods import Crypto.Internal.Compat -import Crypto.Internal.Imports -- | Represent an HMAC that is a phantom type with the hash used to produce the mac. -- diff --git a/Crypto/Number/F2m.hs b/Crypto/Number/F2m.hs index 503c309..93b1f48 100644 --- a/Crypto/Number/F2m.hs +++ b/Crypto/Number/F2m.hs @@ -23,7 +23,6 @@ module Crypto.Number.F2m import Data.Bits (xor, shift, testBit, setBit) import Data.List -import Crypto.Internal.Imports import Crypto.Number.Basic -- | Binary Polynomial represented by an integer diff --git a/Crypto/Number/ModArithmetic.hs b/Crypto/Number/ModArithmetic.hs index ef59d7e..dcd8663 100644 --- a/Crypto/Number/ModArithmetic.hs +++ b/Crypto/Number/ModArithmetic.hs @@ -19,13 +19,12 @@ module Crypto.Number.ModArithmetic ) where import Control.Exception (throw, Exception) -import Data.Typeable import Crypto.Number.Basic import Crypto.Number.Compat -- | Raised when two numbers are supposed to be coprimes but are not. data CoprimesAssertionError = CoprimesAssertionError - deriving (Show,Typeable) + deriving (Show) instance Exception CoprimesAssertionError diff --git a/Crypto/Number/Prime.hs b/Crypto/Number/Prime.hs index 19faaa9..e48477d 100644 --- a/Crypto/Number/Prime.hs +++ b/Crypto/Number/Prime.hs @@ -19,8 +19,6 @@ module Crypto.Number.Prime , isCoprime ) where -import Crypto.Internal.Imports - import Crypto.Number.Compat import Crypto.Number.Generate import Crypto.Number.Basic (sqrti, gcde) diff --git a/Crypto/OTP.hs b/Crypto/OTP.hs index 71c1e74..9b5b383 100644 --- a/Crypto/OTP.hs +++ b/Crypto/OTP.hs @@ -42,15 +42,14 @@ module Crypto.OTP ) where -import Data.Bits (shiftL, shiftR, (.&.), (.|.)) +import Data.Bits (shiftL, (.&.), (.|.)) import Data.ByteArray.Mapping (fromW64BE) import Data.List (elemIndex) import Data.Word -import Foreign.Storable (poke) import Control.Monad (unless) import Crypto.Hash (HashAlgorithm, SHA1(..)) import Crypto.MAC.HMAC -import Crypto.Internal.ByteArray (ByteArrayAccess, ByteArray, Bytes) +import Crypto.Internal.ByteArray (ByteArrayAccess, Bytes) import qualified Crypto.Internal.ByteArray as B @@ -130,8 +129,8 @@ defaultTOTPParams :: TOTPParams SHA1 defaultTOTPParams = TP SHA1 0 30 OTP6 TwoSteps -- | Create a TOTP configuration with customized parameters. -mkTOTPParams :: (HashAlgorithm hash) - => hash +mkTOTPParams :: + hash -> OTPTime -- ^ The T0 parameter in seconds. This is the Unix time from which to start -- counting steps (default 0). Must be before the current time. diff --git a/Crypto/PubKey/Curve25519.hs b/Crypto/PubKey/Curve25519.hs index 720ff9a..d85de91 100644 --- a/Crypto/PubKey/Curve25519.hs +++ b/Crypto/PubKey/Curve25519.hs @@ -33,7 +33,7 @@ import GHC.Ptr import Crypto.Error import Crypto.Internal.Compat import Crypto.Internal.Imports -import Crypto.Internal.ByteArray (ByteArrayAccess, ByteArray, ScrubbedBytes, Bytes, withByteArray) +import Crypto.Internal.ByteArray (ByteArrayAccess, ScrubbedBytes, Bytes, withByteArray) import qualified Crypto.Internal.ByteArray as B import Crypto.Error (CryptoFailable(..)) import Crypto.Random diff --git a/Crypto/PubKey/Curve448.hs b/Crypto/PubKey/Curve448.hs index 0900773..7146e56 100644 --- a/Crypto/PubKey/Curve448.hs +++ b/Crypto/PubKey/Curve448.hs @@ -28,7 +28,6 @@ module Crypto.PubKey.Curve448 import Data.Word import Foreign.Ptr -import GHC.Ptr import Crypto.Error import Crypto.Random diff --git a/Crypto/PubKey/DH.hs b/Crypto/PubKey/DH.hs index 152b1b5..db4de76 100644 --- a/Crypto/PubKey/DH.hs +++ b/Crypto/PubKey/DH.hs @@ -33,7 +33,7 @@ data Params = Params { params_p :: Integer , params_g :: Integer , params_bits :: Int - } deriving (Show,Read,Eq,Data,Typeable) + } deriving (Show,Read,Eq,Data) instance NFData Params where rnf (Params p g bits) = rnf p `seq` rnf g `seq` bits `seq` () diff --git a/Crypto/PubKey/DSA.hs b/Crypto/PubKey/DSA.hs index 35fbf37..0f8c0b5 100644 --- a/Crypto/PubKey/DSA.hs +++ b/Crypto/PubKey/DSA.hs @@ -51,7 +51,7 @@ data Params = Params { params_p :: Integer -- ^ DSA p , params_g :: Integer -- ^ DSA g , params_q :: Integer -- ^ DSA q - } deriving (Show,Read,Eq,Data,Typeable) + } deriving (Show,Read,Eq,Data) instance NFData Params where rnf (Params p g q) = p `seq` g `seq` q `seq` () @@ -60,7 +60,7 @@ instance NFData Params where data Signature = Signature { sign_r :: Integer -- ^ DSA r , sign_s :: Integer -- ^ DSA s - } deriving (Show,Read,Eq,Data,Typeable) + } deriving (Show,Read,Eq,Data) instance NFData Signature where rnf (Signature r s) = r `seq` s `seq` () @@ -69,7 +69,7 @@ instance NFData Signature where data PublicKey = PublicKey { public_params :: Params -- ^ DSA parameters , public_y :: PublicNumber -- ^ DSA public Y - } deriving (Show,Read,Eq,Data,Typeable) + } deriving (Show,Read,Eq,Data) instance NFData PublicKey where rnf (PublicKey params y) = y `seq` params `seq` () @@ -81,14 +81,14 @@ instance NFData PublicKey where data PrivateKey = PrivateKey { private_params :: Params -- ^ DSA parameters , private_x :: PrivateNumber -- ^ DSA private X - } deriving (Show,Read,Eq,Data,Typeable) + } deriving (Show,Read,Eq,Data) instance NFData PrivateKey where rnf (PrivateKey params x) = x `seq` params `seq` () -- | Represent a DSA key pair data KeyPair = KeyPair Params PublicNumber PrivateNumber - deriving (Show,Read,Eq,Data,Typeable) + deriving (Show,Read,Eq,Data) instance NFData KeyPair where rnf (KeyPair params y x) = x `seq` y `seq` params `seq` () diff --git a/Crypto/PubKey/ECC/ECDSA.hs b/Crypto/PubKey/ECC/ECDSA.hs index 6c51242..4cfc4b8 100644 --- a/Crypto/PubKey/ECC/ECDSA.hs +++ b/Crypto/PubKey/ECC/ECDSA.hs @@ -31,23 +31,23 @@ import Crypto.Random.Types data Signature = Signature { sign_r :: Integer -- ^ ECDSA r , sign_s :: Integer -- ^ ECDSA s - } deriving (Show,Read,Eq,Data,Typeable) + } deriving (Show,Read,Eq,Data) -- | ECDSA Private Key. data PrivateKey = PrivateKey { private_curve :: Curve , private_d :: PrivateNumber - } deriving (Show,Read,Eq,Data,Typeable) + } deriving (Show,Read,Eq,Data) -- | ECDSA Public Key. data PublicKey = PublicKey { public_curve :: Curve , public_q :: PublicPoint - } deriving (Show,Read,Eq,Data,Typeable) + } deriving (Show,Read,Eq,Data) -- | ECDSA Key Pair. data KeyPair = KeyPair Curve PublicPoint PrivateNumber - deriving (Show,Read,Eq,Data,Typeable) + deriving (Show,Read,Eq,Data) -- | Public key of a ECDSA Key pair. toPublicKey :: KeyPair -> PublicKey diff --git a/Crypto/PubKey/ECC/Types.hs b/Crypto/PubKey/ECC/Types.hs index 4f34f2e..ac2c9f5 100644 --- a/Crypto/PubKey/ECC/Types.hs +++ b/Crypto/PubKey/ECC/Types.hs @@ -33,7 +33,7 @@ import Crypto.Number.Basic (numBits) -- | Define either a binary curve or a prime curve. data Curve = CurveF2m CurveBinary -- ^ 𝔽(2^m) | CurveFP CurvePrime -- ^ 𝔽p - deriving (Show,Read,Eq,Data,Typeable) + deriving (Show,Read,Eq,Data) -- | ECC Public Point type PublicPoint = Point @@ -44,7 +44,7 @@ type PrivateNumber = Integer -- | Define a point on a curve. data Point = Point Integer Integer | PointO -- ^ Point at Infinity - deriving (Show,Read,Eq,Data,Typeable) + deriving (Show,Read,Eq,Data) instance NFData Point where rnf (Point x y) = x `seq` y `seq` () @@ -53,7 +53,7 @@ instance NFData Point where -- | Define an elliptic curve in 𝔽(2^m). -- The firt parameter is the Integer representatioin of the irreducible polynomial f(x). data CurveBinary = CurveBinary Integer CurveCommon - deriving (Show,Read,Eq,Data,Typeable) + deriving (Show,Read,Eq,Data) instance NFData CurveBinary where rnf (CurveBinary i cc) = i `seq` cc `seq` () @@ -61,7 +61,7 @@ instance NFData CurveBinary where -- | Define an elliptic curve in 𝔽p. -- The first parameter is the Prime Number. data CurvePrime = CurvePrime Integer CurveCommon - deriving (Show,Read,Eq,Data,Typeable) + deriving (Show,Read,Eq,Data) -- | Parameters in common between binary and prime curves. common_curve :: Curve -> CurveCommon @@ -84,7 +84,7 @@ data CurveCommon = CurveCommon , ecc_g :: Point -- ^ base point , ecc_n :: Integer -- ^ order of G , ecc_h :: Integer -- ^ cofactor - } deriving (Show,Read,Eq,Data,Typeable) + } deriving (Show,Read,Eq,Data) -- | Define names for known recommended curves. data CurveName = @@ -121,7 +121,7 @@ data CurveName = | SEC_t409r1 | SEC_t571k1 | SEC_t571r1 - deriving (Show,Read,Eq,Ord,Enum,Bounded,Data,Typeable) + deriving (Show,Read,Eq,Ord,Enum,Bounded,Data) {- curvesOIDs :: [ (CurveName, [Integer]) ] diff --git a/Crypto/PubKey/ECIES.hs b/Crypto/PubKey/ECIES.hs index 7c9c3aa..c6b92ec 100644 --- a/Crypto/PubKey/ECIES.hs +++ b/Crypto/PubKey/ECIES.hs @@ -27,7 +27,6 @@ module Crypto.PubKey.ECIES import Crypto.ECC import Crypto.Error import Crypto.Random -import Crypto.Internal.Proxy -- | Generate random a new Shared secret and the associated point -- to do a ECIES style encryption diff --git a/Crypto/PubKey/RSA.hs b/Crypto/PubKey/RSA.hs index 131da3d..3ce15da 100644 --- a/Crypto/PubKey/RSA.hs +++ b/Crypto/PubKey/RSA.hs @@ -16,7 +16,6 @@ module Crypto.PubKey.RSA , generateBlinder ) where -import Crypto.Internal.Imports import Crypto.Random.Types import Crypto.Number.ModArithmetic (inverse, inverseCoprimes) import Crypto.Number.Generate (generateMax) diff --git a/Crypto/PubKey/RSA/Types.hs b/Crypto/PubKey/RSA/Types.hs index d3ac487..ae29d27 100644 --- a/Crypto/PubKey/RSA/Types.hs +++ b/Crypto/PubKey/RSA/Types.hs @@ -42,7 +42,7 @@ data PublicKey = PublicKey { public_size :: Int -- ^ size of key in bytes , public_n :: Integer -- ^ public p*q , public_e :: Integer -- ^ public exponent e - } deriving (Show,Read,Eq,Data,Typeable) + } deriving (Show,Read,Eq,Data) instance NFData PublicKey where rnf (PublicKey sz n e) = rnf n `seq` rnf e `seq` sz `seq` () @@ -65,7 +65,7 @@ data PrivateKey = PrivateKey , private_dP :: Integer -- ^ d mod (p-1) , private_dQ :: Integer -- ^ d mod (q-1) , private_qinv :: Integer -- ^ q^(-1) mod p - } deriving (Show,Read,Eq,Data,Typeable) + } deriving (Show,Read,Eq,Data) instance NFData PrivateKey where rnf (PrivateKey pub d p q dp dq qinv) = @@ -87,7 +87,7 @@ private_e = public_e . private_pub -- -- note the RSA private key contains already an instance of public key for efficiency newtype KeyPair = KeyPair PrivateKey - deriving (Show,Read,Eq,Data,Typeable,NFData) + deriving (Show,Read,Eq,Data,NFData) -- | Public key of a RSA KeyPair toPublicKey :: KeyPair -> PublicKey diff --git a/Crypto/PubKey/Rabin/Basic.hs b/Crypto/PubKey/Rabin/Basic.hs index bcce97a..b05269a 100644 --- a/Crypto/PubKey/Rabin/Basic.hs +++ b/Crypto/PubKey/Rabin/Basic.hs @@ -27,9 +27,8 @@ import Data.Data import Data.Either (rights) import Crypto.Hash -import Crypto.Number.Basic (gcde, numBytes, asPowerOf2AndOdd) +import Crypto.Number.Basic (gcde, numBytes) import Crypto.Number.ModArithmetic (expSafe, jacobi) -import Crypto.Number.Prime (isProbablyPrime) import Crypto.Number.Serialize (i2osp, i2ospOf_, os2ip) import Crypto.PubKey.Rabin.OAEP import Crypto.PubKey.Rabin.Types @@ -39,7 +38,7 @@ import Crypto.Random (MonadRandom, getRandomBytes) data PublicKey = PublicKey { public_size :: Int -- ^ size of key in bytes , public_n :: Integer -- ^ public p*q - } deriving (Show, Read, Eq, Data, Typeable) + } deriving (Show, Read, Eq, Data) -- | Represent a Rabin private key. data PrivateKey = PrivateKey @@ -48,10 +47,10 @@ data PrivateKey = PrivateKey , private_q :: Integer -- ^ q prime number , private_a :: Integer , private_b :: Integer - } deriving (Show, Read, Eq, Data, Typeable) + } deriving (Show, Read, Eq, Data) -- | Rabin Signature. -data Signature = Signature (Integer, Integer) deriving (Show, Read, Eq, Data, Typeable) +data Signature = Signature (Integer, Integer) deriving (Show, Read, Eq, Data) -- | Generate a pair of (private, public) key of size in bytes. -- Primes p and q are both congruent 3 mod 4. diff --git a/Crypto/PubKey/Rabin/Modified.hs b/Crypto/PubKey/Rabin/Modified.hs index f3836ab..e7ea7d7 100644 --- a/Crypto/PubKey/Rabin/Modified.hs +++ b/Crypto/PubKey/Rabin/Modified.hs @@ -18,13 +18,11 @@ module Crypto.PubKey.Rabin.Modified ) where import Data.ByteString -import qualified Data.ByteString as B import Data.Data import Crypto.Hash -import Crypto.Number.Basic (gcde) import Crypto.Number.ModArithmetic (expSafe, jacobi) -import Crypto.Number.Serialize (i2osp, os2ip) +import Crypto.Number.Serialize (os2ip) import Crypto.PubKey.Rabin.Types import Crypto.Random.Types @@ -32,7 +30,7 @@ import Crypto.Random.Types data PublicKey = PublicKey { public_size :: Int -- ^ size of key in bytes , public_n :: Integer -- ^ public p*q - } deriving (Show, Read, Eq, Data, Typeable) + } deriving (Show, Read, Eq, Data) -- | Represent a Modified-Rabin private key. data PrivateKey = PrivateKey @@ -40,7 +38,7 @@ data PrivateKey = PrivateKey , private_p :: Integer -- ^ p prime number , private_q :: Integer -- ^ q prime number , private_d :: Integer - } deriving (Show, Read, Eq, Data, Typeable) + } deriving (Show, Read, Eq, Data) -- | Generate a pair of (private, public) key of size in bytes. -- Prime p is congruent 3 mod 8 and prime q is congruent 7 mod 8. diff --git a/Crypto/PubKey/Rabin/RW.hs b/Crypto/PubKey/Rabin/RW.hs index 7b0bcaa..1aec25c 100644 --- a/Crypto/PubKey/Rabin/RW.hs +++ b/Crypto/PubKey/Rabin/RW.hs @@ -22,11 +22,10 @@ module Crypto.PubKey.Rabin.RW ) where import Data.ByteString -import qualified Data.ByteString as B import Data.Data import Crypto.Hash -import Crypto.Number.Basic (numBytes, gcde) +import Crypto.Number.Basic (numBytes) import Crypto.Number.ModArithmetic (expSafe, jacobi) import Crypto.Number.Serialize (i2osp, i2ospOf_, os2ip) import Crypto.PubKey.Rabin.OAEP @@ -37,7 +36,7 @@ import Crypto.Random.Types data PublicKey = PublicKey { public_size :: Int -- ^ size of key in bytes , public_n :: Integer -- ^ public p*q - } deriving (Show, Read, Eq, Data, Typeable) + } deriving (Show, Read, Eq, Data) -- | Represent a Rabin-Williams private key. data PrivateKey = PrivateKey @@ -45,7 +44,7 @@ data PrivateKey = PrivateKey , private_p :: Integer -- ^ p prime number , private_q :: Integer -- ^ q prime number , private_d :: Integer - } deriving (Show, Read, Eq, Data, Typeable) + } deriving (Show, Read, Eq, Data) -- | Generate a pair of (private, public) key of size in bytes. -- Prime p is congruent 3 mod 8 and prime q is congruent 7 mod 8. diff --git a/Crypto/Random/ChaChaDRG.hs b/Crypto/Random/ChaChaDRG.hs index e23a444..5062b59 100644 --- a/Crypto/Random/ChaChaDRG.hs +++ b/Crypto/Random/ChaChaDRG.hs @@ -29,7 +29,7 @@ newtype ChaChaDRG = ChaChaDRG C.StateSimple -- | Initialize a new ChaCha context with the number of rounds, -- the key and the nonce associated. -initialize :: B.ByteArrayAccess seed +initialize :: ByteArrayAccess seed => seed -- ^ 40 bytes of seed -> ChaChaDRG -- ^ the initial ChaCha state initialize seed = ChaChaDRG $ C.initializeSimple seed diff --git a/Crypto/Random/SystemDRG.hs b/Crypto/Random/SystemDRG.hs index 50872f2..4f401ca 100644 --- a/Crypto/Random/SystemDRG.hs +++ b/Crypto/Random/SystemDRG.hs @@ -14,7 +14,6 @@ module Crypto.Random.SystemDRG import Crypto.Random.Types import Crypto.Random.Entropy.Unsafe import Crypto.Internal.Compat -import Crypto.Internal.Imports import Data.ByteArray (ScrubbedBytes, ByteArray) import Data.Memory.PtrMethods as B (memCopy) import Data.Maybe (catMaybes) diff --git a/Crypto/Random/Types.hs b/Crypto/Random/Types.hs index 8bcee6f..2806fc3 100644 --- a/Crypto/Random/Types.hs +++ b/Crypto/Random/Types.hs @@ -15,7 +15,6 @@ module Crypto.Random.Types import Crypto.Random.Entropy import Crypto.Internal.ByteArray -import Crypto.Internal.Imports -- | A monad constraint that allows to generate random bytes class (Functor m, Monad m) => MonadRandom m where @@ -47,7 +46,7 @@ instance DRG gen => Applicative (MonadPseudoRandom gen) where in (f a, g3) instance DRG gen => Monad (MonadPseudoRandom gen) where - return a = MonadPseudoRandom $ \g -> (a, g) + return = pure (>>=) m1 m2 = MonadPseudoRandom $ \g1 -> let (a, g2) = runPseudoRandom m1 g1 in runPseudoRandom (m2 a) g2 @@ -57,5 +56,5 @@ instance DRG gen => MonadRandom (MonadPseudoRandom gen) where -- | Run a pure computation with a Deterministic Random Generator -- in the 'MonadPseudoRandom' -withDRG :: DRG gen => gen -> MonadPseudoRandom gen a -> (a, gen) +withDRG :: gen -> MonadPseudoRandom gen a -> (a, gen) withDRG gen m = runPseudoRandom m gen diff --git a/stack.yaml b/stack.yaml index 946d1a4..bf246bb 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,3 +1,3 @@ # ~*~ auto-generated by haskell-ci with config : 8f74deffc95fd794fa2996c167c6543bbfab1ae432f0a83e0898f0b5871a92eb ~*~ -{ resolver: lts-12.26, packages: [ '.' ], extra-deps: [], flags: {} } +{ resolver: lts-13.2, packages: [ '.' ], extra-deps: [], flags: {} } diff --git a/tests/BlockCipher.hs b/tests/BlockCipher.hs index 2fc1248..38adcb2 100644 --- a/tests/BlockCipher.hs +++ b/tests/BlockCipher.hs @@ -307,7 +307,7 @@ generateIvAEAD :: Gen B.ByteString generateIvAEAD = choose (12,90) >>= \sz -> (B.pack <$> replicateM sz arbitrary) -- | Generate a plaintext multiple of blocksize bytes -generatePlaintextMultipleBS :: BlockCipher a => Gen (PlaintextBS a) +generatePlaintextMultipleBS :: Gen (PlaintextBS a) generatePlaintextMultipleBS = choose (1,128) >>= \size -> replicateM (size * 16) arbitrary >>= return . PlaintextBS . B.pack -- | Generate any sized plaintext @@ -474,7 +474,7 @@ testBlockCipher kats cipher = testGroup (cipherName cipher) ++ testModes cipher ++ testIvArith cipher ) -cipherMakeKey :: Cipher cipher => cipher -> ByteString -> Key cipher +cipherMakeKey :: cipher -> ByteString -> Key cipher cipherMakeKey _ bs = Key bs cipherMakeIV :: BlockCipher cipher => cipher -> ByteString -> IV cipher diff --git a/tests/KAT_CAST5.hs b/tests/KAT_CAST5.hs index c220760..6d35862 100644 --- a/tests/KAT_CAST5.hs +++ b/tests/KAT_CAST5.hs @@ -1,7 +1,6 @@ {-# LANGUAGE OverloadedStrings #-} module KAT_CAST5 (tests) where -import Imports import BlockCipher import qualified Crypto.Cipher.CAST5 as CAST5 diff --git a/tests/KAT_HKDF.hs b/tests/KAT_HKDF.hs index 1593cf9..cb72892 100644 --- a/tests/KAT_HKDF.hs +++ b/tests/KAT_HKDF.hs @@ -2,10 +2,7 @@ module KAT_HKDF (tests) where import qualified Crypto.KDF.HKDF as HKDF -import Crypto.Hash (MD5(..), SHA1(..), SHA256(..) - , Keccak_224(..), Keccak_256(..), Keccak_384(..), Keccak_512(..) - , SHA3_224(..), SHA3_256(..), SHA3_384(..), SHA3_512(..) - , HashAlgorithm, digestFromByteString) +import Crypto.Hash (SHA256(..), HashAlgorithm) import qualified Data.ByteString as B import Imports diff --git a/tests/KAT_MiyaguchiPreneel.hs b/tests/KAT_MiyaguchiPreneel.hs index 163e434..9928622 100644 --- a/tests/KAT_MiyaguchiPreneel.hs +++ b/tests/KAT_MiyaguchiPreneel.hs @@ -6,7 +6,6 @@ import Crypto.ConstructHash.MiyaguchiPreneel as MiyaguchiPreneel import Imports -import Data.Char (digitToInt) import qualified Data.ByteString.Char8 as B8 import qualified Data.ByteArray as B import Data.ByteArray.Encoding (Base (Base16), convertFromBase) diff --git a/tests/KAT_OTP.hs b/tests/KAT_OTP.hs index d4d946f..f6fc1b6 100644 --- a/tests/KAT_OTP.hs +++ b/tests/KAT_OTP.hs @@ -94,9 +94,9 @@ tests = testGroup "OTP" ] , testGroup "TOTP" [ testGroup "KATs" - [ testGroup "SHA1" (makeKATs (totp totpSHA1Params otpKey . fromIntegral) totpSHA1Expected) - , testGroup "SHA256" (makeKATs (totp totpSHA256Params totpSHA256Key . fromIntegral) totpSHA256Expected) - , testGroup "SHA512" (makeKATs (totp totpSHA512Params totpSHA512Key . fromIntegral) totpSHA512Expected) + [ testGroup "SHA1" (makeKATs (totp totpSHA1Params otpKey) totpSHA1Expected) + , testGroup "SHA256" (makeKATs (totp totpSHA256Params totpSHA256Key) totpSHA256Expected) + , testGroup "SHA512" (makeKATs (totp totpSHA512Params totpSHA512Key) totpSHA512Expected) ] ] ] diff --git a/tests/Padding.hs b/tests/Padding.hs index f7be773..cc4dcf6 100644 --- a/tests/Padding.hs +++ b/tests/Padding.hs @@ -3,7 +3,6 @@ module Padding (tests) where import qualified Data.ByteString as B import Imports -import Crypto.Error import Crypto.Data.Padding From 133c6e1b2d159b9170c0a50587534dff69a6e557 Mon Sep 17 00:00:00 2001 From: Crockett Date: Sun, 24 Feb 2019 17:04:10 -0800 Subject: [PATCH 2/2] Added some redundant constraints for documentation/consistency. Added an INLINABLE pragma to i2ospOf to hopefully increase specializations. --- Crypto/KDF/PBKDF2.hs | 2 +- Crypto/Number/Serialize.hs | 1 + Crypto/OTP.hs | 4 ++-- Crypto/Random/Types.hs | 2 +- tests/BlockCipher.hs | 4 ++-- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Crypto/KDF/PBKDF2.hs b/Crypto/KDF/PBKDF2.hs index 7a3337c..027086e 100644 --- a/Crypto/KDF/PBKDF2.hs +++ b/Crypto/KDF/PBKDF2.hs @@ -54,7 +54,7 @@ data Parameters = Parameters } -- | generate the pbkdf2 key derivation function from the output -generate :: (ByteArrayAccess salt, ByteArray ba) +generate :: (ByteArrayAccess password, ByteArrayAccess salt, ByteArray ba) => PRF password -> Parameters -> password diff --git a/Crypto/Number/Serialize.hs b/Crypto/Number/Serialize.hs index 9855c5b..858e848 100644 --- a/Crypto/Number/Serialize.hs +++ b/Crypto/Number/Serialize.hs @@ -35,6 +35,7 @@ i2osp m = B.allocAndFreeze sz (\p -> Internal.i2osp m p sz >> return ()) -- | Just like 'i2osp', but takes an extra parameter for size. -- If the number is too big to fit in @len@ bytes, 'Nothing' is returned -- otherwise the number is padded with 0 to fit the @len@ required. +{-# INLINABLE i2ospOf #-} i2ospOf :: B.ByteArray ba => Int -> Integer -> Maybe ba i2ospOf len m | len <= 0 = Nothing diff --git a/Crypto/OTP.hs b/Crypto/OTP.hs index 9b5b383..44503ff 100644 --- a/Crypto/OTP.hs +++ b/Crypto/OTP.hs @@ -129,8 +129,8 @@ defaultTOTPParams :: TOTPParams SHA1 defaultTOTPParams = TP SHA1 0 30 OTP6 TwoSteps -- | Create a TOTP configuration with customized parameters. -mkTOTPParams :: - hash +mkTOTPParams :: (HashAlgorithm hash) + => hash -> OTPTime -- ^ The T0 parameter in seconds. This is the Unix time from which to start -- counting steps (default 0). Must be before the current time. diff --git a/Crypto/Random/Types.hs b/Crypto/Random/Types.hs index 2806fc3..961be8a 100644 --- a/Crypto/Random/Types.hs +++ b/Crypto/Random/Types.hs @@ -56,5 +56,5 @@ instance DRG gen => MonadRandom (MonadPseudoRandom gen) where -- | Run a pure computation with a Deterministic Random Generator -- in the 'MonadPseudoRandom' -withDRG :: gen -> MonadPseudoRandom gen a -> (a, gen) +withDRG :: DRG gen => gen -> MonadPseudoRandom gen a -> (a, gen) withDRG gen m = runPseudoRandom m gen diff --git a/tests/BlockCipher.hs b/tests/BlockCipher.hs index 38adcb2..2fc1248 100644 --- a/tests/BlockCipher.hs +++ b/tests/BlockCipher.hs @@ -307,7 +307,7 @@ generateIvAEAD :: Gen B.ByteString generateIvAEAD = choose (12,90) >>= \sz -> (B.pack <$> replicateM sz arbitrary) -- | Generate a plaintext multiple of blocksize bytes -generatePlaintextMultipleBS :: Gen (PlaintextBS a) +generatePlaintextMultipleBS :: BlockCipher a => Gen (PlaintextBS a) generatePlaintextMultipleBS = choose (1,128) >>= \size -> replicateM (size * 16) arbitrary >>= return . PlaintextBS . B.pack -- | Generate any sized plaintext @@ -474,7 +474,7 @@ testBlockCipher kats cipher = testGroup (cipherName cipher) ++ testModes cipher ++ testIvArith cipher ) -cipherMakeKey :: cipher -> ByteString -> Key cipher +cipherMakeKey :: Cipher cipher => cipher -> ByteString -> Key cipher cipherMakeKey _ bs = Key bs cipherMakeIV :: BlockCipher cipher => cipher -> ByteString -> IV cipher