Merge pull request #267 from crockeea/master-clean

Code maintenance and cleanup
This commit is contained in:
Olivier Chéron 2019-02-25 06:36:11 +01:00
commit 540ef78abb
67 changed files with 127 additions and 186 deletions

View File

@ -19,8 +19,6 @@ import Crypto.Cipher.Types.Block
import Crypto.Cipher.AES.Primitive import Crypto.Cipher.AES.Primitive
import Crypto.Internal.Imports import Crypto.Internal.Imports
import Data.ByteArray as BA
-- | AES with 128 bit key -- | AES with 128 bit key
newtype AES128 = AES128 AES newtype AES128 = AES128 AES
deriving (NFData) deriving (NFData)

View File

@ -48,7 +48,7 @@ initialize nbRounds key nonce
stPtr <- B.alloc 132 $ \stPtr -> stPtr <- B.alloc 132 $ \stPtr ->
B.withByteArray nonce $ \noncePtr -> B.withByteArray nonce $ \noncePtr ->
B.withByteArray key $ \keyPtr -> 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 return $ State stPtr
where kLen = B.length key where kLen = B.length key
nonceLen = B.length nonce nonceLen = B.length nonce

View File

@ -40,7 +40,7 @@ initialize nbRounds key nonce
stPtr <- B.alloc 132 $ \stPtr -> stPtr <- B.alloc 132 $ \stPtr ->
B.withByteArray nonce $ \noncePtr -> B.withByteArray nonce $ \noncePtr ->
B.withByteArray key $ \keyPtr -> 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 return $ State stPtr
where kLen = B.length key where kLen = B.length key
nonceLen = B.length nonce nonceLen = B.length nonce

View File

@ -7,7 +7,6 @@ module Crypto.Cipher.Twofish
import Crypto.Cipher.Twofish.Primitive import Crypto.Cipher.Twofish.Primitive
import Crypto.Cipher.Types import Crypto.Cipher.Types
import Crypto.Cipher.Utils import Crypto.Cipher.Utils
import Crypto.Internal.Imports
newtype Twofish128 = Twofish128 Twofish newtype Twofish128 = Twofish128 Twofish

View File

@ -8,15 +8,12 @@ module Crypto.Cipher.Twofish.Primitive
) where ) where
import Crypto.Error import Crypto.Error
import Crypto.Internal.ByteArray (ByteArrayAccess, ByteArray, Bytes) import Crypto.Internal.ByteArray (ByteArray)
import qualified Crypto.Internal.ByteArray as B import qualified Crypto.Internal.ByteArray as B
import Crypto.Internal.WordArray import Crypto.Internal.WordArray
import Crypto.Internal.Words
import Data.Word import Data.Word
import Data.Int
import Data.Bits import Data.Bits
import Data.List import Data.List
import Control.Monad
-- Based on the Golang referance implementation -- Based on the Golang referance implementation
-- https://github.com/golang/crypto/blob/master/twofish/twofish.go -- 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) 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') genSboxes keyPackage ws = (mkArray b0', mkArray b1', mkArray b2', mkArray b3')
where range = [0..255] where range = [0..255]
mkArray = array32 256 mkArray = array32 256

View File

@ -37,7 +37,6 @@ module Crypto.Cipher.Types.Block
) where ) where
import Data.Word import Data.Word
import Data.Monoid
import Crypto.Error import Crypto.Error
import Crypto.Cipher.Types.Base import Crypto.Cipher.Types.Base
import Crypto.Cipher.Types.GF import Crypto.Cipher.Types.GF
@ -164,7 +163,7 @@ nullIV = toIV undefined
-- | Increment an IV by a number. -- | Increment an IV by a number.
-- --
-- Assume the IV is in Big Endian format. -- 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 ivAdd (IV b) i = IV $ copy b
where copy :: ByteArray bs => bs -> bs where copy :: ByteArray bs => bs -> bs
copy bs = B.copyAndFreeze bs $ loop i (B.length bs - 1) copy bs = B.copyAndFreeze bs $ loop i (B.length bs - 1)

View File

@ -4,7 +4,6 @@ module Crypto.Cipher.Utils
import Crypto.Error import Crypto.Error
import Crypto.Cipher.Types import Crypto.Cipher.Types
import Crypto.Internal.Imports
import Data.ByteArray as BA import Data.ByteArray as BA

View File

@ -17,13 +17,11 @@ module Crypto.Cipher.XSalsa
, State , State
) where ) where
import Crypto.Internal.ByteArray (ByteArrayAccess, ByteArray, ScrubbedBytes) import Crypto.Internal.ByteArray (ByteArrayAccess)
import qualified Crypto.Internal.ByteArray as B import qualified Crypto.Internal.ByteArray as B
import Crypto.Internal.Compat import Crypto.Internal.Compat
import Crypto.Internal.Imports import Crypto.Internal.Imports
import Foreign.Ptr import Foreign.Ptr
import Foreign.Storable
import Foreign.C.Types
import Crypto.Cipher.Salsa hiding (initialize) import Crypto.Cipher.Salsa hiding (initialize)
-- | Initialize a new XSalsa context with the number of rounds, -- | Initialize a new XSalsa context with the number of rounds,
@ -41,7 +39,7 @@ initialize nbRounds key nonce
stPtr <- B.alloc 132 $ \stPtr -> stPtr <- B.alloc 132 $ \stPtr ->
B.withByteArray nonce $ \noncePtr -> B.withByteArray nonce $ \noncePtr ->
B.withByteArray key $ \keyPtr -> 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 return $ State stPtr
where kLen = B.length key where kLen = B.length key
nonceLen = B.length nonce nonceLen = B.length nonce

View File

@ -77,7 +77,7 @@ split hashAlg rng expandTimes src
diffuse hashAlg lastBlock blockSize diffuse hashAlg lastBlock blockSize
fillRandomBlock g blockPtr = do fillRandomBlock g blockPtr = do
let (rand :: Bytes, g') = randomBytesGenerate blockSize g 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' return g'
-- | Merge previously diffused data back to the original data. -- | Merge previously diffused data back to the original data.

View File

@ -38,10 +38,9 @@ import qualified Crypto.Internal.ByteArray as B
import Crypto.Number.Serialize (i2ospOf_, os2ip) import Crypto.Number.Serialize (i2ospOf_, os2ip)
import qualified Crypto.PubKey.Curve25519 as X25519 import qualified Crypto.PubKey.Curve25519 as X25519
import qualified Crypto.PubKey.Curve448 as X448 import qualified Crypto.PubKey.Curve448 as X448
import Data.Function (on)
import Data.ByteArray (convert) import Data.ByteArray (convert)
import Data.Data (Data()) 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 -- | An elliptic curve key pair composed of the private part (a scalar), and
-- the associated point. -- the associated point.
@ -55,10 +54,10 @@ newtype SharedSecret = SharedSecret ScrubbedBytes
class EllipticCurve curve where class EllipticCurve curve where
-- | Point on an Elliptic Curve -- | Point on an Elliptic Curve
type Point curve :: * type Point curve :: Type
-- | Scalar in the Elliptic Curve domain -- | Scalar in the Elliptic Curve domain
type Scalar curve :: * type Scalar curve :: Type
-- | Generate a new random scalar on the curve. -- | Generate a new random scalar on the curve.
-- The scalar will represent a number between 1 and the order of the curve non included -- 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 -- also known as P256
data Curve_P256R1 = Curve_P256R1 data Curve_P256R1 = Curve_P256R1
deriving (Show,Data,Typeable) deriving (Show,Data)
instance EllipticCurve Curve_P256R1 where instance EllipticCurve Curve_P256R1 where
type Point Curve_P256R1 = P256.Point type Point Curve_P256R1 = P256.Point
@ -150,7 +149,7 @@ instance EllipticCurveDH Curve_P256R1 where
ecdh prx s p = checkNonZeroDH (ecdhRaw prx s p) ecdh prx s p = checkNonZeroDH (ecdhRaw prx s p)
data Curve_P384R1 = Curve_P384R1 data Curve_P384R1 = Curve_P384R1
deriving (Show,Data,Typeable) deriving (Show,Data)
instance EllipticCurve Curve_P384R1 where instance EllipticCurve Curve_P384R1 where
type Point Curve_P384R1 = Simple.Point Simple.SEC_p384r1 type Point Curve_P384R1 = Simple.Point Simple.SEC_p384r1
@ -173,7 +172,7 @@ instance EllipticCurveDH Curve_P384R1 where
prx = Proxy :: Proxy Simple.SEC_p384r1 prx = Proxy :: Proxy Simple.SEC_p384r1
data Curve_P521R1 = Curve_P521R1 data Curve_P521R1 = Curve_P521R1
deriving (Show,Data,Typeable) deriving (Show,Data)
instance EllipticCurve Curve_P521R1 where instance EllipticCurve Curve_P521R1 where
type Point Curve_P521R1 = Simple.Point Simple.SEC_p521r1 type Point Curve_P521R1 = Simple.Point Simple.SEC_p521r1
@ -196,7 +195,7 @@ instance EllipticCurveDH Curve_P521R1 where
prx = Proxy :: Proxy Simple.SEC_p521r1 prx = Proxy :: Proxy Simple.SEC_p521r1
data Curve_X25519 = Curve_X25519 data Curve_X25519 = Curve_X25519
deriving (Show,Data,Typeable) deriving (Show,Data)
instance EllipticCurve Curve_X25519 where instance EllipticCurve Curve_X25519 where
type Point Curve_X25519 = X25519.PublicKey type Point Curve_X25519 = X25519.PublicKey
@ -215,7 +214,7 @@ instance EllipticCurveDH Curve_X25519 where
ecdh prx s p = checkNonZeroDH (ecdhRaw prx s p) ecdh prx s p = checkNonZeroDH (ecdhRaw prx s p)
data Curve_X448 = Curve_X448 data Curve_X448 = Curve_X448
deriving (Show,Data,Typeable) deriving (Show,Data)
instance EllipticCurve Curve_X448 where instance EllipticCurve Curve_X448 where
type Point Curve_X448 = X448.PublicKey type Point Curve_X448 = X448.PublicKey
@ -234,7 +233,7 @@ instance EllipticCurveDH Curve_X448 where
ecdh prx s p = checkNonZeroDH (ecdhRaw prx s p) ecdh prx s p = checkNonZeroDH (ecdhRaw prx s p)
data Curve_Edwards25519 = Curve_Edwards25519 data Curve_Edwards25519 = Curve_Edwards25519
deriving (Show,Data,Typeable) deriving (Show,Data)
instance EllipticCurve Curve_Edwards25519 where instance EllipticCurve Curve_Edwards25519 where
type Point Curve_Edwards25519 = Edwards25519.Point type Point Curve_Edwards25519 = Edwards25519.Point

View File

@ -73,15 +73,12 @@ module Crypto.ECC.Edwards25519
, pointsMulVarTime , pointsMulVarTime
) where ) where
import Data.Bits
import Data.Word import Data.Word
import Foreign.C.Types import Foreign.C.Types
import Foreign.Ptr import Foreign.Ptr
import Foreign.Storable
import Crypto.Error import Crypto.Error
import Crypto.Internal.ByteArray (ByteArrayAccess, Bytes, import Crypto.Internal.ByteArray (Bytes, ScrubbedBytes, withByteArray)
ScrubbedBytes, withByteArray)
import qualified Crypto.Internal.ByteArray as B import qualified Crypto.Internal.ByteArray as B
import Crypto.Internal.Compat import Crypto.Internal.Compat
import Crypto.Internal.Imports import Crypto.Internal.Imports

