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)