K057 / Hashes, MACs and key derivation
CMAC
A block-cipher-based MAC that uses a symmetric block cipher to authenticate data and protect integrity.
CRYPTOGRAPHY LAB / K057
Cryptography Lab · CMAC
Run real computations and inspect intermediate states step by step.
Educational only. Never enter real passwords or secret keys. Computation stays in your browser; input and trace values are not sent to a server. Do not use this implementation in production.
AES-CMAC
See the scope above for fixed examples, reduced parameters and supported variants. Standard operation names and formulas are retained.Output
Previous state
- Definition and overview
- A block-cipher-based MAC that uses a symmetric block cipher to authenticate data and protect integrity. Source document ↗
- Classification and reversibility
- Block-cipher-based MAC/keyed-hash family. Source document ↗
- Key or secret requirements
- Requires secret symmetric key of underlying block cipher. Source document ↗
- Operating principle and structure
- Process message blocks like CBC-MAC; XOR K1 or K2 into last block depending on completeness/padding; final ciphertext block is tag. Source document ↗
- Key size, block size and parameters
- AES-128/192/256 etc.; AES has 128-bit blocks/tags, tags may be truncated. TDEA is being retired. Source document ↗
- Security strength and recommendation
- Full 128-bit AES-CMAC tag gives 128-bit forgery resistance; truncation reduces it. NIST SP 800-38B standard. Source document ↗
- Known attacks and vulnerabilities
- No known practical AES/AES-CMAC attack is reported; relies on implementation and key management. Source document ↗
- Standards and certification
- Standardized in NIST SP 800-38B and RFC 4493 (AES-CMAC). Source document ↗
- Typical uses
- Widely used with AES for integrity/authentication in payments, smart cards, vehicles and network protocols. Source document ↗
- Implementations, libraries and tools
- Python cryptography and other libraries provide CMAC. Source document ↗
- Decryption or decoding
- Verification rather than decryption: recompute tag with same key and compare. Source document ↗
- Advantages
- Provable security for variable-length messages; addresses CBC-MAC flaws. Source document ↗
- Limitations and cautions
- Truncation lowers forgery resistance to tag length; consider block-size birthday bound and key management. Source document ↗
- Distinguishing encryption, encoding and hashing
- MAC, not encryption/encoding; verifies integrity and authenticity rather than recovering plaintext. Source document ↗
Practical examples
Example
Sender computes CMAC tag with secret symmetric key and sends with message; receiver recomputes and compares. Tag is evidence of integrity/authentication, not plaintext recovery.
Procedure
Choose agreed symmetric key/block cipher such as AES, compute CMAC tag, store/send with message, verify by constant-time comparison of recomputed tag. No decryption/decoding; separate AEAD for confidentiality.
Scenario
Payment terminals, smart cards and vehicle networks verify tampering with authentication tags. Firmware or commands needing confidentiality should also use separate AEAD encryption.
Pitfalls and alternatives
Follow minimum tag-length policy; avoid poor key management, TDEA, and confusing CMAC with reversible encryption or keyless integrity hashing.
References
- SP 800-38B, Recommendation for Block Cipher Modes of Operation: the CMAC Mode for Authentication | CSRC ↗
- RFC 4493: The AES-CMAC Algorithm ↗
- Cipher-based message authentication code (CMAC) — Cryptography 42.0.6 documentation ↗
- CMAC: A message seal built from a block cipher such as AES ↗
- CMAC — secure-crypto.org ↗
- draft-songlee-aes-cmac-01 ↗
- CMAC - PyCryptodome ↗
- AES-CMAC: sizes, standards and code examples | NextSSL ↗
- CMAC (OMAC) in Python: Implementation Guide ↗
- CMAC - A variable-input-length CBC MAC - Rogaway ↗