From d47ae454d535aee32d7053eeca9b3df60a0ac9d0 Mon Sep 17 00:00:00 2001 From: Vincent Hanquez Date: Thu, 5 Nov 2015 15:02:50 +0000 Subject: [PATCH] [Poly1305] Add a way to create AuthTag from ByteArray. --- Crypto/Error/Types.hs | 1 + Crypto/MAC/Poly1305.hs | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Crypto/Error/Types.hs b/Crypto/Error/Types.hs index 3163675..79065ab 100644 --- a/Crypto/Error/Types.hs +++ b/Crypto/Error/Types.hs @@ -36,6 +36,7 @@ data CryptoError = | CryptoError_SharedSecretSizeInvalid -- Message authentification error | CryptoError_MacKeyInvalid + | CryptoError_AuthenticationTagSizeInvalid deriving (Show,Eq,Enum,Data,Typeable) instance E.Exception CryptoError diff --git a/Crypto/MAC/Poly1305.hs b/Crypto/MAC/Poly1305.hs index 0b2c4fd..f6863cc 100644 --- a/Crypto/MAC/Poly1305.hs +++ b/Crypto/MAC/Poly1305.hs @@ -14,7 +14,7 @@ module Crypto.MAC.Poly1305 ( Ctx , State , Auth(..) - + , authTag -- * Incremental MAC Functions , initialize -- :: State , update -- :: State -> ByteString -> State @@ -44,6 +44,11 @@ type Ctx = State newtype Auth = Auth Bytes deriving (ByteArrayAccess,NFData) +authTag :: ByteArrayAccess b => b -> CryptoFailable Auth +authTag b + | B.length b /= 32 = CryptoFailed $ CryptoError_AuthenticationTagSizeInvalid + | otherwise = CryptoPassed $ Auth $ B.convert b + instance Eq Auth where (Auth a1) == (Auth a2) = B.constEq a1 a2