View File

@ -17,7 +17,6 @@ module Crypto.ECC.Simple.Prim
) where ) where
import Data.Maybe import Data.Maybe
import Crypto.Internal.Imports
import Crypto.Internal.Proxy import Crypto.Internal.Proxy
import Crypto.Number.ModArithmetic import Crypto.Number.ModArithmetic
import Crypto.Number.F2m import Crypto.Number.F2m

View File

@ -84,28 +84,28 @@ data CurveParameters curve = CurveParameters
, curveEccG :: Point curve -- ^ base point , curveEccG :: Point curve -- ^ base point
, curveEccN :: Integer -- ^ order of G , curveEccN :: Integer -- ^ order of G
, curveEccH :: Integer -- ^ cofactor , curveEccH :: Integer -- ^ cofactor
} deriving (Show,Eq,Data,Typeable) } deriving (Show,Eq,Data)
newtype CurveBinaryParam = CurveBinaryParam Integer newtype CurveBinaryParam = CurveBinaryParam Integer
deriving (Show,Read,Eq,Data,Typeable) deriving (Show,Read,Eq,Data)
newtype CurvePrimeParam = CurvePrimeParam Integer newtype CurvePrimeParam = CurvePrimeParam Integer
deriving (Show,Read,Eq,Data,Typeable) deriving (Show,Read,Eq,Data)
data CurveType = data CurveType =
CurveBinary CurveBinaryParam CurveBinary CurveBinaryParam
| CurvePrime CurvePrimeParam | CurvePrime CurvePrimeParam
deriving (Show,Read,Eq,Data,Typeable) deriving (Show,Read,Eq,Data)
-- | ECC Private Number -- | ECC Private Number
newtype Scalar curve = Scalar Integer newtype Scalar curve = Scalar Integer
deriving (Show,Read,Eq,Data,Typeable,NFData) deriving (Show,Read,Eq,Data,NFData)
-- | Define a point on a curve. -- | Define a point on a curve.
data Point curve = data Point curve =
Point Integer Integer Point Integer Integer
| PointO -- ^ Point at Infinity | PointO -- ^ Point at Infinity
deriving (Show,Read,Eq,Data,Typeable) deriving (Show,Read,Eq,Data)
instance NFData (Point curve) where instance NFData (Point curve) where
rnf (Point x y) = x `seq` y `seq` () rnf (Point x y) = x `seq` y `seq` ()

View File

@ -23,7 +23,6 @@ import qualified Control.Exception as E
import Data.Data import Data.Data
import Basement.Monad (MonadFailure(..)) import Basement.Monad (MonadFailure(..))
import Crypto.Internal.Imports
-- | Enumeration of all possible errors that can be found in this library -- | Enumeration of all possible errors that can be found in this library
data CryptoError = data CryptoError =
@ -53,7 +52,7 @@ data CryptoError =
| CryptoError_SaltTooSmall | CryptoError_SaltTooSmall
| CryptoError_OutputLengthTooSmall | CryptoError_OutputLengthTooSmall
| CryptoError_OutputLengthTooBig | CryptoError_OutputLengthTooBig
deriving (Show,Eq,Enum,Data,Typeable) deriving (Show,Eq,Enum,Data)
instance E.Exception CryptoError instance E.Exception CryptoError
@ -83,7 +82,7 @@ instance Applicative CryptoFailable where
pure a = CryptoPassed a pure a = CryptoPassed a
(<*>) fm m = fm >>= \p -> m >>= \r2 -> return (p r2) (<*>) fm m = fm >>= \p -> m >>= \r2 -> return (p r2)
instance Monad CryptoFailable where instance Monad CryptoFailable where
return a = CryptoPassed a return = pure
(>>=) m1 m2 = do (>>=) m1 m2 = do
case m1 of case m1 of
CryptoPassed a -> m2 a CryptoPassed a -> m2 a

View File

@ -44,7 +44,6 @@ module Crypto.Hash
import Basement.Types.OffsetSize (CountOf (..)) import Basement.Types.OffsetSize (CountOf (..))
import Basement.Block (Block, unsafeFreeze) import Basement.Block (Block, unsafeFreeze)
import Basement.Block.Mutable (copyFromPtr, new) import Basement.Block.Mutable (copyFromPtr, new)
import Control.Monad
import Crypto.Internal.Compat (unsafeDoIO) import Crypto.Internal.Compat (unsafeDoIO)
import Crypto.Hash.Types import Crypto.Hash.Types
import Crypto.Hash.Algorithms import Crypto.Hash.Algorithms
@ -110,7 +109,7 @@ hashWith _ = hash
digestFromByteString :: forall a ba . (HashAlgorithm a, ByteArrayAccess ba) => ba -> Maybe (Digest a) digestFromByteString :: forall a ba . (HashAlgorithm a, ByteArrayAccess ba) => ba -> Maybe (Digest a)
digestFromByteString = from undefined digestFromByteString = from undefined
where where
from :: HashAlgorithm a => a -> ba -> Maybe (Digest a) from :: a -> ba -> Maybe (Digest a)
from alg bs from alg bs
| B.length bs == (hashDigestSize alg) = Just $ Digest $ unsafeDoIO $ copyBytes bs | B.length bs == (hashDigestSize alg) = Just $ Digest $ unsafeDoIO $ copyBytes bs
| otherwise = Nothing | otherwise = Nothing

View File

@ -42,9 +42,8 @@ module Crypto.Hash.Blake2
import Crypto.Hash.Types import Crypto.Hash.Types
import Foreign.Ptr (Ptr) import Foreign.Ptr (Ptr)
import Data.Data import Data.Data
import Data.Typeable
import Data.Word (Word8, Word32) import Data.Word (Word8, Word32)
import GHC.TypeLits (Nat, KnownNat, natVal) import GHC.TypeLits (Nat, KnownNat)
import Crypto.Internal.Nat import Crypto.Internal.Nat
-- | Fast and secure alternative to SHA1 and HMAC-SHA1 -- | Fast and secure alternative to SHA1 and HMAC-SHA1
@ -58,7 +57,7 @@ import Crypto.Internal.Nat
-- * Blake2s 256 -- * Blake2s 256
-- --
data Blake2s (bitlen :: Nat) = Blake2s data Blake2s (bitlen :: Nat) = Blake2s
deriving (Show, Typeable) deriving (Show)
instance (IsDivisibleBy8 bitlen, KnownNat bitlen, IsAtLeast bitlen 8, IsAtMost bitlen 256) instance (IsDivisibleBy8 bitlen, KnownNat bitlen, IsAtLeast bitlen 8, IsAtMost bitlen 256)
=> HashAlgorithm (Blake2s bitlen) => HashAlgorithm (Blake2s bitlen)
@ -93,7 +92,7 @@ foreign import ccall unsafe "cryptonite_blake2s_finalize"
-- * Blake2b 512 -- * Blake2b 512
-- --
data Blake2b (bitlen :: Nat) = Blake2b data Blake2b (bitlen :: Nat) = Blake2b
deriving (Show, Typeable) deriving (Show)
instance (IsDivisibleBy8 bitlen, KnownNat bitlen, IsAtLeast bitlen 8, IsAtMost bitlen 512) instance (IsDivisibleBy8 bitlen, KnownNat bitlen, IsAtLeast bitlen 8, IsAtMost bitlen 512)
=> HashAlgorithm (Blake2b bitlen) => 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 () c_blake2b_finalize :: Ptr (Context a) -> Word32 -> Ptr (Digest a) -> IO ()
data Blake2sp (bitlen :: Nat) = Blake2sp data Blake2sp (bitlen :: Nat) = Blake2sp
deriving (Show, Typeable) deriving (Show)
instance (IsDivisibleBy8 bitlen, KnownNat bitlen, IsAtLeast bitlen 8, IsAtMost bitlen 256) instance (IsDivisibleBy8 bitlen, KnownNat bitlen, IsAtLeast bitlen 8, IsAtMost bitlen 256)
=> HashAlgorithm (Blake2sp bitlen) => 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 () c_blake2sp_finalize :: Ptr (Context a) -> Word32 -> Ptr (Digest a) -> IO ()
data Blake2bp (bitlen :: Nat) = Blake2bp data Blake2bp (bitlen :: Nat) = Blake2bp
deriving (Show, Typeable) deriving (Show)
instance (IsDivisibleBy8 bitlen, KnownNat bitlen, IsAtLeast bitlen 8, IsAtMost bitlen 512) instance (IsDivisibleBy8 bitlen, KnownNat bitlen, IsAtLeast bitlen 8, IsAtMost bitlen 512)
=> HashAlgorithm (Blake2bp bitlen) => HashAlgorithm (Blake2bp bitlen)

