From cd552ae5f6c91d0cb41968abdf233fd90f6936a5 Mon Sep 17 00:00:00 2001 From: Nicolas DI PRIMA Date: Mon, 13 Mar 2017 00:22:53 +0000 Subject: [PATCH 1/5] move Nat specific to Cryptonite's insternal module --- Crypto/Hash/SHAKE.hs | 5 +---- Crypto/Internal/Nat.hs | 8 ++++++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Crypto/Hash/SHAKE.hs b/Crypto/Hash/SHAKE.hs index 2e4f3e4..7c9f8ef 100644 --- a/Crypto/Hash/SHAKE.hs +++ b/Crypto/Hash/SHAKE.hs @@ -73,10 +73,7 @@ shakeFinalizeOutput :: (IsDivisibleBy8 bitLen, KnownNat bitLen) -> IO () shakeFinalizeOutput d ctx dig = do c_sha3_finalize_shake ctx - c_sha3_output ctx dig (fromInteger (natVal d `div` 8)) - -byteLen :: (KnownNat bitlen, IsDivisibleBy8 bitlen, Num a) => proxy bitlen -> a -byteLen d = fromInteger (natVal d `div` 8) + c_sha3_output ctx dig (byteLen d) foreign import ccall unsafe "cryptonite_sha3_init" c_sha3_init :: Ptr (Context a) -> Word32 -> IO () diff --git a/Crypto/Internal/Nat.hs b/Crypto/Internal/Nat.hs index ed3a0c0..0870a47 100644 --- a/Crypto/Internal/Nat.hs +++ b/Crypto/Internal/Nat.hs @@ -6,10 +6,18 @@ {-# LANGUAGE UndecidableInstances #-} module Crypto.Internal.Nat ( type IsDivisibleBy8 + , byteLen + , integralNatVal ) where import GHC.TypeLits +byteLen :: (KnownNat bitlen, IsDivisibleBy8 bitlen, Num a) => proxy bitlen -> a +byteLen d = fromInteger (natVal d `div` 8) + +integralNatVal :: (KnownNat bitlen, Num a) => proxy bitlen -> a +integralNatVal = fromInteger . natVal + type family IsDiv8 (bitLen :: Nat) (n :: Nat) where IsDiv8 bitLen 0 = 'True #if MIN_VERSION_base(4,9,0) From c0c33c525448151f0fba4d6ff671212c3d823c92 Mon Sep 17 00:00:00 2001 From: Nicolas DI PRIMA Date: Mon, 13 Mar 2017 00:24:17 +0000 Subject: [PATCH 2/5] Use Nat for the Blake2's digest sizes --- Crypto/Hash/Algorithms.hs | 3 + Crypto/Hash/Blake2.hs | 151 ++++++++++++++++++++++++++++++++++++++ cryptonite.cabal | 1 + 3 files changed, 155 insertions(+) create mode 100644 Crypto/Hash/Blake2.hs diff --git a/Crypto/Hash/Algorithms.hs b/Crypto/Hash/Algorithms.hs index 45ee759..fdf52f4 100644 --- a/Crypto/Hash/Algorithms.hs +++ b/Crypto/Hash/Algorithms.hs @@ -45,6 +45,8 @@ module Crypto.Hash.Algorithms #if MIN_VERSION_base(4,7,0) , SHAKE128(..) , SHAKE256(..) + , Blake2b(..), Blake2bp(..) + , Blake2s(..), Blake2sp(..) #endif , Skein256_224(..) , Skein256_256(..) @@ -78,4 +80,5 @@ import Crypto.Hash.Skein512 import Crypto.Hash.Whirlpool #if MIN_VERSION_base(4,7,0) import Crypto.Hash.SHAKE +import Crypto.Hash.Blake2 #endif diff --git a/Crypto/Hash/Blake2.hs b/Crypto/Hash/Blake2.hs new file mode 100644 index 0000000..b957fa3 --- /dev/null +++ b/Crypto/Hash/Blake2.hs @@ -0,0 +1,151 @@ +-- | +-- Module : Crypto.Hash.Blake2 +-- License : BSD-style +-- Maintainer : Nicolas Di Prima +-- Stability : experimental +-- Portability : unknown +-- +-- module containing the binding functions to work with the +-- Blake2 +-- +-- Implementation based from [RFC7693](https://tools.ietf.org/html/rfc7693) +-- +-- Please consider the following when chosing a hash: +-- +-- Algorithm | Target | Collision | Digest Size | +-- Identifier | Arch | Security | in bytes | +-- ---------------+--------+-----------+-------------+ +-- id-blake2b160 | 64-bit | 2**80 | 20 | +-- id-blake2b256 | 64-bit | 2**128 | 32 | +-- id-blake2b384 | 64-bit | 2**192 | 48 | +-- id-blake2b512 | 64-bit | 2**256 | 64 | +-- ---------------+--------+-----------+-------------+ +-- id-blake2s128 | 32-bit | 2**64 | 16 | +-- id-blake2s160 | 32-bit | 2**80 | 20 | +-- id-blake2s224 | 32-bit | 2**112 | 28 | +-- id-blake2s256 | 32-bit | 2**128 | 32 | +-- ---------------+--------+-----------+-------------+ +-- +{-# LANGUAGE ForeignFunctionInterface #-} +{-# LANGUAGE DeriveDataTypeable #-} +{-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE KindSignatures #-} +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE TypeFamilies #-} +module Crypto.Hash.Blake2 + ( Blake2s(..) + , Blake2sp(..) + , Blake2b(..) + , Blake2bp(..) + ) where + +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 Crypto.Internal.Nat + +-- | Fast and secure alternative to SHA1 and HMAC-SHA1 +-- +-- It is espacially known to target 32bits architectures. +-- +-- known supported digest sizes: +-- +-- * Blake2s 160 +-- * Blake2s 224 +-- * Blake2s 256 +-- +data Blake2s (bitlen :: Nat) = Blake2s + deriving (Show, Typeable) + +instance (IsDivisibleBy8 bitlen, KnownNat bitlen) + => HashAlgorithm (Blake2s bitlen) + where + hashBlockSize _ = 64 + hashDigestSize _ = byteLen (Proxy :: Proxy bitlen) + hashInternalContextSize _ = 185 + hashInternalInit p = c_blake2s_init p (integralNatVal (Proxy :: Proxy bitlen)) + hashInternalUpdate = c_blake2s_update + hashInternalFinalize p = c_blake2s_finalize p (integralNatVal (Proxy :: Proxy bitlen)) + +foreign import ccall unsafe "cryptonite_blake2s_init" + c_blake2s_init :: Ptr (Context a) -> Word32 -> IO () +foreign import ccall "cryptonite_blake2s_update" + c_blake2s_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO () +foreign import ccall unsafe "cryptonite_blake2s_finalize" + c_blake2s_finalize :: Ptr (Context a) -> Word32 -> Ptr (Digest a) -> IO () + +-- | Fast cryptographic hash. +-- +-- It is especially known to target 64bits architectures. +-- +-- Known supported digest sizes: +-- +-- * Blake2b 160 +-- * Blake2b 224 +-- * Blake2b 256 +-- * Blake2b 384 +-- * Blake2b 512 +-- +data Blake2b (bitlen :: Nat) = Blake2b + deriving (Show, Typeable) + +instance (IsDivisibleBy8 bitlen, KnownNat bitlen) + => HashAlgorithm (Blake2b bitlen) + where + hashBlockSize _ = 128 + hashDigestSize _ = byteLen (Proxy :: Proxy bitlen) + hashInternalContextSize _ = 361 + hashInternalInit p = c_blake2b_init p (integralNatVal (Proxy :: Proxy bitlen)) + hashInternalUpdate = c_blake2b_update + hashInternalFinalize p = c_blake2b_finalize p (integralNatVal (Proxy :: Proxy bitlen)) + +foreign import ccall unsafe "cryptonite_blake2b_init" + c_blake2b_init :: Ptr (Context a) -> Word32 -> IO () +foreign import ccall "cryptonite_blake2b_update" + c_blake2b_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO () +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) + +instance (IsDivisibleBy8 bitlen, KnownNat bitlen) + => HashAlgorithm (Blake2sp bitlen) + where + hashBlockSize _ = 64 + hashDigestSize _ = byteLen (Proxy :: Proxy bitlen) + hashInternalContextSize _ = 2185 + hashInternalInit p = c_blake2sp_init p (integralNatVal (Proxy :: Proxy bitlen)) + hashInternalUpdate = c_blake2sp_update + hashInternalFinalize p = c_blake2sp_finalize p (integralNatVal (Proxy :: Proxy bitlen)) + +foreign import ccall unsafe "cryptonite_blake2sp_init" + c_blake2sp_init :: Ptr (Context a) -> Word32 -> IO () +foreign import ccall "cryptonite_blake2sp_update" + c_blake2sp_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO () +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) + +instance (IsDivisibleBy8 bitlen, KnownNat bitlen) + => HashAlgorithm (Blake2bp bitlen) + where + hashBlockSize _ = 128 + hashDigestSize _ = byteLen (Proxy :: Proxy bitlen) + hashInternalContextSize _ = 2325 + hashInternalInit p = c_blake2bp_init p (integralNatVal (Proxy :: Proxy bitlen)) + hashInternalUpdate = c_blake2bp_update + hashInternalFinalize p = c_blake2bp_finalize p (integralNatVal (Proxy :: Proxy bitlen)) + + +foreign import ccall unsafe "cryptonite_blake2bp_init" + c_blake2bp_init :: Ptr (Context a) -> Word32 -> IO () +foreign import ccall "cryptonite_blake2bp_update" + c_blake2bp_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO () +foreign import ccall unsafe "cryptonite_blake2bp_finalize" + c_blake2bp_finalize :: Ptr (Context a) -> Word32 -> Ptr (Digest a) -> IO () diff --git a/cryptonite.cabal b/cryptonite.cabal index 9569a18..f074eb3 100644 --- a/cryptonite.cabal +++ b/cryptonite.cabal @@ -213,6 +213,7 @@ Library Crypto.Internal.WordArray if impl(ghc >= 7.8) Other-modules: Crypto.Hash.SHAKE + Crypto.Hash.Blake2 Crypto.Internal.Nat Build-depends: base >= 4.3 && < 5 , bytestring From 653e67d221787a461daa681c60981a4a39386d6c Mon Sep 17 00:00:00 2001 From: Nicolas DI PRIMA Date: Mon, 13 Mar 2017 00:25:04 +0000 Subject: [PATCH 3/5] add tests for the new digest sizes --- tests/Hash.hs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/Hash.hs b/tests/Hash.hs index 0c00392..abbdb6c 100644 --- a/tests/Hash.hs +++ b/tests/Hash.hs @@ -183,6 +183,38 @@ expected = [ "46b9dd2b0ba88d13233b3feb743eeb243fcd52ea62b81b82b50c27646ed5762fd75dc4ddd8c0f200cb05019d67b592f6fc821c49479ab48640292eacb3b7c4be141e96616fb13957692cc7edd0b45ae3dc07223c8e92937bef84bc0eab862853349ec75546f58fb7c2775c38462c5010d846c185c15111e595522a6bcd16cf86f3d122109e3b1fdd943b6aec468a2d621a7c06c6a957c62b54dafc3be87567d677231395f6147293b68ceab7a9e0c58d864e8efde4e1b9a46cbe854713672f5caaae314ed9083dab4b099f8e300f01b8650f1f4b1d8fcf3f3cb53fb8e9eb2ea203bdc970f50ae55428a91f7f53ac266b28419c3778a15fd248d339ede785fb7f5a1aaa96d313eacc890936c173cdcd0fab882c45755feb3aed96d477ff96390bf9a66d1368b208e21f7c10d04a3dbd4e360633e5db4b602601c14cea737db3dcf722632cc77851cbdde2aaf0a33a07b373445df490cc8fc1e4160ff118378f11f0477de055a81a9eda57a4a2cfb0c83929d310912f729ec6cfa36c6ac6a75837143045d791cc85eff5b21932f23861bcf23a52b5da67eaf7baae0f5fb1369db78f3ac45f8c4ac5671d85735cdddb09d2b1e34a1fc066ff4a162cb263d6541274ae2fcc865f618abe27c124cd8b074ccd516301b91875824d09958f341ef274bdab0bae316339894304e35877b0c28a9b1fd166c796b9cc258a064a8f57e27f2a", "2f671343d9b2e1604dc9dcf0753e5fe15c7c64a0d283cbbf722d411a0e36f6ca1d01d1369a23539cd80f7c054b6e5daf9c962cad5b8ed5bd11998b40d5734442bed798f6e5c915bd8bb07e0188d0a55c1290074f1c287af06352299184492cbdec9acba737ee292e5adaa445547355e72a03a3bac3aac770fe5d6b66600ff15d37d5b4789994ea2aeb097f550aa5e88e4d8ff0ba07b88c1c88573063f5d96df820abc2abd177ab037f351c375e553af917132cf2f563c79a619e1bb76e8e2266b0c5617d695f2c496a25f4073b6840c1833757ebb386f16757a8e16a21e9355e9b248f3b33be672da700266be99b8f8725e8ab06075f0219e655ebc188976364b7db139390d34a6ea67b4b223229183a94cf455ece91fdaf5b9c707fa4b40ec39816c1120c7aaaf47920977be900e6b9ca4b8940e192b927c475bd58e836f512ae3e52924e36ff8e9b1d0251047770a5e465905622b1f159be121ab93819c5e5c6dae299ac73bf1c4ed4a1e2c7fa3caa1039b05e94c9f993d04feb272b6e00bb0276939cf746c42936831fc8f2b4cb0cf94808ae0af405ce4bc67d1e7acfc6fd6590d3de91f795df5aaf57e2cee1845a303d0ea564be3f1299acdce67efe0d62cfc6d6829ff4ecc0a05153c24696c4d34c076453827e796f3062f94f62f4528b7cfc870f0dcd615b7c97b95da4b9be5830e8b3f66cce71e0f622c771994443e2", "fffcaac0606c0edb7bc0d15f033accb68538159016e5ae8470bf9ebea89fa6c9fcc3e027d94f7f967b7246346bd9f6b8084e45a057b976847c4db03bf383c834054866f6a8282a497368c46e1852fc09e20f22c45607a27c8b2a4798ebefada54f8d3795b9f07606b1cd6e41f90d765480ef5c0d5790659cf1d210adfd412378b92e1dd9bd7fd95a1a66677fc6baa0e3a53c9031c1fb59cbad9f5dc5881a3c8e25c80ecb1abf0971488ada1f533dcbf8d37031335378574b8d3fad61159c9fae28caa543b3072ce308d369be340e78c6edc664cc6dde9b2f0a4ad2e60ce9c8b1e5722b8d5b73d0962b74fb9ed86307a180f53933339f9d56d3b345c2a0e98fcf5de7754f3845f6be30089f0e142ad4602f18abdc750bda7c91c3f32872e66640db46045ab4c276b379f1b834c2cbb1bd8601305649ec6b3bf20618695136dee6541492d1d985ea1fb765fd7a559e810eba30f2f710233ae5a411b94ddcaa01a08f1c31320d111c0714422cd5e987c9a76fc865de34003ab12664081be8017d23d977f2bf4ed9e3ce09ea3d64bb4ae8ebfa9d0721f57841008c297e2f455a0441a2bd618ca379dbd239a21e410defb4001b1e11f87e36bf894c222f76f12ddcc3771bbb17d5c0dfd86d89a3e13e084f6dc1c4762bcd393c1757db7afb1434221569e7ddaaffd6318253ec3df8cf5f826b81896d6474ee06a2e30ccc8c6a96bdd5" ]) + , ("Blake2b 160", HashAlg (Blake2b :: Blake2b 160), [ + "3345524abf6bbe1809449224b5972c41790b6cf2", + "3c523ed102ab45a37d54f5610d5a983162fde84f", + "a3d365b5fba5d36fbb19c03b7fde496058969c5a" ]) + , ("Blake2b 224", HashAlg (Blake2b :: Blake2b 224), [ + "836cc68931c2e4e3e838602eca1902591d216837bafddfe6f0c8cb07", + "477c3985751dd4d1b8c93827ea5310b33bb02a26463a050dffd3e857", + "a4a1b6851be66891a3deff406c4d7556879ebf952407450755f90eb6" ]) + , ("Blake2b 256", HashAlg (Blake2b :: Blake2b 256), [ + "0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8", + "01718cec35cd3d796dd00020e0bfecb473ad23457d063b75eff29c0ffa2e58a9", + "036c13096926b3dfccfe3f233bd1b2f583b818b8b15c01be65af69238e900b2c" ]) + , ("Blake2b 384", HashAlg (Blake2b :: Blake2b 384), [ + "b32811423377f52d7862286ee1a72ee540524380fda1724a6f25d7978c6fd3244a6caf0498812673c5e05ef583825100", + "b7c81b228b6bd912930e8f0b5387989691c1cee1e65aade4da3b86a3c9f678fc8018f6ed9e2906720c8d2a3aeda9c03d", + "927a1f297873cbe887a93b2183c4e2eba53966ba92c6db8b87029a1d8c673471d09740676cced79c5016838973f630c3" ]) + , ("Blake2b 512", HashAlg (Blake2b :: Blake2b 512), [ + "786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce", + "a8add4bdddfd93e4877d2746e62817b116364a1fa7bc148d95090bc7333b3673f82401cf7aa2e4cb1ecd90296e3f14cb5413f8ed77be73045b13914cdcd6a918", + "af438eea5d8cdb209336a7e85bf58090dc21b49d823f89a7d064c119f127bd361af9c7d109edda0f0e91bdce078d1d86b8e6f25727c98f6d3bb6f50acb2dd376" ]) + , ("Blake2s 160", HashAlg (Blake2s :: Blake2s 160), [ + "354c9c33f735962418bdacb9479873429c34916f", + "5a604fec9713c369e84b0ed68daed7d7504ef240", + "759bef6d041bcbd861b8b51baaece6c8fffd0acf" ]) + , ("Blake2s 224", HashAlg (Blake2s :: Blake2s 224), [ + "1fa1291e65248b37b3433475b2a0dd63d54a11ecc4e3e034e7bc1ef4", + "e4e5cb6c7cae41982b397bf7b7d2d9d1949823ae78435326e8db4912", + "e220025fd46a9a635c3f7f60bb96a84c01019ac0817f5901e7eeaa2c" ]) + , ("Blake2s 256", HashAlg (Blake2s ::Blake2s 256), [ + "69217a3079908094e11121d042354a7c1f55b6482ca1a51e1b250dfd1ed0eef9", + "606beeec743ccbeff6cbcdf5d5302aa855c256c29b88c8ed331ea1a6bf3c8812", + "94662583a600a12dff357c0a6f1b514a710ef0f587a38e8d2e4d7f67e9c81667" ]) #endif ] From f0286281fbf3479f97024b08204cefb61161bff0 Mon Sep 17 00:00:00 2001 From: Nicolas DI PRIMA Date: Mon, 13 Mar 2017 18:52:24 +0000 Subject: [PATCH 4/5] add new constraints --- Crypto/Internal/Nat.hs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/Crypto/Internal/Nat.hs b/Crypto/Internal/Nat.hs index 0870a47..ac82003 100644 --- a/Crypto/Internal/Nat.hs +++ b/Crypto/Internal/Nat.hs @@ -6,6 +6,7 @@ {-# LANGUAGE UndecidableInstances #-} module Crypto.Internal.Nat ( type IsDivisibleBy8 + , type IsAtMost, type IsAtLeast , byteLen , integralNatVal ) where @@ -18,6 +19,36 @@ byteLen d = fromInteger (natVal d `div` 8) 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 +#if MIN_VERSION_base(4,9,0) + IsLE bitlen n 'False = TypeError + ( ('Text "bitlen " ':<>: 'ShowType bitlen ':<>: 'Text " is greater than " ':<>: 'ShowType n) + ':$$: ('Text "You have tried to use an invalid Digest size. Please, refer to the documentation.") + ) +#else + IsLE bitlen n 'False = 'False +#endif + +-- | ensure the given `bitlen` is lesser or equal to `n` +-- +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 +#if MIN_VERSION_base(4,9,0) + IsGE bitlen n 'False = TypeError + ( ('Text "bitlen " ':<>: 'ShowType bitlen ':<>: 'Text " is lesser than " ':<>: 'ShowType n) + ':$$: ('Text "You have tried to use an invalid Digest size. Please, refer to the documentation.") + ) +#else + IsGE bitlen n 'False = 'False +#endif + +-- | ensure the given `bitlen` is greater or equal to `n` +-- +type IsAtLeast (bitlen :: Nat) (n :: Nat) = IsGE bitlen n (n <=? bitlen) ~ 'True + type family IsDiv8 (bitLen :: Nat) (n :: Nat) where IsDiv8 bitLen 0 = 'True #if MIN_VERSION_base(4,9,0) From 8b6bd1ed5e30f2ce519569627d9152ff822d1d07 Mon Sep 17 00:00:00 2001 From: Nicolas DI PRIMA Date: Mon, 13 Mar 2017 18:53:07 +0000 Subject: [PATCH 5/5] check for at least one byte and at most 256 or 512 (blake2s or blake2b) --- Crypto/Hash/Blake2.hs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Crypto/Hash/Blake2.hs b/Crypto/Hash/Blake2.hs index b957fa3..d86a0d5 100644 --- a/Crypto/Hash/Blake2.hs +++ b/Crypto/Hash/Blake2.hs @@ -60,7 +60,7 @@ import Crypto.Internal.Nat data Blake2s (bitlen :: Nat) = Blake2s deriving (Show, Typeable) -instance (IsDivisibleBy8 bitlen, KnownNat bitlen) +instance (IsDivisibleBy8 bitlen, KnownNat bitlen, IsAtLeast bitlen 8, IsAtMost bitlen 256) => HashAlgorithm (Blake2s bitlen) where hashBlockSize _ = 64 @@ -92,7 +92,7 @@ foreign import ccall unsafe "cryptonite_blake2s_finalize" data Blake2b (bitlen :: Nat) = Blake2b deriving (Show, Typeable) -instance (IsDivisibleBy8 bitlen, KnownNat bitlen) +instance (IsDivisibleBy8 bitlen, KnownNat bitlen, IsAtLeast bitlen 8, IsAtMost bitlen 512) => HashAlgorithm (Blake2b bitlen) where hashBlockSize _ = 128 @@ -112,7 +112,7 @@ foreign import ccall unsafe "cryptonite_blake2b_finalize" data Blake2sp (bitlen :: Nat) = Blake2sp deriving (Show, Typeable) -instance (IsDivisibleBy8 bitlen, KnownNat bitlen) +instance (IsDivisibleBy8 bitlen, KnownNat bitlen, IsAtLeast bitlen 8, IsAtMost bitlen 256) => HashAlgorithm (Blake2sp bitlen) where hashBlockSize _ = 64 @@ -132,7 +132,7 @@ foreign import ccall unsafe "cryptonite_blake2sp_finalize" data Blake2bp (bitlen :: Nat) = Blake2bp deriving (Show, Typeable) -instance (IsDivisibleBy8 bitlen, KnownNat bitlen) +instance (IsDivisibleBy8 bitlen, KnownNat bitlen, IsAtLeast bitlen 8, IsAtMost bitlen 512) => HashAlgorithm (Blake2bp bitlen) where hashBlockSize _ = 128