Copyright | (c) Leo D 2023 |
---|---|
License | BSD-3-Clause |
Maintainer | leo@apotheca.io |
Stability | experimental |
Portability | POSIX |
Safe Haskell | None |
Language | Haskell2010 |
A Message Authentication Code algorithm computes a tag over a message utilizing a shared secret key. Thus a valid tag confirms the authenticity and integrity of the message. Only entities in possession of the shared secret key are able to verify the tag.
Note
When combining a MAC with unauthenticated encryption mode, prefer to first encrypt the message and then MAC the ciphertext. The alternative is to MAC the plaintext, which depending on exact usage can suffer serious security issues. For a detailed discussion of this issue see the paper “The Order of Encryption and Authentication for Protecting Communications” by Hugo Krawczyk
The Botan MAC computation is split into five stages.
- Instantiate the MAC algorithm.
- Set the secret key.
- Process IV.
- Process data.
- Finalize the MAC computation.
Synopsis
- data MAC
- macs :: [MAC]
- type MACKeySpec = KeySpec
- type MACKey = ByteString
- newMACKey :: MonadRandomIO m => MAC -> m MACKey
- newMACKeyMaybe :: MonadRandomIO m => Int -> MAC -> m (Maybe MACKey)
- type MACDigest = ByteString
- macName :: MAC -> ByteString
- macKeySpec :: MAC -> KeySpec
- macDigestLength :: MAC -> Int
- mac :: MAC -> MACKey -> ByteString -> Maybe MACDigest
- gmac :: MAC -> MACKey -> GMACNonce -> ByteString -> Maybe MACDigest
- macLazy :: MAC -> MACKey -> ByteString -> Maybe MACDigest
- data MutableMAC = MkMutableMAC {
- mutableMACType :: MAC
- mutableMACCtx :: MAC
- destroyMAC :: MonadIO m => MutableMAC -> m ()
- newMAC :: MonadIO m => MAC -> m MutableMAC
- getMACName :: MonadIO m => MutableMAC -> m MACName
- getMACKeySpec :: MonadIO m => MutableMAC -> m MACKeySpec
- getMACDigestLength :: MonadIO m => MutableMAC -> m Int
- setMACKey :: MonadIO m => MACKey -> MutableMAC -> m Bool
- type GMACNonce = ByteString
- setGMACNonce :: MonadIO m => GMACNonce -> MutableMAC -> m ()
- clearMAC :: MonadIO m => MutableMAC -> m ()
- updateMAC :: MonadIO m => MutableMAC -> ByteString -> m ()
- finalizeMAC :: MonadIO m => MutableMAC -> m MACDigest
- updateFinalizeMAC :: MonadIO m => MutableMAC -> ByteString -> m MACDigest
- updateFinalizeClearMAC :: MonadIO m => MutableMAC -> ByteString -> m MACDigest
- cmac :: BlockCipher -> MAC
- hmac :: CryptoHash -> MAC
- poly1305 :: MAC
- sipHash :: MAC
- x9_19_mac :: MAC
Message Authentication Codes
Usage
Idiomatic interface
Data type
CMAC BlockCipher | |
GMAC BlockCipher | CBC_MAC BlockCipher -- No longer supported (possibly due to security issues) |
HMAC CryptoHash | |
Poly1305 | KMAC_128 Int -- Output length | KMAC_256 Int -- Output length |
SipHash Int Int | |
X9_19_MAC |
Enumerations
Associated types
type MACKeySpec = KeySpec Source #
type MACKey = ByteString Source #
newMACKeyMaybe :: MonadRandomIO m => Int -> MAC -> m (Maybe MACKey) Source #
type MACDigest = ByteString Source #
Accessors
macName :: MAC -> ByteString Source #
macKeySpec :: MAC -> KeySpec Source #
macDigestLength :: MAC -> Int Source #
Idiomatic algorithm
Mutable interface
Tagged mutable context
data MutableMAC Source #
MkMutableMAC | |
|
Destructor
destroyMAC :: MonadIO m => MutableMAC -> m () Source #
Initializers
Accessors
getMACName :: MonadIO m => MutableMAC -> m MACName Source #
getMACKeySpec :: MonadIO m => MutableMAC -> m MACKeySpec Source #
getMACDigestLength :: MonadIO m => MutableMAC -> m Int Source #
GMAC-specific functions
type GMACNonce = ByteString Source #
setGMACNonce :: MonadIO m => GMACNonce -> MutableMAC -> m () Source #
Accessory functions
clearMAC :: MonadIO m => MutableMAC -> m () Source #
Mutable algorithm
updateMAC :: MonadIO m => MutableMAC -> ByteString -> m () Source #
finalizeMAC :: MonadIO m => MutableMAC -> m MACDigest Source #
updateFinalizeMAC :: MonadIO m => MutableMAC -> ByteString -> m MACDigest Source #
updateFinalizeClearMAC :: MonadIO m => MutableMAC -> ByteString -> m MACDigest Source #
Algorithm references
cmac :: BlockCipher -> MAC Source #
GMAC BlockCipher -- Requires a nonce "GMAC can accept initialization vectors of arbitrary length" | HMAC Hash -- Must be a (CS)Hash, and not a Checksum -- New in 3.2 -- | KMAC_128 Int -- Output length -- | KMAC_256 Int -- Output length | Poly1305 -- Requires a unique key per message (key r and nonce s have been combined) | SipHash Int Int -- Number of input and finalization rounds | X9_19_MAC
hmac :: CryptoHash -> MAC Source #