View File

@ -19,13 +19,12 @@ module Crypto.Hash.Blake2b
import Crypto.Hash.Types import Crypto.Hash.Types
import Foreign.Ptr (Ptr) import Foreign.Ptr (Ptr)
import Data.Data import Data.Data
import Data.Typeable
import Data.Word (Word8, Word32) import Data.Word (Word8, Word32)
-- | Blake2b (160 bits) cryptographic hash algorithm -- | Blake2b (160 bits) cryptographic hash algorithm
data Blake2b_160 = Blake2b_160 data Blake2b_160 = Blake2b_160
deriving (Show,Data,Typeable) deriving (Show,Data)
instance HashAlgorithm Blake2b_160 where instance HashAlgorithm Blake2b_160 where
type HashBlockSize Blake2b_160 = 128 type HashBlockSize Blake2b_160 = 128
@ -40,7 +39,7 @@ instance HashAlgorithm Blake2b_160 where
-- | Blake2b (224 bits) cryptographic hash algorithm -- | Blake2b (224 bits) cryptographic hash algorithm
data Blake2b_224 = Blake2b_224 data Blake2b_224 = Blake2b_224
deriving (Show,Data,Typeable) deriving (Show,Data)
instance HashAlgorithm Blake2b_224 where instance HashAlgorithm Blake2b_224 where
type HashBlockSize Blake2b_224 = 128 type HashBlockSize Blake2b_224 = 128
@ -55,7 +54,7 @@ instance HashAlgorithm Blake2b_224 where
-- | Blake2b (256 bits) cryptographic hash algorithm -- | Blake2b (256 bits) cryptographic hash algorithm
data Blake2b_256 = Blake2b_256 data Blake2b_256 = Blake2b_256
deriving (Show,Data,Typeable) deriving (Show,Data)
instance HashAlgorithm Blake2b_256 where instance HashAlgorithm Blake2b_256 where
type HashBlockSize Blake2b_256 = 128 type HashBlockSize Blake2b_256 = 128
@ -70,7 +69,7 @@ instance HashAlgorithm Blake2b_256 where
-- | Blake2b (384 bits) cryptographic hash algorithm -- | Blake2b (384 bits) cryptographic hash algorithm
data Blake2b_384 = Blake2b_384 data Blake2b_384 = Blake2b_384
deriving (Show,Data,Typeable) deriving (Show,Data)
instance HashAlgorithm Blake2b_384 where instance HashAlgorithm Blake2b_384 where
type HashBlockSize Blake2b_384 = 128 type HashBlockSize Blake2b_384 = 128
@ -85,7 +84,7 @@ instance HashAlgorithm Blake2b_384 where
-- | Blake2b (512 bits) cryptographic hash algorithm -- | Blake2b (512 bits) cryptographic hash algorithm
data Blake2b_512 = Blake2b_512 data Blake2b_512 = Blake2b_512
deriving (Show,Data,Typeable) deriving (Show,Data)
instance HashAlgorithm Blake2b_512 where instance HashAlgorithm Blake2b_512 where
type HashBlockSize Blake2b_512 = 128 type HashBlockSize Blake2b_512 = 128

View File

@ -19,13 +19,12 @@ module Crypto.Hash.Blake2bp
import Crypto.Hash.Types import Crypto.Hash.Types
import Foreign.Ptr (Ptr) import Foreign.Ptr (Ptr)
import Data.Data import Data.Data
import Data.Typeable
import Data.Word (Word8, Word32) import Data.Word (Word8, Word32)
-- | Blake2bp (512 bits) cryptographic hash algorithm -- | Blake2bp (512 bits) cryptographic hash algorithm
data Blake2bp_512 = Blake2bp_512 data Blake2bp_512 = Blake2bp_512
deriving (Show,Data,Typeable) deriving (Show,Data)
instance HashAlgorithm Blake2bp_512 where instance HashAlgorithm Blake2bp_512 where
type HashBlockSize Blake2bp_512 = 128 type HashBlockSize Blake2bp_512 = 128

View File

@ -19,13 +19,12 @@ module Crypto.Hash.Blake2s
import Crypto.Hash.Types import Crypto.Hash.Types
import Foreign.Ptr (Ptr) import Foreign.Ptr (Ptr)
import Data.Data import Data.Data
import Data.Typeable
import Data.Word (Word8, Word32) import Data.Word (Word8, Word32)
-- | Blake2s (160 bits) cryptographic hash algorithm -- | Blake2s (160 bits) cryptographic hash algorithm
data Blake2s_160 = Blake2s_160 data Blake2s_160 = Blake2s_160
deriving (Show,Data,Typeable) deriving (Show,Data)
instance HashAlgorithm Blake2s_160 where instance HashAlgorithm Blake2s_160 where
type HashBlockSize Blake2s_160 = 64 type HashBlockSize Blake2s_160 = 64
@ -40,7 +39,7 @@ instance HashAlgorithm Blake2s_160 where
-- | Blake2s (224 bits) cryptographic hash algorithm -- | Blake2s (224 bits) cryptographic hash algorithm
data Blake2s_224 = Blake2s_224 data Blake2s_224 = Blake2s_224
deriving (Show,Data,Typeable) deriving (Show,Data)
instance HashAlgorithm Blake2s_224 where instance HashAlgorithm Blake2s_224 where
type HashBlockSize Blake2s_224 = 64 type HashBlockSize Blake2s_224 = 64
@ -55,7 +54,7 @@ instance HashAlgorithm Blake2s_224 where
-- | Blake2s (256 bits) cryptographic hash algorithm -- | Blake2s (256 bits) cryptographic hash algorithm
data Blake2s_256 = Blake2s_256 data Blake2s_256 = Blake2s_256
deriving (Show,Data,Typeable) deriving (Show,Data)
instance HashAlgorithm Blake2s_256 where instance HashAlgorithm Blake2s_256 where
type HashBlockSize Blake2s_256 = 64 type HashBlockSize Blake2s_256 = 64

View File

@ -19,13 +19,12 @@ module Crypto.Hash.Blake2sp
import Crypto.Hash.Types import Crypto.Hash.Types
import Foreign.Ptr (Ptr) import Foreign.Ptr (Ptr)
import Data.Data import Data.Data
import Data.Typeable
import Data.Word (Word8, Word32) import Data.Word (Word8, Word32)
-- | Blake2sp (224 bits) cryptographic hash algorithm -- | Blake2sp (224 bits) cryptographic hash algorithm
data Blake2sp_224 = Blake2sp_224 data Blake2sp_224 = Blake2sp_224
deriving (Show,Data,Typeable) deriving (Show,Data)
instance HashAlgorithm Blake2sp_224 where instance HashAlgorithm Blake2sp_224 where
type HashBlockSize Blake2sp_224 = 64 type HashBlockSize Blake2sp_224 = 64
@ -40,7 +39,7 @@ instance HashAlgorithm Blake2sp_224 where
-- | Blake2sp (256 bits) cryptographic hash algorithm -- | Blake2sp (256 bits) cryptographic hash algorithm
data Blake2sp_256 = Blake2sp_256 data Blake2sp_256 = Blake2sp_256
deriving (Show,Data,Typeable) deriving (Show,Data)
instance HashAlgorithm Blake2sp_256 where instance HashAlgorithm Blake2sp_256 where
type HashBlockSize Blake2sp_256 = 64 type HashBlockSize Blake2sp_256 = 64

View File

@ -19,13 +19,12 @@ module Crypto.Hash.Keccak
import Crypto.Hash.Types import Crypto.Hash.Types
import Foreign.Ptr (Ptr) import Foreign.Ptr (Ptr)
import Data.Data import Data.Data
import Data.Typeable
import Data.Word (Word8, Word32) import Data.Word (Word8, Word32)
-- | Keccak (224 bits) cryptographic hash algorithm -- | Keccak (224 bits) cryptographic hash algorithm
data Keccak_224 = Keccak_224 data Keccak_224 = Keccak_224
deriving (Show,Data,Typeable) deriving (Show,Data)
instance HashAlgorithm Keccak_224 where instance HashAlgorithm Keccak_224 where
type HashBlockSize Keccak_224 = 144 type HashBlockSize Keccak_224 = 144
@ -40,7 +39,7 @@ instance HashAlgorithm Keccak_224 where
-- | Keccak (256 bits) cryptographic hash algorithm -- | Keccak (256 bits) cryptographic hash algorithm
data Keccak_256 = Keccak_256 data Keccak_256 = Keccak_256
deriving (Show,Data,Typeable) deriving (Show,Data)
instance HashAlgorithm Keccak_256 where instance HashAlgorithm Keccak_256 where
type HashBlockSize Keccak_256 = 136 type HashBlockSize Keccak_256 = 136
@ -55,7 +54,7 @@ instance HashAlgorithm Keccak_256 where
-- | Keccak (384 bits) cryptographic hash algorithm -- | Keccak (384 bits) cryptographic hash algorithm
data Keccak_384 = Keccak_384 data Keccak_384 = Keccak_384
deriving (Show,Data,Typeable) deriving (Show,Data)
instance HashAlgorithm Keccak_384 where instance HashAlgorithm Keccak_384 where
type HashBlockSize Keccak_384 = 104 type HashBlockSize Keccak_384 = 104
@ -70,7 +69,7 @@ instance HashAlgorithm Keccak_384 where
-- | Keccak (512 bits) cryptographic hash algorithm -- | Keccak (512 bits) cryptographic hash algorithm
data Keccak_512 = Keccak_512 data Keccak_512 = Keccak_512
deriving (Show,Data,Typeable) deriving (Show,Data)
instance HashAlgorithm Keccak_512 where instance HashAlgorithm Keccak_512 where
type HashBlockSize Keccak_512 = 72 type HashBlockSize Keccak_512 = 72

