From 8b235612bee288113ba8b3552339549952061980 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Ch=C3=A9ron?= Date: Sun, 7 Apr 2019 11:38:16 +0200 Subject: [PATCH] Merge cshakeInit with first cshakeUpdate --- Crypto/MAC/KMAC.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Crypto/MAC/KMAC.hs b/Crypto/MAC/KMAC.hs index 2bfe2a2..e48d26a 100644 --- a/Crypto/MAC/KMAC.hs +++ b/Crypto/MAC/KMAC.hs @@ -38,11 +38,12 @@ import Data.Memory.PtrMethods (memSet) -- cSHAKE -cshakeInit :: forall a name string . (HashSHAKE a, ByteArrayAccess name, ByteArrayAccess string) - => name -> string -> H.Context a -cshakeInit n s = H.Context $ B.allocAndFreeze c $ \(ptr :: Ptr (H.Context a)) -> do +cshakeInit :: forall a name string prefix . (HashSHAKE a, ByteArrayAccess name, ByteArrayAccess string, ByteArrayAccess prefix) + => name -> string -> prefix -> H.Context a +cshakeInit n s p = H.Context $ B.allocAndFreeze c $ \(ptr :: Ptr (H.Context a)) -> do hashInternalInit ptr B.withByteArray b $ \d -> hashInternalUpdate ptr d (fromIntegral $ B.length b) + B.withByteArray p $ \d -> hashInternalUpdate ptr d (fromIntegral $ B.length p) where c = hashInternalContextSize (undefined :: a) w = hashBlockSize (undefined :: a) @@ -91,7 +92,7 @@ newtype Context a = Context (H.Context a) -- string and key. initialize :: forall a string key . (HashSHAKE a, ByteArrayAccess string, ByteArrayAccess key) => string -> key -> Context a -initialize str key = Context $ cshakeUpdate (cshakeInit n str) p +initialize str key = Context $ cshakeInit n str p where n = B.pack [75,77,65,67] :: B.Bytes -- "KMAC" w = hashBlockSize (undefined :: a)