← Cryptography guide

K057 / Hashes, MACs and key derivation

CMAC

CMAC OMAC · Survey date 2026-12-05

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.

Scope: Standard operation

AES-CMAC

See the scope above for fixed examples, reduced parameters and supported variants. Standard operation names and formulas are retained.

Reference ↗

Open lab →

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

Examples are illustrative; they are not execution-tested implementations or operational recommendations.

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.

Diagram source ↗

References