View File

@ -17,12 +17,11 @@ module Crypto.Hash.MD2 ( MD2 (..) ) where
import Crypto.Hash.Types import Crypto.Hash.Types
import Foreign.Ptr (Ptr) import Foreign.Ptr (Ptr)
import Data.Data import Data.Data
import Data.Typeable
import Data.Word (Word8, Word32) import Data.Word (Word8, Word32)
-- | MD2 cryptographic hash algorithm -- | MD2 cryptographic hash algorithm
data MD2 = MD2 data MD2 = MD2
deriving (Show,Data,Typeable) deriving (Show,Data)
instance HashAlgorithm MD2 where instance HashAlgorithm MD2 where
type HashBlockSize MD2 = 16 type HashBlockSize MD2 = 16

View File

@ -17,12 +17,11 @@ module Crypto.Hash.MD4 ( MD4 (..) ) where
import Crypto.Hash.Types import Crypto.Hash.Types
import Foreign.Ptr (Ptr) import Foreign.Ptr (Ptr)
import Data.Data import Data.Data
import Data.Typeable
import Data.Word (Word8, Word32) import Data.Word (Word8, Word32)
-- | MD4 cryptographic hash algorithm -- | MD4 cryptographic hash algorithm
data MD4 = MD4 data MD4 = MD4
deriving (Show,Data,Typeable) deriving (Show,Data)
instance HashAlgorithm MD4 where instance HashAlgorithm MD4 where
type HashBlockSize MD4 = 64 type HashBlockSize MD4 = 64

View File

@ -17,12 +17,11 @@ module Crypto.Hash.MD5 ( MD5 (..) ) where
import Crypto.Hash.Types import Crypto.Hash.Types
import Foreign.Ptr (Ptr) import Foreign.Ptr (Ptr)
import Data.Data import Data.Data
import Data.Typeable
import Data.Word (Word8, Word32) import Data.Word (Word8, Word32)
-- | MD5 cryptographic hash algorithm -- | MD5 cryptographic hash algorithm
data MD5 = MD5 data MD5 = MD5
deriving (Show,Data,Typeable) deriving (Show,Data)
instance HashAlgorithm MD5 where instance HashAlgorithm MD5 where
type HashBlockSize MD5 = 64 type HashBlockSize MD5 = 64

View File

@ -17,12 +17,11 @@ module Crypto.Hash.RIPEMD160 ( RIPEMD160 (..) ) where
import Crypto.Hash.Types import Crypto.Hash.Types
import Foreign.Ptr (Ptr) import Foreign.Ptr (Ptr)
import Data.Data import Data.Data
import Data.Typeable
import Data.Word (Word8, Word32) import Data.Word (Word8, Word32)
-- | RIPEMD160 cryptographic hash algorithm -- | RIPEMD160 cryptographic hash algorithm
data RIPEMD160 = RIPEMD160 data RIPEMD160 = RIPEMD160
deriving (Show,Data,Typeable) deriving (Show,Data)
instance HashAlgorithm RIPEMD160 where instance HashAlgorithm RIPEMD160 where
type HashBlockSize RIPEMD160 = 64 type HashBlockSize RIPEMD160 = 64

View File

@ -17,12 +17,11 @@ module Crypto.Hash.SHA1 ( SHA1 (..) ) where
import Crypto.Hash.Types import Crypto.Hash.Types
import Foreign.Ptr (Ptr) import Foreign.Ptr (Ptr)
import Data.Data import Data.Data
import Data.Typeable
import Data.Word (Word8, Word32) import Data.Word (Word8, Word32)
-- | SHA1 cryptographic hash algorithm -- | SHA1 cryptographic hash algorithm
data SHA1 = SHA1 data SHA1 = SHA1
deriving (Show,Data,Typeable) deriving (Show,Data)
instance HashAlgorithm SHA1 where instance HashAlgorithm SHA1 where
type HashBlockSize SHA1 = 64 type HashBlockSize SHA1 = 64

View File

@ -17,12 +17,11 @@ module Crypto.Hash.SHA224 ( SHA224 (..) ) where
import Crypto.Hash.Types import Crypto.Hash.Types
import Foreign.Ptr (Ptr) import Foreign.Ptr (Ptr)
import Data.Data import Data.Data
import Data.Typeable
import Data.Word (Word8, Word32) import Data.Word (Word8, Word32)
-- | SHA224 cryptographic hash algorithm -- | SHA224 cryptographic hash algorithm
data SHA224 = SHA224 data SHA224 = SHA224
deriving (Show,Data,Typeable) deriving (Show,Data)
instance HashAlgorithm SHA224 where instance HashAlgorithm SHA224 where
type HashBlockSize SHA224 = 64 type HashBlockSize SHA224 = 64

View File

@ -17,12 +17,11 @@ module Crypto.Hash.SHA256 ( SHA256 (..) ) where
import Crypto.Hash.Types import Crypto.Hash.Types
import Foreign.Ptr (Ptr) import Foreign.Ptr (Ptr)
import Data.Data import Data.Data
import Data.Typeable
import Data.Word (Word8, Word32) import Data.Word (Word8, Word32)
-- | SHA256 cryptographic hash algorithm -- | SHA256 cryptographic hash algorithm
data SHA256 = SHA256 data SHA256 = SHA256
deriving (Show,Data,Typeable) deriving (Show,Data)
instance HashAlgorithm SHA256 where instance HashAlgorithm SHA256 where
type HashBlockSize SHA256 = 64 type HashBlockSize SHA256 = 64

View File

@ -19,13 +19,12 @@ module Crypto.Hash.SHA3
import Crypto.Hash.Types import Crypto.Hash.Types
import Foreign.Ptr (Ptr) import Foreign.Ptr (Ptr)
import Data.Data import Data.Data
import Data.Typeable
import Data.Word (Word8, Word32) import Data.Word (Word8, Word32)
-- | SHA3 (224 bits) cryptographic hash algorithm -- | SHA3 (224 bits) cryptographic hash algorithm
data SHA3_224 = SHA3_224 data SHA3_224 = SHA3_224
deriving (Show,Data,Typeable) deriving (Show,Data)
instance HashAlgorithm SHA3_224 where instance HashAlgorithm SHA3_224 where
type HashBlockSize SHA3_224 = 144 type HashBlockSize SHA3_224 = 144
@ -40,7 +39,7 @@ instance HashAlgorithm SHA3_224 where
-- | SHA3 (256 bits) cryptographic hash algorithm -- | SHA3 (256 bits) cryptographic hash algorithm
data SHA3_256 = SHA3_256 data SHA3_256 = SHA3_256
deriving (Show,Data,Typeable) deriving (Show,Data)
instance HashAlgorithm SHA3_256 where instance HashAlgorithm SHA3_256 where
type HashBlockSize SHA3_256 = 136 type HashBlockSize SHA3_256 = 136
@ -55,7 +54,7 @@ instance HashAlgorithm SHA3_256 where
-- | SHA3 (384 bits) cryptographic hash algorithm -- | SHA3 (384 bits) cryptographic hash algorithm
data SHA3_384 = SHA3_384 data SHA3_384 = SHA3_384
deriving (Show,Data,Typeable) deriving (Show,Data)
instance HashAlgorithm SHA3_384 where instance HashAlgorithm SHA3_384 where
type HashBlockSize SHA3_384 = 104 type HashBlockSize SHA3_384 = 104
@ -70,7 +69,7 @@ instance HashAlgorithm SHA3_384 where
-- | SHA3 (512 bits) cryptographic hash algorithm -- | SHA3 (512 bits) cryptographic hash algorithm
data SHA3_512 = SHA3_512 data SHA3_512 = SHA3_512
deriving (Show,Data,Typeable) deriving (Show,Data)
instance HashAlgorithm SHA3_512 where instance HashAlgorithm SHA3_512 where
type HashBlockSize SHA3_512 = 72 type HashBlockSize SHA3_512 = 72

View File

@ -17,12 +17,11 @@ module Crypto.Hash.SHA384 ( SHA384 (..) ) where
import Crypto.Hash.Types import Crypto.Hash.Types
import Foreign.Ptr (Ptr) import Foreign.Ptr (Ptr)
import Data.Data import Data.Data
import Data.Typeable
import Data.Word (Word8, Word32) import Data.Word (Word8, Word32)
-- | SHA384 cryptographic hash algorithm -- | SHA384 cryptographic hash algorithm
data SHA384 = SHA384 data SHA384 = SHA384
deriving (Show,Data,Typeable) deriving (Show,Data)
instance HashAlgorithm SHA384 where instance HashAlgorithm SHA384 where
type HashBlockSize SHA384 = 128 type HashBlockSize SHA384 = 128

View File

@ -17,12 +17,11 @@ module Crypto.Hash.SHA512 ( SHA512 (..) ) where
import Crypto.Hash.Types import Crypto.Hash.Types
import Foreign.Ptr (Ptr) import Foreign.Ptr (Ptr)
import Data.Data import Data.Data
import Data.Typeable
import Data.Word (Word8, Word32) import Data.Word (Word8, Word32)
-- | SHA512 cryptographic hash algorithm -- | SHA512 cryptographic hash algorithm
data SHA512 = SHA512 data SHA512 = SHA512
deriving (Show,Data,Typeable) deriving (Show,Data)
instance HashAlgorithm SHA512 where instance HashAlgorithm SHA512 where
type HashBlockSize SHA512 = 128 type HashBlockSize SHA512 = 128

