[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
|
| 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
|
||||||
|
|||||||
@ -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
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user