Why Encrypt-Then-MAC Beats MAC-Then-Encrypt
Understand the cryptographic argument for combining encryption and authentication in the correct order.
Why Encrypt-Then-MAC Beats MAC-Then-Encrypt is a free Cryptology Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Cryptology Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Three Composition Orders
When combining encryption and a MAC, three orderings exist: Encrypt-then-MAC (EtM), MAC-then-Encrypt (MtE), and Encrypt-and-MAC (E&M). Each has fundamentally different security properties, and only one is provably secure in all settings.
Encrypt-then-MAC Defined
In Encrypt-then-MAC, the plaintext is first encrypted to produce ciphertext, and then the MAC is computed over that ciphertext. The receiver can verify the MAC before ever attempting decryption, which means a tampered message is rejected immediately without revealing information.
MAC-then-Encrypt Defined
In MAC-then-Encrypt, the MAC is computed over the plaintext, then both the plaintext and MAC are encrypted together. The receiver must decrypt the message before it can verify the MAC, which opens the door to padding oracle and decryption oracle attacks.
SSL 3.0 and TLS 1.0 Flaw
SSL 3.0 and TLS 1.0 used the MAC-then-Encrypt order for block ciphers in CBC mode. This design flaw was exploited by the BEAST attack in 2011 and the POODLE attack in 2014, both of which leveraged the oracle that exists when decryption happens before MAC verification.
Bellare-Namprempre Proof
In 2000, Bellare and Namprempre formally proved that among the three composition orders, only Encrypt-then-MAC achieves IND-CCA2 security (chosen-ciphertext security) for all combinations of secure encryption and MAC primitives. MtE and E&M can fail in certain compositions.
Encrypt-and-MAC in SSH
SSH uses Encrypt-and-MAC: the MAC is computed over the plaintext and sent alongside the ciphertext in plaintext form. While SSH has not suffered the same exploits as SSL/TLS MtE, this composition is also theoretically flawed as it can leak plaintext information through the unencrypted MAC.
AEAD as the Safe Abstraction
Authenticated Encryption with Associated Data (AEAD) is the modern abstraction that solves the composition problem by design. AEAD integrates encryption and authentication into a single primitive, ensuring they are always combined correctly without requiring the developer to choose a composition order.
AES-GCM: The AEAD Standard
AES-GCM (Galois/Counter Mode) is the most widely deployed AEAD cipher suite. It provides authenticated encryption through a combination of CTR-mode encryption and GHASH authentication, and is hardware-accelerated via AES-NI and CLMUL instructions on modern CPUs.
TLS 1.3 Enforces AEAD Only
TLS 1.3 made a decisive break with the past by removing all non-AEAD cipher suites. Every TLS 1.3 cipher suite uses AEAD, eliminating entire classes of vulnerabilities caused by improper manual composition of encryption and MAC primitives that plagued earlier TLS versions.
Do Not Compose Primitives Manually
The key lesson from decades of cryptographic attacks is that manually composing encryption and MAC primitives is error-prone even for experts. Modern cryptographic libraries expose AEAD interfaces specifically to prevent developers from making composition mistakes that lead to real-world vulnerabilities.
Practical Guidance
When building systems today, always reach for an AEAD primitive such as AES-GCM or ChaCha20-Poly1305. If you must interoperate with legacy systems using separate MAC and encryption, ensure you are using Encrypt-then-MAC order and never MtE or E&M.
EtM vs MtE Check
Which statement correctly describes the security difference between Encrypt-then-MAC and MAC-then-Encrypt?
Lesson Recap: Composition Order Matters
EtM is the only provably secure composition order for separate encryption and MAC primitives. TLS 1.3 eliminates the problem entirely by mandating AEAD-only cipher suites. When in doubt, use an AEAD primitive such as AES-GCM or ChaCha20-Poly1305 and let the library handle composition correctly.
Frequently asked questions
Is the “Why Encrypt-Then-MAC Beats MAC-Then-Encrypt” lesson free?
Yes — the full text of “Why Encrypt-Then-MAC Beats MAC-Then-Encrypt” is free to read here on the web, and the Cryptology Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Cryptology Academy course, upgrade to CoddyKit PRO.
What will I learn in “Why Encrypt-Then-MAC Beats MAC-Then-Encrypt”?
Understand the cryptographic argument for combining encryption and authentication in the correct order. You practise Cryptology Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Cryptology Academy?
No prior experience is required. Cryptology Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Why Encrypt-Then-MAC Beats MAC-Then-Encrypt” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Cryptology Academy lesson?
Yes. Every Cryptology Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Why Encrypt-Then-MAC Beats MAC-Then-Encrypt
- SIV Mode: Nonce-Misuse Resistant AEAD
- AEGIS: High-Speed Authenticated Encryption
- Selecting AEAD for Production Systems