View File

@ -19,13 +19,12 @@ module Crypto.Hash.SHA512t
import Crypto.Hash.Types import Crypto.Hash.Types
import Foreign.Ptr (Ptr) import Foreign.Ptr (Ptr)
import Data.Data import Data.Data
import Data.Typeable
import Data.Word (Word8, Word32) import Data.Word (Word8, Word32)
-- | SHA512t (224 bits) cryptographic hash algorithm -- | SHA512t (224 bits) cryptographic hash algorithm
data SHA512t_224 = SHA512t_224 data SHA512t_224 = SHA512t_224
deriving (Show,Data,Typeable) deriving (Show,Data)
instance HashAlgorithm SHA512t_224 where instance HashAlgorithm SHA512t_224 where
type HashBlockSize SHA512t_224 = 128 type HashBlockSize SHA512t_224 = 128
@ -40,7 +39,7 @@ instance HashAlgorithm SHA512t_224 where
-- | SHA512t (256 bits) cryptographic hash algorithm -- | SHA512t (256 bits) cryptographic hash algorithm
data SHA512t_256 = SHA512t_256 data SHA512t_256 = SHA512t_256
deriving (Show,Data,Typeable) deriving (Show,Data)
instance HashAlgorithm SHA512t_256 where instance HashAlgorithm SHA512t_256 where
type HashBlockSize SHA512t_256 = 128 type HashBlockSize SHA512t_256 = 128

View File

@ -26,7 +26,6 @@ import Foreign.Ptr (Ptr, castPtr)
import Foreign.Storable (Storable(..)) import Foreign.Storable (Storable(..))
import Data.Bits import Data.Bits
import Data.Data import Data.Data
import Data.Typeable
import Data.Word (Word8, Word32) import Data.Word (Word8, Word32)
import Data.Proxy (Proxy(..)) import Data.Proxy (Proxy(..))
@ -40,7 +39,7 @@ import Crypto.Internal.Nat
-- correlated (one being a prefix of the other). Results are unrelated to -- correlated (one being a prefix of the other). Results are unrelated to
-- 'SHAKE256' results. -- 'SHAKE256' results.
data SHAKE128 (bitlen :: Nat) = SHAKE128 data SHAKE128 (bitlen :: Nat) = SHAKE128
deriving (Show, Data, Typeable) deriving (Show, Data)
instance KnownNat bitlen => HashAlgorithm (SHAKE128 bitlen) where instance KnownNat bitlen => HashAlgorithm (SHAKE128 bitlen) where
type HashBlockSize (SHAKE128 bitlen) = 168 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 -- correlated (one being a prefix of the other). Results are unrelated to
-- 'SHAKE128' results. -- 'SHAKE128' results.
data SHAKE256 (bitlen :: Nat) = SHAKE256 data SHAKE256 (bitlen :: Nat) = SHAKE256
deriving (Show, Data, Typeable) deriving (Show, Data)
instance KnownNat bitlen => HashAlgorithm (SHAKE256 bitlen) where instance KnownNat bitlen => HashAlgorithm (SHAKE256 bitlen) where
type HashBlockSize (SHAKE256 bitlen) = 136 type HashBlockSize (SHAKE256 bitlen) = 136

View File

@ -19,13 +19,12 @@ module Crypto.Hash.Skein256
import Crypto.Hash.Types import Crypto.Hash.Types
import Foreign.Ptr (Ptr) import Foreign.Ptr (Ptr)
import Data.Data import Data.Data
import Data.Typeable
import Data.Word (Word8, Word32) import Data.Word (Word8, Word32)
-- | Skein256 (224 bits) cryptographic hash algorithm -- | Skein256 (224 bits) cryptographic hash algorithm
data Skein256_224 = Skein256_224 data Skein256_224 = Skein256_224
deriving (Show,Data,Typeable) deriving (Show,Data)
instance HashAlgorithm Skein256_224 where instance HashAlgorithm Skein256_224 where
type HashBlockSize Skein256_224 = 32 type HashBlockSize Skein256_224 = 32
@ -40,7 +39,7 @@ instance HashAlgorithm Skein256_224 where
-- | Skein256 (256 bits) cryptographic hash algorithm -- | Skein256 (256 bits) cryptographic hash algorithm
data Skein256_256 = Skein256_256 data Skein256_256 = Skein256_256
deriving (Show,Data,Typeable) deriving (Show,Data)
instance HashAlgorithm Skein256_256 where instance HashAlgorithm Skein256_256 where
type HashBlockSize Skein256_256 = 32 type HashBlockSize Skein256_256 = 32

View File

@ -19,13 +19,12 @@ module Crypto.Hash.Skein512
import Crypto.Hash.Types import Crypto.Hash.Types
import Foreign.Ptr (Ptr) import Foreign.Ptr (Ptr)
import Data.Data import Data.Data
import Data.Typeable
import Data.Word (Word8, Word32) import Data.Word (Word8, Word32)
-- | Skein512 (224 bits) cryptographic hash algorithm -- | Skein512 (224 bits) cryptographic hash algorithm
data Skein512_224 = Skein512_224 data Skein512_224 = Skein512_224
deriving (Show,Data,Typeable) deriving (Show,Data)
instance HashAlgorithm Skein512_224 where instance HashAlgorithm Skein512_224 where
type HashBlockSize Skein512_224 = 64 type HashBlockSize Skein512_224 = 64
@ -40,7 +39,7 @@ instance HashAlgorithm Skein512_224 where
-- | Skein512 (256 bits) cryptographic hash algorithm -- | Skein512 (256 bits) cryptographic hash algorithm
data Skein512_256 = Skein512_256 data Skein512_256 = Skein512_256
deriving (Show,Data,Typeable) deriving (Show,Data)
instance HashAlgorithm Skein512_256 where instance HashAlgorithm Skein512_256 where
type HashBlockSize Skein512_256 = 64 type HashBlockSize Skein512_256 = 64
@ -55,7 +54,7 @@ instance HashAlgorithm Skein512_256 where
-- | Skein512 (384 bits) cryptographic hash algorithm -- | Skein512 (384 bits) cryptographic hash algorithm
data Skein512_384 = Skein512_384 data Skein512_384 = Skein512_384
deriving (Show,Data,Typeable) deriving (Show,Data)
instance HashAlgorithm Skein512_384 where instance HashAlgorithm Skein512_384 where
type HashBlockSize Skein512_384 = 64 type HashBlockSize Skein512_384 = 64
@ -70,7 +69,7 @@ instance HashAlgorithm Skein512_384 where
-- | Skein512 (512 bits) cryptographic hash algorithm -- | Skein512 (512 bits) cryptographic hash algorithm
data Skein512_512 = Skein512_512 data Skein512_512 = Skein512_512
deriving (Show,Data,Typeable) deriving (Show,Data)
instance HashAlgorithm Skein512_512 where instance HashAlgorithm Skein512_512 where
type HashBlockSize Skein512_512 = 64 type HashBlockSize Skein512_512 = 64

View File

@ -17,12 +17,11 @@ module Crypto.Hash.Tiger ( Tiger (..) ) where
import Crypto.Hash.Types import Crypto.Hash.Types
import Foreign.Ptr (Ptr) import Foreign.Ptr (Ptr)
import Data.Data import Data.Data
import Data.Typeable
import Data.Word (Word8, Word32) import Data.Word (Word8, Word32)
-- | Tiger cryptographic hash algorithm -- | Tiger cryptographic hash algorithm
data Tiger = Tiger data Tiger = Tiger
deriving (Show,Data,Typeable) deriving (Show,Data)
instance HashAlgorithm Tiger where instance HashAlgorithm Tiger where
type HashBlockSize Tiger = 64 type HashBlockSize Tiger = 64

View File

@ -17,12 +17,11 @@ module Crypto.Hash.Whirlpool ( Whirlpool (..) ) where
import Crypto.Hash.Types import Crypto.Hash.Types
import Foreign.Ptr (Ptr) import Foreign.Ptr (Ptr)
import Data.Data import Data.Data
import Data.Typeable
import Data.Word (Word8, Word32) import Data.Word (Word8, Word32)
-- | Whirlpool cryptographic hash algorithm -- | Whirlpool cryptographic hash algorithm
data Whirlpool = Whirlpool data Whirlpool = Whirlpool
deriving (Show,Data,Typeable) deriving (Show,Data)
instance HashAlgorithm Whirlpool where instance HashAlgorithm Whirlpool where
type HashBlockSize Whirlpool = 64 type HashBlockSize Whirlpool = 64

View File

