From cd552ae5f6c91d0cb41968abdf233fd90f6936a5 Mon Sep 17 00:00:00 2001 From: Nicolas DI PRIMA Date: Mon, 13 Mar 2017 00:22:53 +0000 Subject: [PATCH] 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)