[Poly1305] Add a way to create AuthTag from ByteArray.

This commit is contained in:
Vincent Hanquez 2015-11-05 15:02:50 +00:00
parent fee3b31ee1
commit d47ae454d5
2 changed files with 7 additions and 1 deletions

View File

@ -36,6 +36,7 @@ data CryptoError =
| CryptoError_SharedSecretSizeInvalid | CryptoError_SharedSecretSizeInvalid
-- Message authentification error -- Message authentification error
| CryptoError_MacKeyInvalid | CryptoError_MacKeyInvalid
| CryptoError_AuthenticationTagSizeInvalid
deriving (Show,Eq,Enum,Data,Typeable) deriving (Show,Eq,Enum,Data,Typeable)
instance E.Exception CryptoError instance E.Exception CryptoError

View File

@ -14,7 +14,7 @@ module Crypto.MAC.Poly1305
( Ctx ( Ctx
, State , State
, Auth(..) , Auth(..)
, authTag
-- * Incremental MAC Functions -- * Incremental MAC Functions
, initialize -- :: State , initialize -- :: State
, update -- :: State -> ByteString -> State , update -- :: State -> ByteString -> State
@ -44,6 +44,11 @@ type Ctx = State
newtype Auth = Auth Bytes newtype Auth = Auth Bytes
deriving (ByteArrayAccess,NFData) 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 instance Eq Auth where
(Auth a1) == (Auth a2) = B.constEq a1 a2 (Auth a1) == (Auth a2) = B.constEq a1 a2