@ -22,7 +22,7 @@ integralNatVal :: (KnownNat bitlen, Num a) => proxy bitlen -> a
integralNatVal = fromInteger . natVal integralNatVal = fromInteger . natVal
type family IsLE (bitlen :: Nat) (n :: Nat) (c :: Bool) where 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) #if MIN_VERSION_base(4,9,0)
IsLE bitlen n 'False = TypeError IsLE bitlen n 'False = TypeError
( ('Text "bitlen " ':<>: 'ShowType bitlen ':<>: 'Text " is greater than " ':<>: 'ShowType n) ( ('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 IsAtMost (bitlen :: Nat) (n :: Nat) = IsLE bitlen n (bitlen <=? n) ~ 'True
type family IsGE (bitlen :: Nat) (n :: Nat) (c :: Bool) where 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) #if MIN_VERSION_base(4,9,0)
IsGE bitlen n 'False = TypeError IsGE bitlen n 'False = TypeError
( ('Text "bitlen " ':<>: 'ShowType bitlen ':<>: 'Text " is lesser than " ':<>: 'ShowType n) ( ('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) Div8 n = 8 + Div8 (n - 64)
type family IsDiv8 (bitLen :: Nat) (n :: Nat) where type family IsDiv8 (bitLen :: Nat) (n :: Nat) where
IsDiv8 bitLen 0 = 'True IsDiv8 _ 0 = 'True
#if MIN_VERSION_base(4,9,0) #if MIN_VERSION_base(4,9,0)
IsDiv8 bitLen 1 = TypeError ('Text "bitLen " ':<>: 'ShowType bitLen ':<>: 'Text " is not divisible by 8") 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") 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 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") IsDiv8 bitLen 7 = TypeError ('Text "bitLen " ':<>: 'ShowType bitLen ':<>: 'Text " is not divisible by 8")
#else #else
IsDiv8 bitLen 1 = 'False IsDiv8 _ 1 = 'False
IsDiv8 bitLen 2 = 'False IsDiv8 _ 2 = 'False
IsDiv8 bitLen 3 = 'False IsDiv8 _ 3 = 'False
IsDiv8 bitLen 4 = 'False IsDiv8 _ 4 = 'False
IsDiv8 bitLen 5 = 'False IsDiv8 _ 5 = 'False
IsDiv8 bitLen 6 = 'False IsDiv8 _ 6 = 'False
IsDiv8 bitLen 7 = 'False IsDiv8 _ 7 = 'False
#endif #endif
IsDiv8 bitLen n = IsDiv8 n (Mod8 n) IsDiv8 _ n = IsDiv8 n (Mod8 n)
type family Mod8 (n :: Nat) where type family Mod8 (n :: Nat) where
Mod8 0 = 0 Mod8 0 = 0

View File

@ -25,7 +25,7 @@ module Crypto.KDF.Argon2
, hash , hash
) where ) where
import Crypto.Internal.ByteArray (ScrubbedBytes, ByteArray, ByteArrayAccess) import Crypto.Internal.ByteArray (ByteArray, ByteArrayAccess)
import qualified Crypto.Internal.ByteArray as B import qualified Crypto.Internal.ByteArray as B
import Crypto.Error import Crypto.Error
import Control.Monad (when) import Control.Monad (when)

View File

@ -24,7 +24,7 @@ import Data.Word
import Data.Bits import Data.Bits
import Foreign.Marshal.Alloc import Foreign.Marshal.Alloc
import Foreign.Ptr (plusPtr, Ptr) import Foreign.Ptr (plusPtr, Ptr)
import Foreign.C.Types (CUInt(..), CInt(..), CSize(..)) import Foreign.C.Types (CUInt(..), CSize(..))
import Crypto.Hash (HashAlgorithm) import Crypto.Hash (HashAlgorithm)
import qualified Crypto.MAC.HMAC as HMAC import qualified Crypto.MAC.HMAC as HMAC

View File

@ -24,11 +24,10 @@ module Crypto.MAC.HMAC
import Crypto.Hash hiding (Context) import Crypto.Hash hiding (Context)
import qualified Crypto.Hash as Hash (Context) import qualified Crypto.Hash as Hash (Context)
import Crypto.Hash.IO 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 qualified Crypto.Internal.ByteArray as B
import Data.Memory.PtrMethods import Data.Memory.PtrMethods
import Crypto.Internal.Compat import Crypto.Internal.Compat
import Crypto.Internal.Imports
-- | Represent an HMAC that is a phantom type with the hash used to produce the mac. -- | Represent an HMAC that is a phantom type with the hash used to produce the mac.
-- --

View File

@ -23,7 +23,6 @@ module Crypto.Number.F2m
import Data.Bits (xor, shift, testBit, setBit) import Data.Bits (xor, shift, testBit, setBit)
import Data.List import Data.List
import Crypto.Internal.Imports
import Crypto.Number.Basic import Crypto.Number.Basic
-- | Binary Polynomial represented by an integer -- | Binary Polynomial represented by an integer

View File

@ -19,13 +19,12 @@ module Crypto.Number.ModArithmetic
) where ) where
import Control.Exception (throw, Exception) import Control.Exception (throw, Exception)
import Data.Typeable
import Crypto.Number.Basic import Crypto.Number.Basic
import Crypto.Number.Compat import Crypto.Number.Compat
-- | Raised when two numbers are supposed to be coprimes but are not. -- | Raised when two numbers are supposed to be coprimes but are not.
data CoprimesAssertionError = CoprimesAssertionError data CoprimesAssertionError = CoprimesAssertionError
deriving (Show,Typeable) deriving (Show)
instance Exception CoprimesAssertionError instance Exception CoprimesAssertionError

View File

@ -19,8 +19,6 @@ module Crypto.Number.Prime
, isCoprime , isCoprime
) where ) where
import Crypto.Internal.Imports
import Crypto.Number.Compat import Crypto.Number.Compat
import Crypto.Number.Generate import Crypto.Number.Generate
import Crypto.Number.Basic (sqrti, gcde) import Crypto.Number.Basic (sqrti, gcde)

View File

@ -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. -- | Just like 'i2osp', but takes an extra parameter for size.
-- If the number is too big to fit in @len@ bytes, 'Nothing' is returned -- 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. -- otherwise the number is padded with 0 to fit the @len@ required.
{-# INLINABLE i2ospOf #-}
i2ospOf :: B.ByteArray ba => Int -> Integer -> Maybe ba i2ospOf :: B.ByteArray ba => Int -> Integer -> Maybe ba
i2ospOf len m i2ospOf len m
| len <= 0 = Nothing | len <= 0 = Nothing

View File

@ -42,15 +42,14 @@ module Crypto.OTP
) )
where where
import Data.Bits (shiftL, shiftR, (.&.), (.|.)) import Data.Bits (shiftL, (.&.), (.|.))
import Data.ByteArray.Mapping (fromW64BE) import Data.ByteArray.Mapping (fromW64BE)
import Data.List (elemIndex) import Data.List (elemIndex)
import Data.Word import Data.Word
import Foreign.Storable (poke)
import Control.Monad (unless) import Control.Monad (unless)
import Crypto.Hash (HashAlgorithm, SHA1(..)) import Crypto.Hash (HashAlgorithm, SHA1(..))
import Crypto.MAC.HMAC import Crypto.MAC.HMAC
import Crypto.Internal.ByteArray (ByteArrayAccess, ByteArray, Bytes) import Crypto.Internal.ByteArray (ByteArrayAccess, Bytes)
import qualified Crypto.Internal.ByteArray as B import qualified Crypto.Internal.ByteArray as B

View File

@ -33,7 +33,7 @@ import GHC.Ptr
import Crypto.Error import Crypto.Error
import Crypto.Internal.Compat import Crypto.Internal.Compat
import Crypto.Internal.Imports 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 qualified Crypto.Internal.ByteArray as B
import Crypto.Error (CryptoFailable(..)) import Crypto.Error (CryptoFailable(..))
import Crypto.Random import Crypto.Random

View File

@ -28,7 +28,6 @@ module Crypto.PubKey.Curve448
import Data.Word import Data.Word
import Foreign.Ptr import Foreign.Ptr
import GHC.Ptr
import Crypto.Error import Crypto.Error
import Crypto.Random import Crypto.Random

View File

@ -33,7 +33,7 @@ data Params = Params
{ params_p :: Integer { params_p :: Integer
, params_g :: Integer , params_g :: Integer
, params_bits :: Int , params_bits :: Int
} deriving (Show,Read,Eq,Data,Typeable) } deriving (Show,Read,Eq,Data)
instance NFData Params where instance NFData Params where
rnf (Params p g bits) = rnf p `seq` rnf g `seq` bits `seq` () rnf (Params p g bits) = rnf p `seq` rnf g `seq` bits `seq` ()

View File

@ -51,7 +51,7 @@ data Params = Params
{ params_p :: Integer -- ^ DSA p { params_p :: Integer -- ^ DSA p
, params_g :: Integer -- ^ DSA g , params_g :: Integer -- ^ DSA g
, params_q :: Integer -- ^ DSA q , params_q :: Integer -- ^ DSA q
} deriving (Show,Read,Eq,Data,Typeable) } deriving (Show,Read,Eq,Data)
instance NFData Params where instance NFData Params where
rnf (Params p g q) = p `seq` g `seq` q `seq` () rnf (Params p g q) = p `seq` g `seq` q `seq` ()
@ -60,7 +60,7 @@ instance NFData Params where
data Signature = Signature data Signature = Signature
{ sign_r :: Integer -- ^ DSA r { sign_r :: Integer -- ^ DSA r
, sign_s :: Integer -- ^ DSA s , sign_s :: Integer -- ^ DSA s
} deriving (Show,Read,Eq,Data,Typeable) } deriving (Show,Read,Eq,Data)
instance NFData Signature where instance NFData Signature where
rnf (Signature r s) = r `seq` s `seq` () rnf (Signature r s) = r `seq` s `seq` ()
@ -69,7 +69,7 @@ instance NFData Signature where
data PublicKey = PublicKey data PublicKey = PublicKey
{ public_params :: Params -- ^ DSA parameters { public_params :: Params -- ^ DSA parameters
, public_y :: PublicNumber -- ^ DSA public Y , public_y :: PublicNumber -- ^ DSA public Y
} deriving (Show,Read,Eq,Data,Typeable) } deriving (Show,Read,Eq,Data)
instance NFData PublicKey where instance NFData PublicKey where
rnf (PublicKey params y) = y `seq` params `seq` () rnf (PublicKey params y) = y `seq` params `seq` ()
@ -81,14 +81,14 @@ instance NFData PublicKey where
data PrivateKey = PrivateKey data PrivateKey = PrivateKey
{ private_params :: Params -- ^ DSA parameters { private_params :: Params -- ^ DSA parameters
, private_x :: PrivateNumber -- ^ DSA private X , private_x :: PrivateNumber -- ^ DSA private X
} deriving (Show,Read,Eq,Data,Typeable) } deriving (Show,Read,Eq,Data)
instance NFData PrivateKey where instance NFData PrivateKey where
rnf (PrivateKey params x) = x `seq` params `seq` () rnf (PrivateKey params x) = x `seq` params `seq` ()
-- | Represent a DSA key pair -- | Represent a DSA key pair
data KeyPair = KeyPair Params PublicNumber PrivateNumber data KeyPair = KeyPair Params PublicNumber PrivateNumber
deriving (Show,Read,Eq,Data,Typeable) deriving (Show,Read,Eq,Data)
instance NFData KeyPair where instance NFData KeyPair where
rnf (KeyPair params y x) = x `seq` y `seq` params `seq` () rnf (KeyPair params y x) = x `seq` y `seq` params `seq` ()

