Skip to content
Vol. 1 · Ed. 2026
CyberGlossary
Entry № 750

Message Authentication Code (MAC)

Reviewed byCybersecurity entrepreneur & security researcher

What is Message Authentication Code (MAC)?

Message Authentication Code (MAC)A short symmetric-key tag that authenticates a message and detects tampering, computed and verified with the same shared secret.


A Message Authentication Code (MAC) is a fixed-length tag computed over a message using a symmetric secret key, such that verification requires the same key. It provides integrity and authenticity but not non-repudiation, because both parties hold the key. Common constructions include HMAC (hash-based, RFC 2104), CMAC (CBC-MAC, NIST SP 800-38B), GMAC (used in GCM), Poly1305 (paired with ChaCha20 in ChaCha20-Poly1305, RFC 8439) and KMAC (built on Keccak/SHA-3, NIST SP 800-185).

The reason HMAC exists rather than a naive MAC = H(key ‖ message) is that Merkle–Damgård hashes such as MD5, SHA-1 and SHA-256 are vulnerable to length-extension attacks: an attacker who knows a valid tag can append data and compute a valid tag for the longer message without the key. HMAC's nested H(key ⊕ opad ‖ H(key ⊕ ipad ‖ msg)) structure defeats this and has a formal security proof.

MACs must be verified in constant time — comparing tags byte-by-byte with early return leaks their length via timing, which enabled the 2009 forgery against Keyczar. They underpin TLS record authentication, IPsec AH, JWT HS256, API request signing and every AEAD mode. A MAC over ciphertext (encrypt-then-MAC) is preferred over MAC-then-encrypt, which contributed to padding-oracle attacks like Lucky Thirteen.

flowchart LR
  subgraph Sender
    M1[Message] --> T1["MAC(key, message)"]
    K1[Shared secret key] --> T1
    T1 --> S[Send message + tag]
  end
  subgraph Receiver
    S --> R["Recompute MAC(key, message)"]
    K2[Shared secret key] --> R
    R --> C{"Constant-time<br/>compare with sent tag"}
    C -->|Equal| OK[Accept: authentic & intact]
    C -->|Differ| NO[Reject: forged or altered]
  end

Examples

  1. 01

    HMAC-SHA-256 is used to authenticate AWS Signature Version 4 requests.

  2. 02

    Poly1305 authenticates ciphertext in the ChaCha20-Poly1305 AEAD used by TLS 1.3.

Frequently asked questions

What is Message Authentication Code (MAC)?

A short symmetric-key tag that authenticates a message and detects tampering, computed and verified with the same shared secret. It belongs to the Cryptography category of cybersecurity.

What does Message Authentication Code (MAC) mean?

A short symmetric-key tag that authenticates a message and detects tampering, computed and verified with the same shared secret.

How do you defend against Message Authentication Code (MAC)?

Defences for Message Authentication Code (MAC) typically combine technical controls and operational practices, as detailed in the full definition above.

What are other names for Message Authentication Code (MAC)?

Common alternative names include: MAC, Cryptographic checksum.

Related terms