Merge pull request #267 from crockeea/master-clean
Code maintenance and cleanup
This commit is contained in:
commit
540ef78abb
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -4,7 +4,6 @@ module Crypto.Cipher.Utils
|
||||
|
||||
import Crypto.Error
|
||||
import Crypto.Cipher.Types
|
||||
import Crypto.Internal.Imports
|
||||
|
||||
import Data.ByteArray as BA
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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` ()
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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.
|
||||
--
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -28,7 +28,6 @@ module Crypto.PubKey.Curve448
|
||||
|
||||
import Data.Word
|
||||
import Foreign.Ptr
|
||||
import GHC.Ptr
|
||||
|
||||
import Crypto.Error
|
||||
import Crypto.Random
|
||||
|
||||
@ -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` ()
|
||||
|
||||
@ -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` ()
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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]) ]
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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: {} }
|
||||
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
module KAT_CAST5 (tests) where
|
||||
|
||||
import Imports
|
||||
import BlockCipher
|
||||
import qualified Crypto.Cipher.CAST5 as CAST5
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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)
|
||||
]
|
||||
]
|
||||
]
|
||||
|
||||
@ -3,7 +3,6 @@ module Padding (tests) where
|
||||
|
||||
import qualified Data.ByteString as B
|
||||
import Imports
|
||||
import Crypto.Error
|
||||
|
||||
import Crypto.Data.Padding
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user