View File

@ -31,23 +31,23 @@ import Crypto.Random.Types
data Signature = Signature data Signature = Signature
{ sign_r :: Integer -- ^ ECDSA r { sign_r :: Integer -- ^ ECDSA r
, sign_s :: Integer -- ^ ECDSA s , sign_s :: Integer -- ^ ECDSA s
} deriving (Show,Read,Eq,Data,Typeable) } deriving (Show,Read,Eq,Data)
-- | ECDSA Private Key. -- | ECDSA Private Key.
data PrivateKey = PrivateKey data PrivateKey = PrivateKey
{ private_curve :: Curve { private_curve :: Curve
, private_d :: PrivateNumber , private_d :: PrivateNumber
} deriving (Show,Read,Eq,Data,Typeable) } deriving (Show,Read,Eq,Data)
-- | ECDSA Public Key. -- | ECDSA Public Key.
data PublicKey = PublicKey data PublicKey = PublicKey
{ public_curve :: Curve { public_curve :: Curve
, public_q :: PublicPoint , public_q :: PublicPoint
} deriving (Show,Read,Eq,Data,Typeable) } deriving (Show,Read,Eq,Data)
-- | ECDSA Key Pair. -- | ECDSA Key Pair.
data KeyPair = KeyPair Curve PublicPoint PrivateNumber data KeyPair = KeyPair Curve PublicPoint PrivateNumber
deriving (Show,Read,Eq,Data,Typeable) deriving (Show,Read,Eq,Data)
-- | Public key of a ECDSA Key pair. -- | Public key of a ECDSA Key pair.
toPublicKey :: KeyPair -> PublicKey toPublicKey :: KeyPair -> PublicKey

View File

@ -33,7 +33,7 @@ import Crypto.Number.Basic (numBits)
-- | Define either a binary curve or a prime curve. -- | Define either a binary curve or a prime curve.
data Curve = CurveF2m CurveBinary -- ^ 𝔽(2^m) data Curve = CurveF2m CurveBinary -- ^ 𝔽(2^m)
| CurveFP CurvePrime -- ^ 𝔽p | CurveFP CurvePrime -- ^ 𝔽p
deriving (Show,Read,Eq,Data,Typeable) deriving (Show,Read,Eq,Data)
-- | ECC Public Point -- | ECC Public Point
type PublicPoint = Point type PublicPoint = Point
@ -44,7 +44,7 @@ type PrivateNumber = Integer
-- | Define a point on a curve. -- | Define a point on a curve.
data Point = Point Integer Integer data Point = Point Integer Integer
| PointO -- ^ Point at Infinity | PointO -- ^ Point at Infinity
deriving (Show,Read,Eq,Data,Typeable) deriving (Show,Read,Eq,Data)
instance NFData Point where instance NFData Point where
rnf (Point x y) = x `seq` y `seq` () rnf (Point x y) = x `seq` y `seq` ()
@ -53,7 +53,7 @@ instance NFData Point where
-- | Define an elliptic curve in 𝔽(2^m). -- | Define an elliptic curve in 𝔽(2^m).
-- The firt parameter is the Integer representatioin of the irreducible polynomial f(x). -- The firt parameter is the Integer representatioin of the irreducible polynomial f(x).
data CurveBinary = CurveBinary Integer CurveCommon data CurveBinary = CurveBinary Integer CurveCommon
deriving (Show,Read,Eq,Data,Typeable) deriving (Show,Read,Eq,Data)
instance NFData CurveBinary where instance NFData CurveBinary where
rnf (CurveBinary i cc) = i `seq` cc `seq` () rnf (CurveBinary i cc) = i `seq` cc `seq` ()
@ -61,7 +61,7 @@ instance NFData CurveBinary where
-- | Define an elliptic curve in 𝔽p. -- | Define an elliptic curve in 𝔽p.
-- The first parameter is the Prime Number. -- The first parameter is the Prime Number.
data CurvePrime = CurvePrime Integer CurveCommon data CurvePrime = CurvePrime Integer CurveCommon
deriving (Show,Read,Eq,Data,Typeable) deriving (Show,Read,Eq,Data)
-- | Parameters in common between binary and prime curves. -- | Parameters in common between binary and prime curves.
common_curve :: Curve -> CurveCommon common_curve :: Curve -> CurveCommon
@ -84,7 +84,7 @@ data CurveCommon = CurveCommon
, ecc_g :: Point -- ^ base point , ecc_g :: Point -- ^ base point
, ecc_n :: Integer -- ^ order of G , ecc_n :: Integer -- ^ order of G
, ecc_h :: Integer -- ^ cofactor , ecc_h :: Integer -- ^ cofactor
} deriving (Show,Read,Eq,Data,Typeable) } deriving (Show,Read,Eq,Data)
-- | Define names for known recommended curves. -- | Define names for known recommended curves.
data CurveName = data CurveName =
@ -121,7 +121,7 @@ data CurveName =
| SEC_t409r1 | SEC_t409r1
| SEC_t571k1 | SEC_t571k1
| SEC_t571r1 | SEC_t571r1
deriving (Show,Read,Eq,Ord,Enum,Bounded,Data,Typeable) deriving (Show,Read,Eq,Ord,Enum,Bounded,Data)
{- {-
curvesOIDs :: [ (CurveName, [Integer]) ] curvesOIDs :: [ (CurveName, [Integer]) ]

View File

@ -27,7 +27,6 @@ module Crypto.PubKey.ECIES
import Crypto.ECC import Crypto.ECC
import Crypto.Error import Crypto.Error
import Crypto.Random import Crypto.Random
import Crypto.Internal.Proxy
-- | Generate random a new Shared secret and the associated point -- | Generate random a new Shared secret and the associated point
-- to do a ECIES style encryption -- to do a ECIES style encryption

View File

@ -16,7 +16,6 @@ module Crypto.PubKey.RSA
, generateBlinder , generateBlinder
) where ) where
import Crypto.Internal.Imports
import Crypto.Random.Types import Crypto.Random.Types
import Crypto.Number.ModArithmetic (inverse, inverseCoprimes) import Crypto.Number.ModArithmetic (inverse, inverseCoprimes)
import Crypto.Number.Generate (generateMax) import Crypto.Number.Generate (generateMax)

View File

@ -42,7 +42,7 @@ data PublicKey = PublicKey
{ public_size :: Int -- ^ size of key in bytes { public_size :: Int -- ^ size of key in bytes
, public_n :: Integer -- ^ public p*q , public_n :: Integer -- ^ public p*q
, public_e :: Integer -- ^ public exponent e , public_e :: Integer -- ^ public exponent e
} deriving (Show,Read,Eq,Data,Typeable) } deriving (Show,Read,Eq,Data)
instance NFData PublicKey where instance NFData PublicKey where
rnf (PublicKey sz n e) = rnf n `seq` rnf e `seq` sz `seq` () 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_dP :: Integer -- ^ d mod (p-1)
, private_dQ :: Integer -- ^ d mod (q-1) , private_dQ :: Integer -- ^ d mod (q-1)
, private_qinv :: Integer -- ^ q^(-1) mod p , private_qinv :: Integer -- ^ q^(-1) mod p
} deriving (Show,Read,Eq,Data,Typeable) } deriving (Show,Read,Eq,Data)
instance NFData PrivateKey where instance NFData PrivateKey where
rnf (PrivateKey pub d p q dp dq qinv) = 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 -- note the RSA private key contains already an instance of public key for efficiency
newtype KeyPair = KeyPair PrivateKey newtype KeyPair = KeyPair PrivateKey
deriving (Show,Read,Eq,Data,Typeable,NFData) deriving (Show,Read,Eq,Data,NFData)
-- | Public key of a RSA KeyPair -- | Public key of a RSA KeyPair
toPublicKey :: KeyPair -> PublicKey toPublicKey :: KeyPair -> PublicKey

View File

@ -27,9 +27,8 @@ import Data.Data
import Data.Either (rights) import Data.Either (rights)
import Crypto.Hash 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.ModArithmetic (expSafe, jacobi)
import Crypto.Number.Prime (isProbablyPrime)
import Crypto.Number.Serialize (i2osp, i2ospOf_, os2ip) import Crypto.Number.Serialize (i2osp, i2ospOf_, os2ip)
import Crypto.PubKey.Rabin.OAEP import Crypto.PubKey.Rabin.OAEP
import Crypto.PubKey.Rabin.Types import Crypto.PubKey.Rabin.Types
@ -39,7 +38,7 @@ import Crypto.Random (MonadRandom, getRandomBytes)
data PublicKey = PublicKey data PublicKey = PublicKey
{ public_size :: Int -- ^ size of key in bytes { public_size :: Int -- ^ size of key in bytes
, public_n :: Integer -- ^ public p*q , public_n :: Integer -- ^ public p*q
} deriving (Show, Read, Eq, Data, Typeable) } deriving (Show, Read, Eq, Data)
-- | Represent a Rabin private key. -- | Represent a Rabin private key.
data PrivateKey = PrivateKey data PrivateKey = PrivateKey
@ -48,10 +47,10 @@ data PrivateKey = PrivateKey
, private_q :: Integer -- ^ q prime number , private_q :: Integer -- ^ q prime number
, private_a :: Integer , private_a :: Integer
, private_b :: Integer , private_b :: Integer
} deriving (Show, Read, Eq, Data, Typeable) } deriving (Show, Read, Eq, Data)
-- | Rabin Signature. -- | 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. -- | Generate a pair of (private, public) key of size in bytes.
-- Primes p and q are both congruent 3 mod 4. -- Primes p and q are both congruent 3 mod 4.

