move Nat specific to Cryptonite's insternal module

This commit is contained in:
Nicolas DI PRIMA 2017-03-13 00:22:53 +00:00
parent f9b593520f
commit cd552ae5f6
2 changed files with 9 additions and 4 deletions

View File

@ -73,10 +73,7 @@ shakeFinalizeOutput :: (IsDivisibleBy8 bitLen, KnownNat bitLen)
-> IO () -> IO ()
shakeFinalizeOutput d ctx dig = do shakeFinalizeOutput d ctx dig = do
c_sha3_finalize_shake ctx c_sha3_finalize_shake ctx
c_sha3_output ctx dig (fromInteger (natVal d `div` 8)) c_sha3_output ctx dig (byteLen d)
byteLen :: (KnownNat bitlen, IsDivisibleBy8 bitlen, Num a) => proxy bitlen -> a
byteLen d = fromInteger (natVal d `div` 8)
foreign import ccall unsafe "cryptonite_sha3_init" foreign import ccall unsafe "cryptonite_sha3_init"
c_sha3_init :: Ptr (Context a) -> Word32 -> IO () c_sha3_init :: Ptr (Context a) -> Word32 -> IO ()

View File

@ -6,10 +6,18 @@
{-# LANGUAGE UndecidableInstances #-} {-# LANGUAGE UndecidableInstances #-}
module Crypto.Internal.Nat module Crypto.Internal.Nat
( type IsDivisibleBy8 ( type IsDivisibleBy8
, byteLen
, integralNatVal
) where ) where
import GHC.TypeLits 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 type family IsDiv8 (bitLen :: Nat) (n :: Nat) where
IsDiv8 bitLen 0 = 'True IsDiv8 bitLen 0 = 'True
#if MIN_VERSION_base(4,9,0) #if MIN_VERSION_base(4,9,0)