A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Message Authentication Codes (MACs)

Graduate Depth 97 in the knowledge graph ☐ I know this ☆ Set as goal
1topic build on this
515prerequisites beneath it
See this on the map →
Hash Functions and Collision ResistanceSymmetric Encryption and Block Ciphers→→Authenticated Encryption
mac hmac cbc-mac message-integrity unforgeability

Core Idea

A MAC is a keyed function that takes a secret key and a message and produces a short tag. The sender transmits (message, tag); the receiver recomputes the tag with the shared key and checks for a match. Security requires existential unforgeability under chosen-message attack (EUF-CMA): an adversary who can obtain tags on messages of their choice still cannot forge a valid tag on any new message. HMAC (hash-based) and CBC-MAC (block-cipher-based) are the main constructions. MACs provide integrity and authenticity but not confidentiality — the message is sent in the clear alongside the tag.

Explainer

Encryption protects confidentiality — it hides what you said. But it does not protect integrity — it cannot tell you whether what arrived is what was sent. Standard encryption modes are malleable: an attacker can modify ciphertext in ways that produce controlled changes in the decrypted plaintext. Flipping a bit in CTR-mode ciphertext flips the corresponding plaintext bit. Without a separate integrity mechanism, the recipient decrypts tampered ciphertext into tampered plaintext and cannot detect the manipulation. A Message Authentication Code (MAC) fills this gap.

A MAC is a keyed function: Tag = MAC(key, message). The sender transmits both the message and the tag. The receiver, who shares the secret key, recomputes the tag and checks that it matches. If it does, the message has not been tampered with and was produced by someone who knows the key. The formal security definition is EUF-CMA (existential unforgeability under chosen-message attack): even an adversary who can request tags on any messages of their choosing cannot forge a valid tag on any message they haven't already queried. This is a strong guarantee — the attacker has adaptive access to a tagging oracle and still cannot cheat.

The two main constructions are HMAC and CBC-MAC. HMAC is built from a hash function: HMAC(k, m) = H((k XOR opad) || H((k XOR ipad) || m)), where ipad and opad are fixed constants. The nested structure prevents length extension attacks that plague the naive H(key || message) construction. HMAC is provably secure under the assumption that the hash's compression function is a pseudorandom function — a weaker assumption than collision resistance, which means HMAC can remain secure even if collision attacks on the hash are found. CBC-MAC encrypts the message in CBC mode and uses the final block as the tag. It is provably secure for fixed-length messages but requires modifications (CMAC, EMAC) for variable-length messages due to specific forgery attacks.

A critical limitation of MACs is that they provide authentication but not non-repudiation. Since both parties share the same key, either could have produced the tag — the receiver cannot prove to a third party that the sender specifically created the message, because the receiver could have forged it. Digital signatures, which use asymmetric cryptography, solve this by letting only the private key holder sign while anyone can verify. For many protocols, MACs suffice (two parties who already trust each other), but wherever proof of origin matters — legal documents, financial transactions, software distribution — signatures are needed instead.

Practice Questions 5 questions

Prerequisite Chain

Understanding Zero → The Number Zero → Counting to Five → Counting to 10 → Counting to 20 → Counting a Set of Objects Up to 20 → Cardinality: The Last Number Counted → Matching Numerals to Quantities → Subitizing Small Quantities → Addition Within 10 → Number Bonds to 10 → Addition Within 20 → Doubles and Near Doubles → Doubles Facts Within 10 → Near Doubles Facts Within 20 → Mental Math Strategies for Addition → Mental Math: Adding and Subtracting Tens → Addition Within 100 → Repeated Addition as Multiplication → Multiplication as Equal Groups → Multiplication: Arrays → Basic Multiplication Facts (0s, 1s, 2s, 5s, 10s) → Multiplication Facts Within 100 → Division as Equal Sharing → Division as Grouping (Measurement Division) → Division: Grouping (Repeated Subtraction) Model → Division: Fair Sharing Model → Division as Equal Sharing → Division as Grouping → Basic Division Facts → Division Facts Within 100 → Multiplication and Division Fact Families → Relationship Between Multiplication and Division → Division Facts as Inverse of Multiplication → Remainders and Quotients in Division → Division Word Problems → Multi-Step Word Problems → Solving Multi-Step Word Problems → Multiplication Word Problems → Division Word Problems → Introduction to Long Division → Factors and Multiples → Prime and Composite Numbers → Equivalent Fractions → Relating Fractions and Decimals → Decimal Place Value → Integers and the Number Line → Comparing and Ordering Integers → Absolute Value → Adding Integers → Subtracting Integers → Multiplying Integers → Introduction to Exponents → Order of Operations → Integer Order of Operations → Variable Expressions → The Distributive Property → Variables and Expressions Review → Introduction to Polynomials → Adding and Subtracting Polynomials → Multiplying Polynomials → Factorial → Permutations → Combinations → Counting Principles: Addition and Multiplication Rules → Introduction to Graph Theory → Propositional Logic Foundations → Logical Equivalences → Boolean Algebra → Boolean Type and Truth Values → Comparison Operators and Boolean Tests → Logical Operators and Boolean Algebra → Boolean Algebra and Fundamental Laws → Logic Gates Fundamentals → Implementing Boolean Functions with Gates → Karnaugh Map Simplification → Combinational Circuit Design → Flip-Flops and Latches → Finite State Machines (FSMs) → Deterministic Finite Automata (DFA) → Nondeterministic Finite Automata (NFA) → Two-Way Finite Automata → NFA to DFA Conversion (Subset Construction) → DFA Properties and Minimization Algorithms → Regular Languages: Definition and Characterization → Context-Free Grammars (CFGs) → Pushdown Automata (PDA) → Equivalence of CFGs and Pushdown Automata → Closure Properties of Context-Free Languages → Limitations of Context-Free Languages → Pumping Lemma for Context-Free Languages → Turing Machines → Variants of Turing Machines and Equivalence → Nondeterministic Time Complexity and NP → The P vs. NP Problem → Complexity Class P: Polynomial Time → Hash Functions and Collision Resistance → Message Authentication Codes (MACs)

Longest path: 98 steps · 515 total prerequisite topics

Prerequisites (2)

Leads To (1)