View File

@ -18,13 +18,11 @@ module Crypto.PubKey.Rabin.Modified
) where ) where
import Data.ByteString import Data.ByteString
import qualified Data.ByteString as B
import Data.Data import Data.Data
import Crypto.Hash import Crypto.Hash
import Crypto.Number.Basic (gcde)
import Crypto.Number.ModArithmetic (expSafe, jacobi) import Crypto.Number.ModArithmetic (expSafe, jacobi)
import Crypto.Number.Serialize (i2osp, os2ip) import Crypto.Number.Serialize (os2ip)
import Crypto.PubKey.Rabin.Types import Crypto.PubKey.Rabin.Types
import Crypto.Random.Types import Crypto.Random.Types
@ -32,7 +30,7 @@ import Crypto.Random.Types
data PublicKey = PublicKey data PublicKey = PublicKey
{ public_size :: Int -- ^ size of key in bytes { public_size :: Int -- ^ size of key in bytes
, public_n :: Integer -- ^ public p*q , public_n :: Integer -- ^ public p*q
} deriving (Show, Read, Eq, Data, Typeable) } deriving (Show, Read, Eq, Data)
-- | Represent a Modified-Rabin private key. -- | Represent a Modified-Rabin private key.
data PrivateKey = PrivateKey data PrivateKey = PrivateKey
@ -40,7 +38,7 @@ data PrivateKey = PrivateKey
, private_p :: Integer -- ^ p prime number , private_p :: Integer -- ^ p prime number
, private_q :: Integer -- ^ q prime number , private_q :: Integer -- ^ q prime number
, private_d :: Integer , 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. -- | 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. -- Prime p is congruent 3 mod 8 and prime q is congruent 7 mod 8.

View File

@ -22,11 +22,10 @@ module Crypto.PubKey.Rabin.RW
) where ) where
import Data.ByteString import Data.ByteString
import qualified Data.ByteString as B
import Data.Data import Data.Data
import Crypto.Hash import Crypto.Hash
import Crypto.Number.Basic (numBytes, gcde) import Crypto.Number.Basic (numBytes)
import Crypto.Number.ModArithmetic (expSafe, jacobi) import Crypto.Number.ModArithmetic (expSafe, jacobi)
import Crypto.Number.Serialize (i2osp, i2ospOf_, os2ip) import Crypto.Number.Serialize (i2osp, i2ospOf_, os2ip)
import Crypto.PubKey.Rabin.OAEP import Crypto.PubKey.Rabin.OAEP
@ -37,7 +36,7 @@ import Crypto.Random.Types
data PublicKey = PublicKey data PublicKey = PublicKey
{ public_size :: Int -- ^ size of key in bytes { public_size :: Int -- ^ size of key in bytes
, public_n :: Integer -- ^ public p*q , public_n :: Integer -- ^ public p*q
} deriving (Show, Read, Eq, Data, Typeable) } deriving (Show, Read, Eq, Data)
-- | Represent a Rabin-Williams private key. -- | Represent a Rabin-Williams private key.
data PrivateKey = PrivateKey data PrivateKey = PrivateKey
@ -45,7 +44,7 @@ data PrivateKey = PrivateKey
, private_p :: Integer -- ^ p prime number , private_p :: Integer -- ^ p prime number
, private_q :: Integer -- ^ q prime number , private_q :: Integer -- ^ q prime number
, private_d :: Integer , 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. -- | 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. -- Prime p is congruent 3 mod 8 and prime q is congruent 7 mod 8.

View File

@ -29,7 +29,7 @@ newtype ChaChaDRG = ChaChaDRG C.StateSimple
-- | Initialize a new ChaCha context with the number of rounds, -- | Initialize a new ChaCha context with the number of rounds,
-- the key and the nonce associated. -- the key and the nonce associated.
initialize :: B.ByteArrayAccess seed initialize :: ByteArrayAccess seed
=> seed -- ^ 40 bytes of seed => seed -- ^ 40 bytes of seed
-> ChaChaDRG -- ^ the initial ChaCha state -> ChaChaDRG -- ^ the initial ChaCha state
initialize seed = ChaChaDRG $ C.initializeSimple seed initialize seed = ChaChaDRG $ C.initializeSimple seed

View File

@ -14,7 +14,6 @@ module Crypto.Random.SystemDRG
import Crypto.Random.Types import Crypto.Random.Types
import Crypto.Random.Entropy.Unsafe import Crypto.Random.Entropy.Unsafe
import Crypto.Internal.Compat import Crypto.Internal.Compat
import Crypto.Internal.Imports
import Data.ByteArray (ScrubbedBytes, ByteArray) import Data.ByteArray (ScrubbedBytes, ByteArray)
import Data.Memory.PtrMethods as B (memCopy) import Data.Memory.PtrMethods as B (memCopy)
import Data.Maybe (catMaybes) import Data.Maybe (catMaybes)

View File

@ -15,7 +15,6 @@ module Crypto.Random.Types
import Crypto.Random.Entropy import Crypto.Random.Entropy
import Crypto.Internal.ByteArray import Crypto.Internal.ByteArray
import Crypto.Internal.Imports
-- | A monad constraint that allows to generate random bytes -- | A monad constraint that allows to generate random bytes
class (Functor m, Monad m) => MonadRandom m where class (Functor m, Monad m) => MonadRandom m where
@ -47,7 +46,7 @@ instance DRG gen => Applicative (MonadPseudoRandom gen) where
in (f a, g3) in (f a, g3)
instance DRG gen => Monad (MonadPseudoRandom gen) where instance DRG gen => Monad (MonadPseudoRandom gen) where
return a = MonadPseudoRandom $ \g -> (a, g) return = pure
(>>=) m1 m2 = MonadPseudoRandom $ \g1 -> (>>=) m1 m2 = MonadPseudoRandom $ \g1 ->
let (a, g2) = runPseudoRandom m1 g1 let (a, g2) = runPseudoRandom m1 g1
in runPseudoRandom (m2 a) g2 in runPseudoRandom (m2 a) g2

View File

@ -1,3 +1,3 @@
# ~*~ auto-generated by haskell-ci with config : 8f74deffc95fd794fa2996c167c6543bbfab1ae432f0a83e0898f0b5871a92eb ~*~ # ~*~ auto-generated by haskell-ci with config : 8f74deffc95fd794fa2996c167c6543bbfab1ae432f0a83e0898f0b5871a92eb ~*~
{ resolver: lts-12.26, packages: [ '.' ], extra-deps: [], flags: {} } { resolver: lts-13.2, packages: [ '.' ], extra-deps: [], flags: {} }

View File

@ -1,7 +1,6 @@
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
module KAT_CAST5 (tests) where module KAT_CAST5 (tests) where
import Imports
import BlockCipher import BlockCipher
import qualified Crypto.Cipher.CAST5 as CAST5 import qualified Crypto.Cipher.CAST5 as CAST5

View File

@ -2,10 +2,7 @@
module KAT_HKDF (tests) where module KAT_HKDF (tests) where
import qualified Crypto.KDF.HKDF as HKDF import qualified Crypto.KDF.HKDF as HKDF
import Crypto.Hash (MD5(..), SHA1(..), SHA256(..) import Crypto.Hash (SHA256(..), HashAlgorithm)
, Keccak_224(..), Keccak_256(..), Keccak_384(..), Keccak_512(..)
, SHA3_224(..), SHA3_256(..), SHA3_384(..), SHA3_512(..)
, HashAlgorithm, digestFromByteString)
import qualified Data.ByteString as B import qualified Data.ByteString as B
import Imports import Imports

View File

@ -6,7 +6,6 @@ import Crypto.ConstructHash.MiyaguchiPreneel as MiyaguchiPreneel
import Imports import Imports
import Data.Char (digitToInt)
import qualified Data.ByteString.Char8 as B8 import qualified Data.ByteString.Char8 as B8
import qualified Data.ByteArray as B import qualified Data.ByteArray as B
import Data.ByteArray.Encoding (Base (Base16), convertFromBase) import Data.ByteArray.Encoding (Base (Base16), convertFromBase)

View File

@ -94,9 +94,9 @@ tests = testGroup "OTP"
] ]
, testGroup "TOTP" , testGroup "TOTP"
[ testGroup "KATs" [ testGroup "KATs"
[ testGroup "SHA1" (makeKATs (totp totpSHA1Params otpKey . fromIntegral) totpSHA1Expected) [ testGroup "SHA1" (makeKATs (totp totpSHA1Params otpKey) totpSHA1Expected)
, testGroup "SHA256" (makeKATs (totp totpSHA256Params totpSHA256Key . fromIntegral) totpSHA256Expected) , testGroup "SHA256" (makeKATs (totp totpSHA256Params totpSHA256Key) totpSHA256Expected)
, testGroup "SHA512" (makeKATs (totp totpSHA512Params totpSHA512Key . fromIntegral) totpSHA512Expected) , testGroup "SHA512" (makeKATs (totp totpSHA512Params totpSHA512Key) totpSHA512Expected)
] ]
] ]
] ]

View File

@ -3,7 +3,6 @@ module Padding (tests) where
import qualified Data.ByteString as B import qualified Data.ByteString as B
import Imports import Imports
import Crypto.Error
import Crypto.Data.Padding import Crypto.Data.Padding