Add HashBlockSize & HashDigestSize & HashInternalContextSize type family for all Hash algorithms
supercedes PR #158
This commit is contained in:
parent
cb293eb6db
commit
0dc0f30b86
@ -63,6 +63,9 @@ data Blake2s (bitlen :: Nat) = Blake2s
|
||||
instance (IsDivisibleBy8 bitlen, KnownNat bitlen, IsAtLeast bitlen 8, IsAtMost bitlen 256)
|
||||
=> HashAlgorithm (Blake2s bitlen)
|
||||
where
|
||||
type HashBlockSize (Blake2s bitlen) = 64
|
||||
type HashDigestSize (Blake2s bitlen) = bitlen
|
||||
type HashInternalContextSize (Blake2s bitlen) = 185
|
||||
hashBlockSize _ = 64
|
||||
hashDigestSize _ = byteLen (Proxy :: Proxy bitlen)
|
||||
hashInternalContextSize _ = 185
|
||||
@ -95,6 +98,9 @@ data Blake2b (bitlen :: Nat) = Blake2b
|
||||
instance (IsDivisibleBy8 bitlen, KnownNat bitlen, IsAtLeast bitlen 8, IsAtMost bitlen 512)
|
||||
=> HashAlgorithm (Blake2b bitlen)
|
||||
where
|
||||
type HashBlockSize (Blake2b bitlen) = 128
|
||||
type HashDigestSize (Blake2b bitlen) = bitlen
|
||||
type HashInternalContextSize (Blake2b bitlen) = 361
|
||||
hashBlockSize _ = 128
|
||||
hashDigestSize _ = byteLen (Proxy :: Proxy bitlen)
|
||||
hashInternalContextSize _ = 361
|
||||
@ -115,6 +121,9 @@ data Blake2sp (bitlen :: Nat) = Blake2sp
|
||||
instance (IsDivisibleBy8 bitlen, KnownNat bitlen, IsAtLeast bitlen 8, IsAtMost bitlen 256)
|
||||
=> HashAlgorithm (Blake2sp bitlen)
|
||||
where
|
||||
type HashBlockSize (Blake2sp bitlen) = 64
|
||||
type HashDigestSize (Blake2sp bitlen) = bitlen
|
||||
type HashInternalContextSize (Blake2sp bitlen) = 2185
|
||||
hashBlockSize _ = 64
|
||||
hashDigestSize _ = byteLen (Proxy :: Proxy bitlen)
|
||||
hashInternalContextSize _ = 2185
|
||||
@ -135,6 +144,9 @@ data Blake2bp (bitlen :: Nat) = Blake2bp
|
||||
instance (IsDivisibleBy8 bitlen, KnownNat bitlen, IsAtLeast bitlen 8, IsAtMost bitlen 512)
|
||||
=> HashAlgorithm (Blake2bp bitlen)
|
||||
where
|
||||
type HashBlockSize (Blake2bp bitlen) = 128
|
||||
type HashDigestSize (Blake2bp bitlen) = bitlen
|
||||
type HashInternalContextSize (Blake2bp bitlen) = 2325
|
||||
hashBlockSize _ = 128
|
||||
hashDigestSize _ = byteLen (Proxy :: Proxy bitlen)
|
||||
hashInternalContextSize _ = 2325
|
||||
|
||||
@ -10,6 +10,8 @@
|
||||
--
|
||||
{-# LANGUAGE ForeignFunctionInterface #-}
|
||||
{-# LANGUAGE DeriveDataTypeable #-}
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
module Crypto.Hash.Blake2b
|
||||
( Blake2b_160 (..), Blake2b_224 (..), Blake2b_256 (..), Blake2b_384 (..), Blake2b_512 (..)
|
||||
) where
|
||||
@ -26,6 +28,9 @@ data Blake2b_160 = Blake2b_160
|
||||
deriving (Show,Data,Typeable)
|
||||
|
||||
instance HashAlgorithm Blake2b_160 where
|
||||
type HashBlockSize Blake2b_160 = 128
|
||||
type HashDigestSize Blake2b_160 = 20
|
||||
type HashInternalContextSize Blake2b_160 = 361
|
||||
hashBlockSize _ = 128
|
||||
hashDigestSize _ = 20
|
||||
hashInternalContextSize _ = 361
|
||||
@ -38,6 +43,9 @@ data Blake2b_224 = Blake2b_224
|
||||
deriving (Show,Data,Typeable)
|
||||
|
||||
instance HashAlgorithm Blake2b_224 where
|
||||
type HashBlockSize Blake2b_224 = 128
|
||||
type HashDigestSize Blake2b_224 = 28
|
||||
type HashInternalContextSize Blake2b_224 = 361
|
||||
hashBlockSize _ = 128
|
||||
hashDigestSize _ = 28
|
||||
hashInternalContextSize _ = 361
|
||||
@ -50,6 +58,9 @@ data Blake2b_256 = Blake2b_256
|
||||
deriving (Show,Data,Typeable)
|
||||
|
||||
instance HashAlgorithm Blake2b_256 where
|
||||
type HashBlockSize Blake2b_256 = 128
|
||||
type HashDigestSize Blake2b_256 = 32
|
||||
type HashInternalContextSize Blake2b_256 = 361
|
||||
hashBlockSize _ = 128
|
||||
hashDigestSize _ = 32
|
||||
hashInternalContextSize _ = 361
|
||||
@ -62,6 +73,9 @@ data Blake2b_384 = Blake2b_384
|
||||
deriving (Show,Data,Typeable)
|
||||
|
||||
instance HashAlgorithm Blake2b_384 where
|
||||
type HashBlockSize Blake2b_384 = 128
|
||||
type HashDigestSize Blake2b_384 = 48
|
||||
type HashInternalContextSize Blake2b_384 = 361
|
||||
hashBlockSize _ = 128
|
||||
hashDigestSize _ = 48
|
||||
hashInternalContextSize _ = 361
|
||||
@ -74,6 +88,9 @@ data Blake2b_512 = Blake2b_512
|
||||
deriving (Show,Data,Typeable)
|
||||
|
||||
instance HashAlgorithm Blake2b_512 where
|
||||
type HashBlockSize Blake2b_512 = 128
|
||||
type HashDigestSize Blake2b_512 = 64
|
||||
type HashInternalContextSize Blake2b_512 = 361
|
||||
hashBlockSize _ = 128
|
||||
hashDigestSize _ = 64
|
||||
hashInternalContextSize _ = 361
|
||||
|
||||
@ -10,6 +10,8 @@
|
||||
--
|
||||
{-# LANGUAGE ForeignFunctionInterface #-}
|
||||
{-# LANGUAGE DeriveDataTypeable #-}
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
module Crypto.Hash.Blake2bp
|
||||
( Blake2bp_512 (..)
|
||||
) where
|
||||
@ -26,6 +28,9 @@ data Blake2bp_512 = Blake2bp_512
|
||||
deriving (Show,Data,Typeable)
|
||||
|
||||
instance HashAlgorithm Blake2bp_512 where
|
||||
type HashBlockSize Blake2bp_512 = 128
|
||||
type HashDigestSize Blake2bp_512 = 64
|
||||
type HashInternalContextSize Blake2bp_512 = 2325
|
||||
hashBlockSize _ = 128
|
||||
hashDigestSize _ = 64
|
||||
hashInternalContextSize _ = 2325
|
||||
|
||||
@ -10,6 +10,8 @@
|
||||
--
|
||||
{-# LANGUAGE ForeignFunctionInterface #-}
|
||||
{-# LANGUAGE DeriveDataTypeable #-}
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
module Crypto.Hash.Blake2s
|
||||
( Blake2s_160 (..), Blake2s_224 (..), Blake2s_256 (..)
|
||||
) where
|
||||
@ -26,6 +28,9 @@ data Blake2s_160 = Blake2s_160
|
||||
deriving (Show,Data,Typeable)
|
||||
|
||||
instance HashAlgorithm Blake2s_160 where
|
||||
type HashBlockSize Blake2s_160 = 64
|
||||
type HashDigestSize Blake2s_160 = 20
|
||||
type HashInternalContextSize Blake2s_160 = 185
|
||||
hashBlockSize _ = 64
|
||||
hashDigestSize _ = 20
|
||||
hashInternalContextSize _ = 185
|
||||
@ -38,6 +43,9 @@ data Blake2s_224 = Blake2s_224
|
||||
deriving (Show,Data,Typeable)
|
||||
|
||||
instance HashAlgorithm Blake2s_224 where
|
||||
type HashBlockSize Blake2s_224 = 64
|
||||
type HashDigestSize Blake2s_224 = 28
|
||||
type HashInternalContextSize Blake2s_224 = 185
|
||||
hashBlockSize _ = 64
|
||||
hashDigestSize _ = 28
|
||||
hashInternalContextSize _ = 185
|
||||
@ -50,6 +58,9 @@ data Blake2s_256 = Blake2s_256
|
||||
deriving (Show,Data,Typeable)
|
||||
|
||||
instance HashAlgorithm Blake2s_256 where
|
||||
type HashBlockSize Blake2s_256 = 64
|
||||
type HashDigestSize Blake2s_256 = 32
|
||||
type HashInternalContextSize Blake2s_256 = 185
|
||||
hashBlockSize _ = 64
|
||||
hashDigestSize _ = 32
|
||||
hashInternalContextSize _ = 185
|
||||
|
||||
@ -10,6 +10,8 @@
|
||||
--
|
||||
{-# LANGUAGE ForeignFunctionInterface #-}
|
||||
{-# LANGUAGE DeriveDataTypeable #-}
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
module Crypto.Hash.Blake2sp
|
||||
( Blake2sp_224 (..), Blake2sp_256 (..)
|
||||
) where
|
||||
@ -26,6 +28,9 @@ data Blake2sp_224 = Blake2sp_224
|
||||
deriving (Show,Data,Typeable)
|
||||
|
||||
instance HashAlgorithm Blake2sp_224 where
|
||||
type HashBlockSize Blake2sp_224 = 64
|
||||
type HashDigestSize Blake2sp_224 = 28
|
||||
type HashInternalContextSize Blake2sp_224 = 2185
|
||||
hashBlockSize _ = 64
|
||||
hashDigestSize _ = 28
|
||||
hashInternalContextSize _ = 2185
|
||||
@ -38,6 +43,9 @@ data Blake2sp_256 = Blake2sp_256
|
||||
deriving (Show,Data,Typeable)
|
||||
|
||||
instance HashAlgorithm Blake2sp_256 where
|
||||
type HashBlockSize Blake2sp_256 = 64
|
||||
type HashDigestSize Blake2sp_256 = 32
|
||||
type HashInternalContextSize Blake2sp_256 = 2185
|
||||
hashBlockSize _ = 64
|
||||
hashDigestSize _ = 32
|
||||
hashInternalContextSize _ = 2185
|
||||
|
||||
@ -10,6 +10,8 @@
|
||||
--
|
||||
{-# LANGUAGE ForeignFunctionInterface #-}
|
||||
{-# LANGUAGE DeriveDataTypeable #-}
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
module Crypto.Hash.Keccak
|
||||
( Keccak_224 (..), Keccak_256 (..), Keccak_384 (..), Keccak_512 (..)
|
||||
) where
|
||||
@ -26,6 +28,9 @@ data Keccak_224 = Keccak_224
|
||||
deriving (Show,Data,Typeable)
|
||||
|
||||
instance HashAlgorithm Keccak_224 where
|
||||
type HashBlockSize Keccak_224 = 144
|
||||
type HashDigestSize Keccak_224 = 28
|
||||
type HashInternalContextSize Keccak_224 = 352
|
||||
hashBlockSize _ = 144
|
||||
hashDigestSize _ = 28
|
||||
hashInternalContextSize _ = 352
|
||||
@ -38,6 +43,9 @@ data Keccak_256 = Keccak_256
|
||||
deriving (Show,Data,Typeable)
|
||||
|
||||
instance HashAlgorithm Keccak_256 where
|
||||
type HashBlockSize Keccak_256 = 136
|
||||
type HashDigestSize Keccak_256 = 32
|
||||
type HashInternalContextSize Keccak_256 = 344
|
||||
hashBlockSize _ = 136
|
||||
hashDigestSize _ = 32
|
||||
hashInternalContextSize _ = 344
|
||||
@ -50,6 +58,9 @@ data Keccak_384 = Keccak_384
|
||||
deriving (Show,Data,Typeable)
|
||||
|
||||
instance HashAlgorithm Keccak_384 where
|
||||
type HashBlockSize Keccak_384 = 104
|
||||
type HashDigestSize Keccak_384 = 48
|
||||
type HashInternalContextSize Keccak_384 = 312
|
||||
hashBlockSize _ = 104
|
||||
hashDigestSize _ = 48
|
||||
hashInternalContextSize _ = 312
|
||||
@ -62,6 +73,9 @@ data Keccak_512 = Keccak_512
|
||||
deriving (Show,Data,Typeable)
|
||||
|
||||
instance HashAlgorithm Keccak_512 where
|
||||
type HashBlockSize Keccak_512 = 72
|
||||
type HashDigestSize Keccak_512 = 64
|
||||
type HashInternalContextSize Keccak_512 = 280
|
||||
hashBlockSize _ = 72
|
||||
hashDigestSize _ = 64
|
||||
hashInternalContextSize _ = 280
|
||||
|
||||
@ -10,6 +10,8 @@
|
||||
--
|
||||
{-# LANGUAGE ForeignFunctionInterface #-}
|
||||
{-# LANGUAGE DeriveDataTypeable #-}
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
module Crypto.Hash.MD2 ( MD2 (..) ) where
|
||||
|
||||
import Crypto.Hash.Types
|
||||
@ -23,6 +25,9 @@ data MD2 = MD2
|
||||
deriving (Show,Data,Typeable)
|
||||
|
||||
instance HashAlgorithm MD2 where
|
||||
type HashBlockSize MD2 = 16
|
||||
type HashDigestSize MD2 = 16
|
||||
type HashInternalContextSize MD2 = 96
|
||||
hashBlockSize _ = 16
|
||||
hashDigestSize _ = 16
|
||||
hashInternalContextSize _ = 96
|
||||
|
||||
@ -10,6 +10,8 @@
|
||||
--
|
||||
{-# LANGUAGE ForeignFunctionInterface #-}
|
||||
{-# LANGUAGE DeriveDataTypeable #-}
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
module Crypto.Hash.MD4 ( MD4 (..) ) where
|
||||
|
||||
import Crypto.Hash.Types
|
||||
@ -23,6 +25,9 @@ data MD4 = MD4
|
||||
deriving (Show,Data,Typeable)
|
||||
|
||||
instance HashAlgorithm MD4 where
|
||||
type HashBlockSize MD4 = 64
|
||||
type HashDigestSize MD4 = 16
|
||||
type HashInternalContextSize MD4 = 96
|
||||
hashBlockSize _ = 64
|
||||
hashDigestSize _ = 16
|
||||
hashInternalContextSize _ = 96
|
||||
|
||||
@ -10,6 +10,8 @@
|
||||
--
|
||||
{-# LANGUAGE ForeignFunctionInterface #-}
|
||||
{-# LANGUAGE DeriveDataTypeable #-}
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
module Crypto.Hash.MD5 ( MD5 (..) ) where
|
||||
|
||||
import Crypto.Hash.Types
|
||||
@ -23,6 +25,9 @@ data MD5 = MD5
|
||||
deriving (Show,Data,Typeable)
|
||||
|
||||
instance HashAlgorithm MD5 where
|
||||
type HashBlockSize MD5 = 64
|
||||
type HashDigestSize MD5 = 16
|
||||
type HashInternalContextSize MD5 = 96
|
||||
hashBlockSize _ = 64
|
||||
hashDigestSize _ = 16
|
||||
hashInternalContextSize _ = 96
|
||||
|
||||
@ -10,6 +10,8 @@
|
||||
--
|
||||
{-# LANGUAGE ForeignFunctionInterface #-}
|
||||
{-# LANGUAGE DeriveDataTypeable #-}
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
module Crypto.Hash.RIPEMD160 ( RIPEMD160 (..) ) where
|
||||
|
||||
import Crypto.Hash.Types
|
||||
@ -23,6 +25,9 @@ data RIPEMD160 = RIPEMD160
|
||||
deriving (Show,Data,Typeable)
|
||||
|
||||
instance HashAlgorithm RIPEMD160 where
|
||||
type HashBlockSize RIPEMD160 = 64
|
||||
type HashDigestSize RIPEMD160 = 20
|
||||
type HashInternalContextSize RIPEMD160 = 128
|
||||
hashBlockSize _ = 64
|
||||
hashDigestSize _ = 20
|
||||
hashInternalContextSize _ = 128
|
||||
|
||||
@ -10,6 +10,8 @@
|
||||
--
|
||||
{-# LANGUAGE ForeignFunctionInterface #-}
|
||||
{-# LANGUAGE DeriveDataTypeable #-}
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
module Crypto.Hash.SHA1 ( SHA1 (..) ) where
|
||||
|
||||
import Crypto.Hash.Types
|
||||
@ -23,6 +25,9 @@ data SHA1 = SHA1
|
||||
deriving (Show,Data,Typeable)
|
||||
|
||||
instance HashAlgorithm SHA1 where
|
||||
type HashBlockSize SHA1 = 64
|
||||
type HashDigestSize SHA1 = 20
|
||||
type HashInternalContextSize SHA1 = 96
|
||||
hashBlockSize _ = 64
|
||||
hashDigestSize _ = 20
|
||||
hashInternalContextSize _ = 96
|
||||
|
||||
@ -10,6 +10,8 @@
|
||||
--
|
||||
{-# LANGUAGE ForeignFunctionInterface #-}
|
||||
{-# LANGUAGE DeriveDataTypeable #-}
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
module Crypto.Hash.SHA224 ( SHA224 (..) ) where
|
||||
|
||||
import Crypto.Hash.Types
|
||||
@ -23,6 +25,9 @@ data SHA224 = SHA224
|
||||
deriving (Show,Data,Typeable)
|
||||
|
||||
instance HashAlgorithm SHA224 where
|
||||
type HashBlockSize SHA224 = 64
|
||||
type HashDigestSize SHA224 = 28
|
||||
type HashInternalContextSize SHA224 = 192
|
||||
hashBlockSize _ = 64
|
||||
hashDigestSize _ = 28
|
||||
hashInternalContextSize _ = 192
|
||||
|
||||
@ -10,6 +10,8 @@
|
||||
--
|
||||
{-# LANGUAGE ForeignFunctionInterface #-}
|
||||
{-# LANGUAGE DeriveDataTypeable #-}
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
module Crypto.Hash.SHA256 ( SHA256 (..) ) where
|
||||
|
||||
import Crypto.Hash.Types
|
||||
@ -23,6 +25,9 @@ data SHA256 = SHA256
|
||||
deriving (Show,Data,Typeable)
|
||||
|
||||
instance HashAlgorithm SHA256 where
|
||||
type HashBlockSize SHA256 = 64
|
||||
type HashDigestSize SHA256 = 32
|
||||
type HashInternalContextSize SHA256 = 192
|
||||
hashBlockSize _ = 64
|
||||
hashDigestSize _ = 32
|
||||
hashInternalContextSize _ = 192
|
||||
|
||||
@ -10,6 +10,8 @@
|
||||
--
|
||||
{-# LANGUAGE ForeignFunctionInterface #-}
|
||||
{-# LANGUAGE DeriveDataTypeable #-}
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
module Crypto.Hash.SHA3
|
||||
( SHA3_224 (..), SHA3_256 (..), SHA3_384 (..), SHA3_512 (..)
|
||||
) where
|
||||
@ -20,11 +22,15 @@ 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)
|
||||
|
||||
instance HashAlgorithm SHA3_224 where
|
||||
type HashBlockSize SHA3_224 = 144
|
||||
type HashDigestSize SHA3_224 = 28
|
||||
type HashInternalContextSize SHA3_224 = 352
|
||||
hashBlockSize _ = 144
|
||||
hashDigestSize _ = 28
|
||||
hashInternalContextSize _ = 352
|
||||
@ -37,6 +43,9 @@ data SHA3_256 = SHA3_256
|
||||
deriving (Show,Data,Typeable)
|
||||
|
||||
instance HashAlgorithm SHA3_256 where
|
||||
type HashBlockSize SHA3_256 = 136
|
||||
type HashDigestSize SHA3_256 = 32
|
||||
type HashInternalContextSize SHA3_256 = 344
|
||||
hashBlockSize _ = 136
|
||||
hashDigestSize _ = 32
|
||||
hashInternalContextSize _ = 344
|
||||
@ -49,6 +58,9 @@ data SHA3_384 = SHA3_384
|
||||
deriving (Show,Data,Typeable)
|
||||
|
||||
instance HashAlgorithm SHA3_384 where
|
||||
type HashBlockSize SHA3_384 = 104
|
||||
type HashDigestSize SHA3_384 = 48
|
||||
type HashInternalContextSize SHA3_384 = 312
|
||||
hashBlockSize _ = 104
|
||||
hashDigestSize _ = 48
|
||||
hashInternalContextSize _ = 312
|
||||
@ -61,6 +73,9 @@ data SHA3_512 = SHA3_512
|
||||
deriving (Show,Data,Typeable)
|
||||
|
||||
instance HashAlgorithm SHA3_512 where
|
||||
type HashBlockSize SHA3_512 = 72
|
||||
type HashDigestSize SHA3_512 = 64
|
||||
type HashInternalContextSize SHA3_512 = 280
|
||||
hashBlockSize _ = 72
|
||||
hashDigestSize _ = 64
|
||||
hashInternalContextSize _ = 280
|
||||
@ -68,6 +83,7 @@ instance HashAlgorithm SHA3_512 where
|
||||
hashInternalUpdate = c_sha3_update
|
||||
hashInternalFinalize p = c_sha3_finalize p 512
|
||||
|
||||
|
||||
foreign import ccall unsafe "cryptonite_sha3_init"
|
||||
c_sha3_init :: Ptr (Context a) -> Word32 -> IO ()
|
||||
|
||||
|
||||
@ -10,6 +10,8 @@
|
||||
--
|
||||
{-# LANGUAGE ForeignFunctionInterface #-}
|
||||
{-# LANGUAGE DeriveDataTypeable #-}
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
module Crypto.Hash.SHA384 ( SHA384 (..) ) where
|
||||
|
||||
import Crypto.Hash.Types
|
||||
@ -23,6 +25,9 @@ data SHA384 = SHA384
|
||||
deriving (Show,Data,Typeable)
|
||||
|
||||
instance HashAlgorithm SHA384 where
|
||||
type HashBlockSize SHA384 = 128
|
||||
type HashDigestSize SHA384 = 48
|
||||
type HashInternalContextSize SHA384 = 256
|
||||
hashBlockSize _ = 128
|
||||
hashDigestSize _ = 48
|
||||
hashInternalContextSize _ = 256
|
||||
|
||||
@ -10,6 +10,8 @@
|
||||
--
|
||||
{-# LANGUAGE ForeignFunctionInterface #-}
|
||||
{-# LANGUAGE DeriveDataTypeable #-}
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
module Crypto.Hash.SHA512 ( SHA512 (..) ) where
|
||||
|
||||
import Crypto.Hash.Types
|
||||
@ -23,6 +25,9 @@ data SHA512 = SHA512
|
||||
deriving (Show,Data,Typeable)
|
||||
|
||||
instance HashAlgorithm SHA512 where
|
||||
type HashBlockSize SHA512 = 128
|
||||
type HashDigestSize SHA512 = 64
|
||||
type HashInternalContextSize SHA512 = 256
|
||||
hashBlockSize _ = 128
|
||||
hashDigestSize _ = 64
|
||||
hashInternalContextSize _ = 256
|
||||
|
||||
@ -10,6 +10,8 @@
|
||||
--
|
||||
{-# LANGUAGE ForeignFunctionInterface #-}
|
||||
{-# LANGUAGE DeriveDataTypeable #-}
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
module Crypto.Hash.SHA512t
|
||||
( SHA512t_224 (..), SHA512t_256 (..)
|
||||
) where
|
||||
@ -26,6 +28,9 @@ data SHA512t_224 = SHA512t_224
|
||||
deriving (Show,Data,Typeable)
|
||||
|
||||
instance HashAlgorithm SHA512t_224 where
|
||||
type HashBlockSize SHA512t_224 = 128
|
||||
type HashDigestSize SHA512t_224 = 28
|
||||
type HashInternalContextSize SHA512t_224 = 256
|
||||
hashBlockSize _ = 128
|
||||
hashDigestSize _ = 28
|
||||
hashInternalContextSize _ = 256
|
||||
@ -38,6 +43,9 @@ data SHA512t_256 = SHA512t_256
|
||||
deriving (Show,Data,Typeable)
|
||||
|
||||
instance HashAlgorithm SHA512t_256 where
|
||||
type HashBlockSize SHA512t_256 = 128
|
||||
type HashDigestSize SHA512t_256 = 32
|
||||
type HashInternalContextSize SHA512t_256 = 256
|
||||
hashBlockSize _ = 128
|
||||
hashDigestSize _ = 32
|
||||
hashInternalContextSize _ = 256
|
||||
|
||||
@ -41,6 +41,9 @@ data SHAKE128 (bitlen :: Nat) = SHAKE128
|
||||
deriving (Show, Typeable)
|
||||
|
||||
instance (IsDivisibleBy8 bitLen, KnownNat bitLen) => HashAlgorithm (SHAKE128 bitLen) where
|
||||
type HashBlockSize (SHAKE128 bitlen) = 168
|
||||
type HashDigestSize (SHAKE128 bitlen) = Div8 bitlen
|
||||
type HashInternalContextSize (SHAKE128 bitlen) = 376
|
||||
hashBlockSize _ = 168
|
||||
hashDigestSize _ = byteLen (Proxy :: Proxy bitLen)
|
||||
hashInternalContextSize _ = 376
|
||||
@ -59,6 +62,9 @@ data SHAKE256 (bitlen :: Nat) = SHAKE256
|
||||
deriving (Show, Typeable)
|
||||
|
||||
instance (IsDivisibleBy8 bitLen, KnownNat bitLen) => HashAlgorithm (SHAKE256 bitLen) where
|
||||
type HashBlockSize (SHAKE256 bitlen) = 136
|
||||
type HashDigestSize (SHAKE256 bitlen) = Div8 bitlen
|
||||
type HashInternalContextSize (SHAKE256 bitlen) = 344
|
||||
hashBlockSize _ = 136
|
||||
hashDigestSize _ = byteLen (Proxy :: Proxy bitLen)
|
||||
hashInternalContextSize _ = 344
|
||||
|
||||
@ -10,6 +10,8 @@
|
||||
--
|
||||
{-# LANGUAGE ForeignFunctionInterface #-}
|
||||
{-# LANGUAGE DeriveDataTypeable #-}
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
module Crypto.Hash.Skein256
|
||||
( Skein256_224 (..), Skein256_256 (..)
|
||||
) where
|
||||
@ -26,6 +28,9 @@ data Skein256_224 = Skein256_224
|
||||
deriving (Show,Data,Typeable)
|
||||
|
||||
instance HashAlgorithm Skein256_224 where
|
||||
type HashBlockSize Skein256_224 = 32
|
||||
type HashDigestSize Skein256_224 = 28
|
||||
type HashInternalContextSize Skein256_224 = 96
|
||||
hashBlockSize _ = 32
|
||||
hashDigestSize _ = 28
|
||||
hashInternalContextSize _ = 96
|
||||
@ -38,6 +43,9 @@ data Skein256_256 = Skein256_256
|
||||
deriving (Show,Data,Typeable)
|
||||
|
||||
instance HashAlgorithm Skein256_256 where
|
||||
type HashBlockSize Skein256_256 = 32
|
||||
type HashDigestSize Skein256_256 = 32
|
||||
type HashInternalContextSize Skein256_256 = 96
|
||||
hashBlockSize _ = 32
|
||||
hashDigestSize _ = 32
|
||||
hashInternalContextSize _ = 96
|
||||
|
||||
@ -10,6 +10,8 @@
|
||||
--
|
||||
{-# LANGUAGE ForeignFunctionInterface #-}
|
||||
{-# LANGUAGE DeriveDataTypeable #-}
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
module Crypto.Hash.Skein512
|
||||
( Skein512_224 (..), Skein512_256 (..), Skein512_384 (..), Skein512_512 (..)
|
||||
) where
|
||||
@ -26,6 +28,9 @@ data Skein512_224 = Skein512_224
|
||||
deriving (Show,Data,Typeable)
|
||||
|
||||
instance HashAlgorithm Skein512_224 where
|
||||
type HashBlockSize Skein512_224 = 64
|
||||
type HashDigestSize Skein512_224 = 28
|
||||
type HashInternalContextSize Skein512_224 = 160
|
||||
hashBlockSize _ = 64
|
||||
hashDigestSize _ = 28
|
||||
hashInternalContextSize _ = 160
|
||||
@ -38,6 +43,9 @@ data Skein512_256 = Skein512_256
|
||||
deriving (Show,Data,Typeable)
|
||||
|
||||
instance HashAlgorithm Skein512_256 where
|
||||
type HashBlockSize Skein512_256 = 64
|
||||
type HashDigestSize Skein512_256 = 32
|
||||
type HashInternalContextSize Skein512_256 = 160
|
||||
hashBlockSize _ = 64
|
||||
hashDigestSize _ = 32
|
||||
hashInternalContextSize _ = 160
|
||||
@ -50,6 +58,9 @@ data Skein512_384 = Skein512_384
|
||||
deriving (Show,Data,Typeable)
|
||||
|
||||
instance HashAlgorithm Skein512_384 where
|
||||
type HashBlockSize Skein512_384 = 64
|
||||
type HashDigestSize Skein512_384 = 48
|
||||
type HashInternalContextSize Skein512_384 = 160
|
||||
hashBlockSize _ = 64
|
||||
hashDigestSize _ = 48
|
||||
hashInternalContextSize _ = 160
|
||||
@ -62,6 +73,9 @@ data Skein512_512 = Skein512_512
|
||||
deriving (Show,Data,Typeable)
|
||||
|
||||
instance HashAlgorithm Skein512_512 where
|
||||
type HashBlockSize Skein512_512 = 64
|
||||
type HashDigestSize Skein512_512 = 64
|
||||
type HashInternalContextSize Skein512_512 = 160
|
||||
hashBlockSize _ = 64
|
||||
hashDigestSize _ = 64
|
||||
hashInternalContextSize _ = 160
|
||||
|
||||
@ -10,6 +10,8 @@
|
||||
--
|
||||
{-# LANGUAGE ForeignFunctionInterface #-}
|
||||
{-# LANGUAGE DeriveDataTypeable #-}
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
module Crypto.Hash.Tiger ( Tiger (..) ) where
|
||||
|
||||
import Crypto.Hash.Types
|
||||
@ -23,6 +25,9 @@ data Tiger = Tiger
|
||||
deriving (Show,Data,Typeable)
|
||||
|
||||
instance HashAlgorithm Tiger where
|
||||
type HashBlockSize Tiger = 64
|
||||
type HashDigestSize Tiger = 24
|
||||
type HashInternalContextSize Tiger = 96
|
||||
hashBlockSize _ = 64
|
||||
hashDigestSize _ = 24
|
||||
hashInternalContextSize _ = 96
|
||||
|
||||
@ -8,6 +8,8 @@
|
||||
-- Crypto hash types definitions
|
||||
--
|
||||
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
module Crypto.Hash.Types
|
||||
( HashAlgorithm(..)
|
||||
, Context(..)
|
||||
@ -20,6 +22,7 @@ import qualified Crypto.Internal.ByteArray as B
|
||||
import Foreign.Ptr (Ptr)
|
||||
import qualified Foundation.Array as F
|
||||
import qualified Foundation as F
|
||||
import GHC.TypeLits (Nat)
|
||||
|
||||
-- | Class representing hashing algorithms.
|
||||
--
|
||||
@ -27,6 +30,13 @@ import qualified Foundation as F
|
||||
-- and lowlevel. the Hash module takes care of
|
||||
-- hidding the mutable interface properly.
|
||||
class HashAlgorithm a where
|
||||
-- | Associated type for the block size of the hash algorithm
|
||||
type HashBlockSize a :: Nat
|
||||
-- | Associated type for the digest size of the hash algorithm
|
||||
type HashDigestSize a :: Nat
|
||||
-- | Associated type for the internal context size of the hash algorithm
|
||||
type HashInternalContextSize a :: Nat
|
||||
|
||||
-- | Get the block size of a hash algorithm
|
||||
hashBlockSize :: a -> Int
|
||||
-- | Get the digest size of a hash algorithm
|
||||
|
||||
@ -10,6 +10,8 @@
|
||||
--
|
||||
{-# LANGUAGE ForeignFunctionInterface #-}
|
||||
{-# LANGUAGE DeriveDataTypeable #-}
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
module Crypto.Hash.Whirlpool ( Whirlpool (..) ) where
|
||||
|
||||
import Crypto.Hash.Types
|
||||
@ -23,6 +25,9 @@ data Whirlpool = Whirlpool
|
||||
deriving (Show,Data,Typeable)
|
||||
|
||||
instance HashAlgorithm Whirlpool where
|
||||
type HashBlockSize Whirlpool = 64
|
||||
type HashDigestSize Whirlpool = 64
|
||||
type HashInternalContextSize Whirlpool = 168
|
||||
hashBlockSize _ = 64
|
||||
hashDigestSize _ = 64
|
||||
hashInternalContextSize _ = 168
|
||||
|
||||
@ -9,6 +9,7 @@ module Crypto.Internal.Nat
|
||||
, type IsAtMost, type IsAtLeast
|
||||
, byteLen
|
||||
, integralNatVal
|
||||
, type Div8
|
||||
) where
|
||||
|
||||
import GHC.TypeLits
|
||||
@ -49,6 +50,42 @@ type family IsGE (bitlen :: Nat) (n :: Nat) (c :: Bool) where
|
||||
--
|
||||
type IsAtLeast (bitlen :: Nat) (n :: Nat) = IsGE bitlen n (n <=? bitlen) ~ 'True
|
||||
|
||||
type family Div8 (bitLen :: Nat) where
|
||||
Div8 0 = 0
|
||||
Div8 1 = 0
|
||||
Div8 2 = 0
|
||||
Div8 3 = 0
|
||||
Div8 4 = 0
|
||||
Div8 5 = 0
|
||||
Div8 6 = 0
|
||||
Div8 7 = 0
|
||||
Div8 8 = 1
|
||||
Div8 9 = 1
|
||||
Div8 10 = 1
|
||||
Div8 11 = 1
|
||||
Div8 12 = 1
|
||||
Div8 13 = 1
|
||||
Div8 14 = 1
|
||||
Div8 15 = 1
|
||||
Div8 16 = 2
|
||||
Div8 17 = 2
|
||||
Div8 18 = 2
|
||||
Div8 19 = 2
|
||||
Div8 20 = 2
|
||||
Div8 21 = 2
|
||||
Div8 22 = 2
|
||||
Div8 23 = 2
|
||||
Div8 24 = 3
|
||||
Div8 25 = 3
|
||||
Div8 26 = 3
|
||||
Div8 27 = 3
|
||||
Div8 28 = 3
|
||||
Div8 29 = 3
|
||||
Div8 30 = 3
|
||||
Div8 31 = 3
|
||||
Div8 32 = 4
|
||||
Div8 n = 4 + Div8 (n - 32)
|
||||
|
||||
type family IsDiv8 (bitLen :: Nat) (n :: Nat) where
|
||||
IsDiv8 bitLen 0 = 'True
|
||||
#if MIN_VERSION_base(4,9,0)
|
||||
|
||||
@ -10,6 +10,8 @@
|
||||
--
|
||||
{-# LANGUAGE ForeignFunctionInterface #-}
|
||||
{-# LANGUAGE DeriveDataTypeable #-}
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
module Crypto.Hash.%%MODULENAME%%
|
||||
( %{CUSTOMIZABLE%}%%COMMA%% %%MODULENAME%%_%%CUSTOM_BITSIZE%% (..)%{CUSTOMIZABLE%}
|
||||
) where
|
||||
@ -26,6 +28,9 @@ data %%MODULENAME%%_%%CUSTOM_BITSIZE%% = %%MODULENAME%%_%%CUSTOM_BITSIZE%%
|
||||
deriving (Show,Data,Typeable)
|
||||
|
||||
instance HashAlgorithm %%MODULENAME%%_%%CUSTOM_BITSIZE%% where
|
||||
type HashBlockSize %%MODULENAME%%_%%CUSTOM_BITSIZE%% = %%CUSTOM_BLOCK_SIZE_BYTES%%
|
||||
type HashDigestSize %%MODULENAME%%_%%CUSTOM_BITSIZE%% = %%CUSTOM_DIGEST_SIZE_BYTES%%
|
||||
type HashInternalContextSize %%MODULENAME%%_%%CUSTOM_BITSIZE%% = %%CUSTOM_CTX_SIZE_BYTES%%
|
||||
hashBlockSize _ = %%CUSTOM_BLOCK_SIZE_BYTES%%
|
||||
hashDigestSize _ = %%CUSTOM_DIGEST_SIZE_BYTES%%
|
||||
hashInternalContextSize _ = %%CUSTOM_CTX_SIZE_BYTES%%
|
||||
|
||||
@ -10,6 +10,8 @@
|
||||
--
|
||||
{-# LANGUAGE ForeignFunctionInterface #-}
|
||||
{-# LANGUAGE DeriveDataTypeable #-}
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
module Crypto.Hash.%%MODULENAME%% ( %%MODULENAME%% (..) ) where
|
||||
|
||||
import Crypto.Hash.Types
|
||||
@ -23,6 +25,9 @@ data %%MODULENAME%% = %%MODULENAME%%
|
||||
deriving (Show,Data,Typeable)
|
||||
|
||||
instance HashAlgorithm %%MODULENAME%% where
|
||||
type HashBlockSize %%MODULENAME%% = %%BLOCK_SIZE_BYTES%%
|
||||
type HashDigestSize %%MODULENAME%% = %%DIGEST_SIZE_BYTES%%
|
||||
type HashInternalContextSize %%MODULENAME%% = %%CTX_SIZE_BYTES%%
|
||||
hashBlockSize _ = %%BLOCK_SIZE_BYTES%%
|
||||
hashDigestSize _ = %%DIGEST_SIZE_BYTES%%
|
||||
hashInternalContextSize _ = %%CTX_SIZE_BYTES%%
|
||||
|
||||
Loading…
Reference in New Issue
Block a user