[Poly1305] Add a way to create AuthTag from ByteArray.
This commit is contained in:
parent
fee3b31ee1
commit
d47ae454d5
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user