Skip to main content
Definition Website Computer and Technology

Message Authentication Code

Subject: Computer and Technology noun /ˈmɛs.ɪdʒ ɔːˌθɛn.tɪˈkeɪ.ʃən koʊd/ 1 definition

  1. Definition (noun)

    Entry #194 · Updated

    A Message Authentication Code (MAC) is a fixed-length cryptographic tag derived from a message and a symmetric secret key to verify that data has not been altered in transit and originated from an authorized holder of that key. A sender computes the tag using a keyed MAC algorithm and transmits it alongside the payload, enabling any recipient sharing the same key to recompute the value and check for an exact match in constant time. Unlike unkeyed checksums or cryptographic hashes—which only detect accidental corruption unless protected separately—a MAC prevents intentional forgery by attackers without the key, though its symmetric trust model means it cannot provide third-party non-repudiation like an asymmetric digital signature.

    Common Types

    • HMAC (Hash-based MAC): Combines a cryptographic hash function (such as SHA-256) with inner and outer key padding to prevent length-extension attacks, making it a standard choice in TLS, SSH, and API request signing.

    • CMAC (Cipher-based MAC): Computes a tag using a symmetric block cipher (typically AES) with derived final-block subkeys to eliminate variable-length CBC-MAC forgery risks, often used in embedded systems and hardware-accelerated paths.

    • Universal-Hash MAC (GMAC and Poly1305): Evaluates a fast polynomial hash over the message and masks the result with a single-use cipher output to deliver high-throughput, constant-time authentication in modern AEAD suites.

    • KMAC (Keccak MAC): Uses the SHA-3 extendable-output sponge construction (cSHAKE) to produce variable-length authentication tags directly, avoiding HMAC's two-pass wrapper because sponge functions inherently resist length-extension attacks.

    Example

    When a payment gateway dispatches an order-settled webhook, it computes an HMAC-SHA256 tag over the request timestamp and JSON payload using a shared secret key and sends the digest in an X-Signature HTTP header. The merchant's API server recomputes the MAC with its copy of the secret and verifies it using a constant-time comparison, rejecting forged requests or altered payloads before updating the database.