CBC-MAC
The original block-cipher MAC: secure only for fixed-length messages
Old but not broken. Kept for interoperability; root API only. Reach it with NextSSL(root=True) in Python or the nextssl_root_* functions in C.
About CBC-MAC
CBC-MAC is one of 2 CBC-MAC and DES-MAC variants in the NextSSL registry, a message authentication code. It uses a 16–32-byte key, a 16-byte (128-bit) authentication tag and a 16-byte (128-bit) block. Its registry entry cites ISO/IEC 9797-1 (algorithm 1) and NIST SP 800-38A (CBC). NextSSL lists it in the legacy tier and exposes it through the root API only (NextSSL(root=True) in Python, nextssl_root_* in C).
Overview
CBC-MAC computes a tag by encrypting a message in CBC mode with a zero IV and keeping the last ciphertext block. It is one of the oldest MAC constructions, standardised for DES as DES-MAC in ANSI X9.9 and FIPS 113.
CBC-MAC XORs each message block into the previous cipher output and encrypts the result. When all messages have the same fixed length, this is a secure pseudo-random function. When lengths vary, an attacker who knows the tags of two messages can construct a third valid message-tag pair by splicing, because the tag of one message is the chaining value for the next. This led to the development of CMAC, which fixes the problem with subkey masking.
NextSSL includes generic CBC-MAC as described in ISO/IEC 9797-1 algorithm 1 and DES-MAC from the withdrawn FIPS 113, both for legacy interoperability. Some protocols prepend the length or use a separately derived final key, as EMAC and ISO/IEC 9797-1 algorithm 2 do, to make CBC-MAC safe for variable lengths. CCM mode uses CBC-MAC internally, with the length encoded in the first block.
History
1985–2001Specified in FIPS 113
Specified in NIST SP 800-38A
Security notes
Plain CBC-MAC is forgeable for variable-length messages and must not be used unless the length is fixed and authenticated. DES-MAC additionally relies on 56-bit DES and is broken by exhaustive key search. Use CMAC or HMAC instead.
Typical uses
Sizes
| Field | Bytes | Meaning |
|---|---|---|
| key | 16 – 32 | Secret key |
| tag | 16 | Authentication tag |
| block | 16 | Block |
Use it
from nextssl_demo import NextSSL
root = NextSSL(root=True) # tier 'legacy' is reachable from the root API only
key = root.random(16)
tag = root.call("mac", "cbc-mac", None, key, b"message", 0)[0]
ok = root.check("mac_verify", "cbc-mac", None, key, b"message", tag)
nextssl_root_mac("cbc-mac", NULL, key, data, 0, tag);
nextssl_root_mac_verify("cbc-mac", NULL, key, data, tag);
use nextssl_core::Params;
use nextssl_registry::{self as reg, Policy};
let alg = reg::new_mac_in(reg::all(), Policy::Any, "cbc-mac", &Params::new())?;
let tag = alg.tag(&key, b"message")?;
let ok = alg.verify(&key, b"message", &tag)?;
Calls follow the NextSSL C ABI and its language bindings. Buffer sizes are validated against the sizes above.
Other CBC-MAC and DES-MAC variants
1More message authentication codes
All 30Frequently asked questions
What is CBC-MAC?
CBC-MAC is a MAC in the CBC-MAC and DES-MAC family. CBC-MAC computes a tag by encrypting a message in CBC mode with a zero IV and keeping the last ciphertext block.
What are the CBC-MAC sizes?
In NextSSL, CBC-MAC uses: key 16 to 32 bytes, tag 16 bytes, block 16 bytes.
Who designed CBC-MAC and when?
CBC-MAC belongs to the CBC-MAC and DES-MAC family, first published in 1985. Its origin: ANSI X9.9; FIPS 113 (withdrawn); ISO/IEC 9797-1.
Which standards define CBC-MAC?
CBC-MAC is referenced by ISO/IEC 9797-1 (algorithm 1), NIST SP 800-38A (CBC).
Is CBC-MAC safe to use?
CBC-MAC is in the legacy tier. Old but not broken. Kept for interoperability; root API only. It is only reachable through the root API (NextSSL(root=True) in Python, nextssl_root_* in C).
What other CBC-MAC and DES-MAC variants are there?
NextSSL also registers des-mac in the CBC-MAC and DES-MAC family.