Hubbry Logo
CBC-MACCBC-MACMain
Open search
CBC-MAC
Community hub
CBC-MAC
logo
8 pages, 0 posts
0 subscribers
Be the first to start a discussion here.
Be the first to start a discussion here.
CBC-MAC
CBC-MAC
from Wikipedia

In cryptography, a cipher block chaining message authentication code (CBC-MAC) is a technique for constructing a message authentication code (MAC) from a block cipher. The message is encrypted with some block cipher algorithm in cipher block chaining (CBC) mode to create a chain of blocks such that each block depends on the proper encryption of the previous block. This interdependence ensures that a change to any of the plaintext bits will cause the final encrypted block to change in a way that cannot be predicted or counteracted without knowing the key to the block cipher.

CBC-MAC construction

To calculate the CBC-MAC of message m, one encrypts m in CBC mode with zero initialization vector and keeps the last block. The following figure sketches the computation of the CBC-MAC of a message comprising blocks using a secret key k and a block cipher E:

CBC-MAC on its own is not secure for variable-length messages[1] (see the discussion below) and is currently used to construct a pseudorandom function family[2] and as a component of the CCM mode.

Use in standards

[edit]

The CBC-MAC construct is used as part of the CCM mode utilized in IEEE 802.11i and NIST SP 800-97 (as CCMP, the CCM encryption protocol for WPA2), IPsec,[3] and TLS 1.2,[4] as well as Bluetooth Low Energy (as of Bluetooth 4.0, see NIST SP 800-121 Rev2).[5] It is available for TLS 1.3, but not enabled by default in OpenSSL.[6]

CBC-MAC is also used as a "conditioning component" (a.k.a. randomness extractor,[2] a method to generate bitstrings with full entropy) in NIST SP 800-90B.

Standards that define the algorithm

[edit]

FIPS PUB 113 Computer Data Authentication is a (now obsolete) U.S. government standard that specified the CBC-MAC algorithm using DES as the block cipher.

The CBC-MAC algorithm is also included into ANSI X9.9, ANSI X9.19, ISO 8731-1, and ISO/IEC 9797-1 MAC (Algorithm 1).[7]

Security with fixed and variable-length messages

[edit]

If the block cipher used is secure (meaning that it is a pseudorandom permutation), then CBC-MAC is secure for fixed-length messages.[1] However, by itself, it is not secure for variable-length messages. Thus, any single key must only be used for messages of a fixed and known length. This is because an attacker who knows the correct authentication tag (i.e. CBC-MAC) pairs for two messages and can generate a third message whose CBC-MAC will also be . This is simply done by XORing the first block of with t and then concatenating m with this modified ; i.e., by making . When computing the MAC for the message , it follows that we compute the MAC for m in the usual manner as t, but when this value is chained forwards to the stage computing we will perform an exclusive OR operation with the value derived for the MAC of the first message. The presence of that tag in the new message means it will cancel, leaving no contribution to the MAC from the blocks of plain text in the first message m: and thus the tag for is .

This problem cannot be solved by adding a message-size block to the end.[8] There are three main ways of modifying CBC-MAC so that it is secure for variable length messages: 1) Input-length key separation; 2) Length-prepending; 3) Encrypt last block.[8] In such a case, it may also be recommended to use a different mode of operation, for example, CMAC or HMAC to protect the integrity of variable-length messages.

Length prepending

[edit]

One solution is to include the length of the message in the first block;[9] in fact CBC-MAC has been proven secure as long as no two messages that are prefixes of each other are ever used and prepending the length is a special case of this.[10] This can be problematic if the message length may not be known when processing begins.

Encrypt-last-block

[edit]
Computation of CBC-MAC Encrypt-last-block.

Encrypt-last-block CBC-MAC (ECBC-MAC)[11] is defined as CBC-MAC-ELB(m, (k1, k2)) = E(k2, CBC-MAC(k1, m)).[8] Compared to the other discussed methods of extending CBC-MAC to variable-length messages, encrypt-last-block has the advantage of not needing to know the length of the message until the end of the computation.

Attack methods against incorrect use

[edit]

As with many cryptographic schemes, naïve use of ciphers and other protocols may lead to attacks being possible, reducing the effectiveness of the cryptographic protection (or even rendering it useless). We present attacks which are possible due to using the CBC-MAC incorrectly.[12]

Using the same key for encryption and authentication

[edit]

One common mistake is to reuse the same key k for CBC encryption and CBC-MAC. Although a reuse of a key for different purposes is a bad practice in general, in this particular case the mistake leads to a spectacular attack:

Suppose Alice has sent to Bob the cipher text blocks . During the transmission process, Eve can tamper with any of the cipher-text blocks and adjust any of the bits therein as she chooses, provided that the final block, , remains the same. We assume, for the purposes of this example and without loss of generality, that the initialization vector used for the encryption process is a vector of zeroes.

When Bob receives the message, he will first decrypt the message by reversing the encryption process which Alice applied, using the cipher text blocks . The tampered message, delivered to Bob in replacement of Alice's original, is .

Bob first decrypts the message received using the shared secret key K to obtain corresponding plain text. Note that all plain text produced will be different from that which Alice originally sent, because Eve has modified all but the last cipher text block. In particular, the final plain text, , differs from the original, , which Alice sent; although is the same, , so a different plain text is produced when chaining the previous cipher text block into the exclusive-OR after decryption of : .

It follows that Bob will now compute the authentication tag using CBC-MAC over all the values of plain text which he decoded. The tag for the new message, , is given by:

Notice that this expression is equal to

which is exactly :

and it follows that .

Therefore, Eve was able to modify the cipher text in transit (without necessarily knowing what plain text it corresponds to) such that an entirely different message, , was produced, but the tag for this message matched the tag of the original, and Bob was unaware that the contents had been modified in transit. By definition, a Message Authentication Code is broken if we can find a different message (a sequence of plain-text pairs ) which produces the same tag as the previous message, P, with . It follows that the message authentication protocol, in this usage scenario, has been broken, and Bob has been deceived into believing Alice sent him a message which she did not produce.

If, instead, we use different keys for the encryption and authentication stages, say and , respectively, this attack is foiled. The decryption of the modified cipher-text blocks obtains some plain text string . However, due to the MAC's usage of a different key , we cannot "undo" the decryption process in the forward step of the computation of the message authentication code so as to produce the same tag; each modified will now be encrypted by in the CBC-MAC process to some value .

This example also shows that a CBC-MAC cannot be used as a collision-resistant one-way function: given a key it is trivial to create a different message which "hashes" to the same tag.

Allowing the initialization vector to vary in value

[edit]

When encrypting data using a block cipher in cipher block chaining (or another) mode, it is common to introduce an initialization vector to the first stage of the encryption process. It is typically required that this vector be chosen randomly (a nonce) and that it is not repeated for any given secret key under which the block cipher operates. This provides semantic security, by means of ensuring the same plain text is not encrypted to the same cipher text, allowing an attacker to infer a relationship exists.

When computing a message authentication code, such as by CBC-MAC, the use of an initialization vector is a possible attack vector.

In the operation of a ciphertext block chaining cipher, the first block of plain text is mixed with the initialization vector using an exclusive OR (). The result of this operation is the input to the block cipher for encryption.

However, when performing encryption and decryption, we are required to send the initialization vector in plain text - typically as the block immediately preceding the first block of cipher text - such that the first block of plain text can be decrypted and recovered successfully. If computing a MAC, we will also need to transmit the initialization vector to the other party in plain text so that they can verify the tag on the message matches the value they have computed.

If we allow the initialization vector to be selected arbitrarily, it follows that the first block of plain text can potentially be modified (transmitting a different message) while producing the same message tag.

Consider a message . In particular, when computing the message tag for CBC-MAC, suppose we choose an initialization vector such that computation of the MAC begins with . This produces a (message, tag) pair .

Now produce the message . For each bit modified in , flip the corresponding bit in the initialization vector to produce the initialization vector . It follows that to compute the MAC for this message, we begin the computation by . As bits in both the plain text and initialization vector have been flipped in the same places, the modification is cancelled in this first stage, meaning the input to the block cipher is identical to that for . If no further changes are made to the plain text, the same tag will be derived despite a different message being transmitted.

If the freedom to select an initialization vector is removed and all implementations of CBC-MAC fix themselves on a particular initialization vector (often the vector of zeroes, but in theory, it could be anything provided all implementations agree), this attack cannot proceed.

To sum up, if the attacker is able to set the IV that will be used for MAC verification, he can perform arbitrary modification of the first data block without invalidating the MAC.

Using predictable initialization vector

[edit]

Sometimes IV is used as a counter to prevent message replay attacks. However, if the attacker can predict what IV will be used for MAC verification, he or she can replay previously observed message by modifying the first data block to compensate for the change in the IV that will be used for the verification. For example, if the attacker has observed message with and knows , he can produce that will pass MAC verification with .

The simplest countermeasure is to encrypt the IV before using it (i.e., prepending IV to the data). Alternatively MAC in CFB mode can be used, because in CFB mode the IV is encrypted before it is XORed with the data.

Another solution (in case protection against message replay attacks is not required) is to always use a zero vector IV.[13] Note that the above formula for becomes . So since and are the same message, by definition they will have the same tag. This is not a forgery, rather the intended use of CBC-MAC.

See also

[edit]
  • CMAC – A block-cipher–based MAC algorithm which is secure for messages of different lengths (recommended by NIST).
  • OMAC and PMAC – Other methods to turn block ciphers into message authentication codes (MACs).
  • One-way compression function – Hash functions can be made from block ciphers. But note, there are significant differences in function and uses for security between MACs (such as CBC-MAC) and hashes.

References

[edit]

Sources

[edit]
Revisions and contributorsEdit on WikipediaRead on Wikipedia
from Grokipedia
CBC-MAC, or Cipher Block Chaining , is a mode of operation for s that generates a fixed-length (MAC) to verify the integrity and authenticity of a message by processing it in chained blocks. It applies the block cipher iteratively to each message block, XORing the input with the previous block (starting from an all-zero ), and outputs a truncated portion of the final block as the tag. The algorithm authenticates an m-block message x=x1xmx = x_1 \dots x_m using a FF with key kk, computing y0=0[n](/page/N+)y_0 = 0^[n](/page/N+), yi=Fk(yi1xi)y_i = F_k(y_{i-1} \oplus x_i) for i=1i = 1 to mm, and deriving the s-bit tag from ymy_m (where nn is the block size and sns \leq n). This ensures that any alteration to the propagates through the , making the tag sensitive to changes. CBC-MAC was originally designed for fixed-length messages and has been widely adopted in financial systems, such as banking protocols using the (DES). Standardized internationally in ISO/IEC 9797-1 since 1999, with the second edition in 2011 and an amendment in 2023, CBC-MAC serves as the basis for the first mechanism in the standard, known explicitly as the CBC mode for MAC generation. It was formerly specified in the now-withdrawn ANSI X9.9 (1986) for DES-based implementations , though modern uses often pair it with stronger ciphers like AES. Its simplicity and efficiency—requiring only m block cipher invocations—contributed to its popularity before more advanced variants emerged. Security analyses, notably from , prove that if the underlying is a (PRP), then CBC-MAC functions as a strongly pseudorandom function (PRF) and secure MAC against existential under chosen-message attacks, with an advantage bound of approximately q2m2/2n1q^2 m^2 / 2^{n-1} for q queries (birthday-bound security). However, CBC-MAC is insecure for variable-length messages without proper padding, as attackers can exploit length-extension collisions to forge tags—e.g., two messages of lengths differing by a block can yield the same tag if crafted adversarially. To address this, NIST recommends variants like CMAC (in SP 800-38B), which modifies CBC-MAC with subkeys for arbitrary lengths while maintaining efficiency. CBC-MAC also forms the authentication component in combined modes like CCM (Counter with CBC-MAC) for .

Overview

Definition and Purpose

A message authentication code (MAC) is a symmetric-key cryptographic primitive that takes a variable-length message and a secret key as inputs to produce a fixed-length output tag, which is typically much shorter than the message itself and used to verify both the integrity and authenticity of the transmitted data. Unlike unkeyed cryptographic hash functions, which provide only collision resistance for data integrity without authentication, a MAC requires the shared secret key for both tag generation and verification, ensuring that only parties possessing the key can generate valid tags or confirm the message's origin. The CBC-MAC, or Cipher Block Chaining Message Authentication Code, is a specific type of MAC constructed from a symmetric , operating as a deterministic function that processes the message under a secret key to yield a fixed-length authentication tag equal in size to the block cipher's output. Its primary purpose is to provide efficient message authentication in symmetric cryptography settings, leveraging existing block ciphers to assure data integrity against tampering and authenticity against forgery by unauthorized parties, without relying on separate hash functions. This makes CBC-MAC particularly suitable for resource-constrained environments. Developed in the as an efficient mechanism utilizing prevalent block ciphers like DES, CBC-MAC was formalized in international standards to enable secure data protection in early cryptographic applications, including financial and telecommunications systems. By integrating seamlessly with primitives, it offered a practical alternative to more computationally intensive methods, promoting widespread adoption for verifying message legitimacy in symmetric-key protocols.

Relation to Block Ciphers and CBC Mode

CBC-MAC is constructed using a symmetric-key , which operates on fixed-size input blocks, typically 64 or 128 bits, to provide pseudorandom permutations under a secret key. For instance, the (AES) serves as a common underlying for CBC-MAC implementations, employing 128-bit blocks regardless of the key length chosen (128, 192, or 256 bits). The must be secure against chosen-plaintext attacks to ensure the overall integrity of the mechanism, as weaknesses in the primitive could compromise the MAC's security. The core of CBC-MAC draws from the Cipher Block Chaining (CBC) mode of operation, a standard technique for processing sequential data blocks with a . In CBC mode, encryption begins with an (IV) that is XORed with the first block before ; subsequent blocks are each XORed with the immediately preceding block prior to , creating a dependency chain that diffuses changes across the output. This chaining prevents identical blocks from producing identical blocks, enhancing security over simpler modes like Electronic Codebook (ECB). Decryption reverses the process by applying the inverse and XORing with the prior or IV. In adapting CBC mode for CBC-MAC, the same secret key is used for all block encryptions throughout the message processing, without requiring multiple keys or key derivation. Unlike CBC , CBC-MAC initializes the with a fixed all-zero block instead of a variable IV, and it assumes messages of exact multiples of the block size with no applied. The construction discards all intermediate values, retaining only the final chained block as the authentication tag, which serves to verify message rather than enable plaintext recovery. This shift in purpose—from confidentiality in CBC to in CBC-MAC—eliminates the need for an IV's unpredictability while leveraging the for diffusion properties essential to resisting forgery.

Algorithm Construction

Initialization Vector and Key Setup

The CBC-MAC algorithm requires a secret key KK that matches the key length supported by the underlying , such as 128 bits for AES-128. This key must be randomly generated with uniform distribution and maintained in strict to ensure the security of the process. Unlike the CBC encryption mode, which employs a random (IV) to achieve , CBC-MAC uses a fixed IV consisting of an all-zero string of length equal to the block size nn (denoted 0n0^n) to produce a deterministic output for a given message and key. This choice ensures that the same message always yields the same tag, which is essential for message verification. In the setup phase, the secret key KK is loaded into the , and the initial chaining value H0H_0 is set to the zero vector 0n0^n. For example, when using a 64-bit like DES, the IV is 0640^{64}.

Message Processing Steps

The input message MM, assumed to be of fixed length that is a positive multiple of the 's block size nn, is partitioned into mm sequential blocks M1,M2,,MmM_1, M_2, \dots, M_m, each consisting of nn bits. The processing initializes a chaining value C0C_0 as the all-zero block of nn bits, serving as the zero . For each block index ii from 1 to mm, the algorithm iteratively computes the next chaining value according to the formula Ci=EK(MiCi1),C_i = E_K(M_i \oplus C_{i-1}), where EKE_K denotes the 's function under the secret key KK, and \oplus represents the bitwise exclusive-or operation. This operation applies the to the XOR of the current message block and the previous chaining value. Through this block-by-block chaining, each intermediate CiC_i incorporates information from all prior blocks M1M_1 through MiM_i, establishing a cumulative dependency that propagates across the entire and diffuses any alterations in early blocks to subsequent computations.

Final Tag Computation

In the CBC-MAC construction, after processing all message blocks through the chaining mechanism, the final chaining value CmC_m directly serves as the authentication tag TT. Specifically, for an mm-block divided into blocks m1,m2,,mmm_1, m_2, \dots, m_m, the computation begins with an of zero, and each subsequent chaining value is derived as Ci=EK(Ci1mi)C_i = E_K(C_{i-1} \oplus m_i) for i=1i = 1 to mm, where EKE_K is the underlying under key KK and C0=0nC_0 = 0^n. Upon completion, T=CmT = C_m, providing a fixed-output value that encapsulates the entire authentication. The length of the tag TT matches the block size of the underlying cipher, ensuring it inherits the full output length for security purposes in the basic scheme. For instance, when using AES as the , the tag is 128 bits long. In practical implementations, the tag may be truncated to a shorter length sns \leq n bits to balance and efficiency, though the full block output is used in the core computation before any truncation. To verify the tag, the recipient independently recomputes the CBC-MAC value TT' from the received message and shared key KK, then checks whether T=TT' = T; equality confirms message integrity and authenticity. Unlike certain other message authentication codes that apply a final hash function or additional encryption step to the chaining output, CBC-MAC employs no further processing beyond outputting CmC_m as the tag, maintaining its simplicity as a direct derivative of the block cipher chaining.

Security for Fixed-Length Messages

Provable Security Bounds

The CBC-MAC for fixed-length messages is proven to be a pseudorandom function (PRF) assuming the underlying behaves as a . This security model captures the indistinguishability of CBC-MAC outputs from a truly random function, even against adaptive adversaries querying the MAC on distinct messages of the same length. The distinguishing advantage of an adversary making qq queries is at most approximately q2m22n1\frac{q^2 m^2}{2^{n-1}}, where nn denotes the block size in bits and mm is the fixed number of blocks in the messages. This bound arises from the birthday paradox applied to intermediate chaining values, combined with the security of the underlying PRP, ensuring that collisions in the internal state—which could reveal structure—are unlikely until roughly 2n/2/m2^{n/2} / m queries. Earlier analyses provided guarantees of this form, but the refined bound from Black, Halevi, Krawczyk, Krovetz, and Rogaway (2002) tightens the constants to approximately q2m2/2nq^2 m^2 / 2^n for practical fixed-length scenarios, emphasizing scalability for moderate query volumes. As a consequence of its PRF security, CBC-MAC resists existential under chosen-message attacks when restricted to messages of identical, known length. The advantage remains bounded by the PRF distinguishing advantage, typically negligible provided messages are distinct and the length is fixed in advance, as this prevents adversaries from exploiting length-based extensions to construct valid . This property holds under the same PRP assumption on the , with the core theorem tracing to foundational work by Rogaway (2001) and refined in subsequent analyses.

Distinguishing Attacks

Distinguishing attacks on CBC-MAC for fixed-length messages exploit the structure of to differentiate it from a truly random function, revealing the limits of its . A key example is a birthday-bound attack that leverages the property of the underlying . The adversary constructs q2n/2q \approx 2^{n/2} fixed-length messages, where nn is the block size, that differ only in their first block while keeping the remaining blocks identical. In CBC-MAC, the chaining value after processing the first block is Fk(m10)F_k(m_1 \oplus 0), and since FkF_k is a , these chaining values are distinct for distinct first blocks. The identical subsequent blocks then produce distinct inputs to the final FkF_k, resulting in distinct tags with probability 1—no collisions occur. In contrast, under a random function , the probability of at least one tag collision among qq outputs is approximately 1eq(q1)/2n+10.631 - e^{-q(q-1)/2^{n+1}} \approx 0.63 for q1.18×2n/2q \approx 1.18 \times 2^{n/2}. The adversary declares the CBC-MAC if no collision is observed and random otherwise, succeeding with constant advantage. This attack requires O(2n/2)O(2^{n/2}) queries and time, demonstrating that CBC-MAC's security as a fixed-input-length pseudorandom function (FIL-PRF) is bounded by the birthday paradox, with distinguishing advantage Θ(q2m2/2n)\Theta(q^2 m^2 / 2^n). The bound is tight, as matching upper bounds are proven under the assumption that the block cipher is a secure PRF or PRP. While CBC-MAC achieves provable PRF security for fixed-length messages up to this birthday limit, it fails as a variable-input-length PRF (VIL-PRF) without modifications, as simple relations between tags for messages of different lengths allow distinguishing with constant probability using just two queries. For instance, querying the all-zero single-block message yields tag t=Fk(0)t = F_k(0); the two-block message consisting of the all-zero block followed by tt then yields the same tag tt, a relation unlikely under a random function. This vulnerability also enables existential forgeries under chosen-message attacks when lengths vary. To mitigate these limitations, CBC-MAC should be restricted to fixed-length messages in applications requiring FIL-PRF security, or extended with length-prepending or other modifications (such as XCBC or TMAC) to achieve VIL-MAC or VIL-PRF properties while preserving security bounds close to the fixed-length case.

Handling Variable-Length Messages

Length Prepending Method

The length prepending method addresses the insecurity of basic CBC-MAC for variable-length messages by incorporating an explicit encoding of the message length as the initial block in the input to the algorithm. This ensures that messages of different lengths are processed with distinct starting inputs, thereby preventing forgery attacks that exploit prefix relationships between messages. The approach transforms the input such that no authenticated message can serve as a prefix for another, restoring provable security under standard assumptions for a pseudorandom function family. In the processing steps, the algorithm begins with an C0C_0 set to the zero block. The first block is then formed by encoding the original LL (typically in bits) as a fixed-width representation within a full block, using big-endian byte order and with leading zeros if necessary to fill the block size. For instance, with a 64-bit block size and a of 100 bits, the 100 is encoded as the 64-bit binary value 0x00000000000000640x0000000000000064 (big-endian). The subsequent blocks consist of the original , which is padded to a multiple of the block size using ISO 9797-1 method 2 (appending a single '1' bit followed by zeros). The chaining then proceeds as in fixed-length CBC-MAC: each block is XORed with the previous block and encrypted under the shared key to produce the next block, culminating in the final block as the authentication tag. This method restores PRF-like security for distinct-length messages, with the adversary's advantage bounded by approximately m2q22n\frac{m^2 q^2}{2^n}, where mm is the maximum number of blocks in any query, qq is the number of queries, and nn is the block size in bits; this bound follows from adapting proofs of CBC-MAC unpredictability to the prepended form, assuming the underlying is a strong . By including the length upfront, it specifically thwarts length-extension attacks, where an adversary might otherwise append data to a known message-tag pair without altering the tag, as any extension would mismatch the prepended and invalidate verification. The fixed-width, big-endian encoding avoids in length interpretation across systems, ensuring consistent processing regardless of the message's bit up to the 's capacity.

Encrypt-Last-Block Method

The encrypt-last-block method provides an extension to for handling variable-length messages by following the standard CBC processing for all blocks and then encrypting the final chained output using a second key. The message is divided into blocks, with the first block XORed with an (typically zero), and each subsequent block XORed with the previous before under the key K1K_1. The final chained value is then encrypted using a second key K2K_2. In standards such as ISO/IEC 9797-1 (MAC Algorithm 3), a specific variant employs this approach with , where the CBC chaining uses single DES with the first subkey for intermediate blocks, but the final block input (XORed with the previous ciphertext) undergoes a full encryption using both subkeys. This method offers weaker security compared to length-prepending techniques, as it remains vulnerable to attacks when two messages of different lengths produce the same intermediate CBC state before the last block, allowing length collisions to enable existential forgeries with probability approaching 1 after 2n/22^{n/2} queries, where nn is the block size. Despite these limitations, the encrypt-last-block approach is more efficient for streaming applications, requiring only one additional block cipher invocation beyond the message length in blocks and enabling online processing without upfront knowledge of the full message length. It forms the basis for the (Encrypt-and-MAC) construction, which uses two independent keys to compute the CBC chain under K1K_1 and then encrypts the resulting tag under K2K_2, supporting variable-length messages padded to full blocks. Contemporary analyses critique the method as less suitable for general-purpose use due to its reliance on careful key derivation and padding to avoid length-extension vulnerabilities, favoring more robust variants like CMAC for broader adoption.

Attacks on Incorrect Implementations

Shared Key with Encryption

One common misuse of CBC-MAC occurs when the same cryptographic key is shared between CBC mode encryption for and CBC-MAC for , particularly in an encrypt-then-MAC where the MAC is computed over the . This key reuse enables an attacker who observes a valid ciphertext and its accompanying MAC tag to perform forgeries by crafting modified ciphertexts that verify under the MAC but decrypt to attacker-chosen plaintexts. The arises because the shared key allows the attacker to exploit the structural similarities in the dependencies of both modes, effectively linking the encryption process to the computation in a predictable manner. In the specific attack, suppose a message M=M1M2MnM = M_1 || M_2 || \dots || M_n is encrypted under key KK using CBC mode with initialization vector IV(0)IV^{(0)} to produce ciphertext blocks C0(0)C1(0)Cn1(0)C_0^{(0)} || C_1^{(0)} || \dots || C_{n-1}^{(0)}, where C0(0)=IV(0)C_0^{(0)} = IV^{(0)} and Ci(0)=EK(Mi+1Ci1(0))C_i^{(0)} = E_K(M_{i+1} \oplus C_{i-1}^{(0)}) for i1i \geq 1, with EKE_K denoting the block cipher encryption under KK. The corresponding plaintext blocks are P1(0)P2(0)Pn(0)P_1^{(0)} || P_2^{(0)} || \dots || P_n^{(0)}, recovered via decryption as Pi+1(0)=DK(Ci(0)Ci1(0))P_{i+1}^{(0)} = D_K(C_i^{(0)} \oplus C_{i-1}^{(0)}), where DKD_K is the decryption function. The valid MAC tag T(0)T^{(0)} is then computed as the final chaining value of CBC-MAC over the ciphertext blocks C0(0)C1(0)Cn1(0)C_0^{(0)} || C_1^{(0)} || \dots || C_{n-1}^{(0)} under the same key KK, starting from an all-zero IV: S0=0S_0 = 0, Si=EK(Ci(0)Si1)S_i = E_K(C_i^{(0)} \oplus S_{i-1}), and T(0)=Sn1T^{(0)} = S_{n-1}. An attacker can now forge a new ciphertext by setting IV=0IV' = 0 and constructing blocks C0=C0(0)C_0' = C_0^{(0)}, C1=C1(0)C_1' = C_1^{(0)}, ..., up to a manipulation point, such as altering a later block like Cn2=Cn2(0)Pn(0)PnC_{n-2}' = C_{n-2}^{(0)} \oplus P_n^{(0)} \oplus P_n' and keeping Cn1=Cn1(0)C_{n-1}' = C_{n-1}^{(0)}, where PnP_n' is the attacker's chosen plaintext block. Due to the shared key, the CBC-MAC computation over this forged ciphertext CC' yields the same tag T(0)T^{(0)}, as the chaining values align predictably with the original encryption dependencies up to the manipulation. Upon decryption of CC', the initial blocks recover the original structure, but the altered block produces the desired PnP_n', enabling an existential forgery where the attacker controls part of the decrypted message while the MAC verifies successfully. This attack succeeds with probability 1 after observing just one valid (ciphertext, tag) pair. To illustrate with DES as the underlying (a 64-bit historically used in both modes), consider a simplified two-block M=M1M2M = M_1 || M_2 encrypted under a shared 56-bit DES key KK with IV(0)=0IV^{(0)} = 0. The ciphertext is C1=DESK(M1)C_1 = DES_K(M_1), C2=DESK(M2C1)C_2 = DES_K(M_2 \oplus C_1), and the MAC tag T=DESK(C2DESK(C1))T = DES_K(C_2 \oplus DES_K(C_1)). An attacker observes C1C2TC_1 || C_2 || T and forges a new two-block ciphertext C1=C1C_1' = C_1, C2=C2ΔC_2' = C_2 \oplus \Delta, where Δ\Delta is chosen such that decryption yields a modified M2=M2ΔM_2' = M_2 \oplus \Delta. The MAC over C1C2C_1' || C_2' computes S1=DESK(C1)S_1' = DES_K(C_1), T=DESK(C2S1)=DESK((C2Δ)DESK(C1))T' = DES_K(C_2' \oplus S_1') = DES_K((C_2 \oplus \Delta) \oplus DES_K(C_1)). By selecting Δ\Delta to compensate for the chaining (leveraging the known structure), T=TT' = T, allowing verification while altering the decrypted output. This demonstrates how DES's small block size exacerbates predictability in the attack, though the issue is structural and applies to any secure under key reuse. The primary mitigation is to use distinct keys for CBC encryption and CBC-MAC: generate a separate authentication key KMACK_{MAC} independent of the encryption key KencK_{enc}, or derive KMACK_{MAC} from KencK_{enc} using an approved (e.g., ) to ensure cryptographic separation. NIST guidelines explicitly recommend that a single key be used for only one cryptographic function, such as or integrity protection via MAC, to prevent such cross-mode vulnerabilities and limit the impact of key compromise. Authenticated modes like GCM or CCM, which integrate both functions under a single key in a provably secure manner, may be considered as alternatives to separate CBC-based constructions.

Variable Initialization Vector

In CBC-MAC, the standard construction mandates a fixed (IV) of all zeros to ensure for fixed-length messages. However, a common misuse arises when implementers treat CBC-MAC analogously to CBC-mode , incorporating a variable or message-dependent IV in an attempt to enhance or reuse components from protocols. This , observed in some early implementations that assumed IV practices from could be directly applied, compromises the scheme's core properties. The vulnerability stems from the CBC-MAC's first processing step, where the IV is XORed with the initial block before . If the IV is variable and controllable by an attacker—often because it must be transmitted alongside the and tag for verification—the attacker can exploit this to achieve tag malleability. Specifically, upon obtaining a valid tag TT for a MM under IV, the attacker can forge a new tag T=TδT' = T \oplus \delta for a modified MM' (with its first block altered by δ\delta) by simply setting a new IV' = IV δ\oplus \delta. This directly alters the effective first block input to the without invalidating the tag, as the subsequent computations remain consistent. As a result, unforgeability is completely broken: a single valid (M, T, IV) triple suffices for the attacker to generate arbitrarily many forgeries for related messages, undermining the MAC's ability to detect tampering. To mitigate this, implementations must strictly enforce the fixed zero IV as per the original design. For scenarios requiring a nonce or variable input to prevent replay attacks, nonce-based MACs such as GMAC—defined in NIST SP 800-38D and used in modes like GCM—should be adopted instead.

Predictable Initialization Vector

In CBC-MAC, the standard construction requires a fixed all-zero to ensure provable security as a pseudorandom function for messages of fixed length. Deviations from this, such as employing a constant non-zero IV, can introduce vulnerabilities in certain implementations, particularly if the IV is transmitted alongside the message and tag for verification. For example, the nCipher nCore API prior to version 2.18 transmitted the IV when a non-zero value was used, enabling remote attackers to modify messages while bypassing integrity checks by exploiting the exposed IV. A related issue arises when implementations use a counter or other predictable value, such as a , as the IV to provide uniqueness across messages. This predictability allows an attacker to anticipate the IV for a target message and perform offline computations. Specifically, upon observing a valid (IV1, M1, tag) where M1 consists of full blocks, the attacker can predict IV2, compute the adjusted message M2 such that each block of M2 is XORed with the corresponding block of (IV1 XOR IV2 padded appropriately), and submit the forged (IV2, M2, tag); the verification will succeed because the initial value IV2 XOR first block of M2 equals IV1 XOR first block of M1, yielding identical subsequent and the same tag. Such attacks facilitate preimage recovery for valid message-tag pairs through simple XOR operations once the IV is known or predicted, effectively reducing the scheme's resistance to offline computation and chosen-IV forgery. The security degrades from the provable bound of roughly 2b/22^{b/2} (where bb is the block size) against distinguishing attacks in the standard fixed-zero IV construction to trivial forgery probability 1, severely compromising message authenticity. To mitigate these risks, CBC-MAC implementations must strictly use the all-zero IV as specified in standards like FIPS 113. For applications needing nonces or counters to handle variable inputs or replay protection, modes such as GCM are recommended, as they integrate nonce-based and without relying on modifiable IVs in the MAC computation.

Standards and Applications

Defining Standards

The Cipher Block Chaining (CBC-MAC) has been formally specified in several cryptographic standards, beginning with early definitions for the (DES) and evolving to support modern block ciphers like the (AES) while addressing security limitations for variable-length messages. One of the earliest standards is FIPS PUB 113, published by the National Institute of Standards and Technology (NIST) in 1985, which defines a Data Algorithm (DAA) based on DES operating in CBC mode to produce a MAC of 36 to 64 bits (in multiples of 8) for authenticating data blocks. This standard specifies the use of DES as the underlying with a 64-bit block size and 56-bit effective key , allowing variable-length messages grouped into 64-bit blocks, with the final partial block padded with zeros if necessary, and mandates iterative starting from an of zero. FIPS 113 emphasizes the algorithm's role in detecting unauthorized modifications in computer data, but it was withdrawn on September 1, 2008, following the deprecation of DES. The (ISO) and (IEC) formalized CBC-MAC more broadly in ISO/IEC 9797-1:2011, which outlines six MAC algorithms using an n-bit and a secret key to generate an m-bit MAC, with the first mechanism directly corresponding to standard CBC-MAC. This standard supports block ciphers of various sizes (e.g., 64-bit or 128-bit blocks) and specifies three methods—basic (zero-padding), CBC (per ISO 10118-1 with '1' bit followed by zeros), and length prepending—along with optional truncation of the MAC output to reduce length while maintaining security, along with rules for key sizes matching the cipher (e.g., 128 bits for AES). ISO/IEC 9797-1 also includes variants like MAC Algorithm 2 (a modified CBC-MAC with additional processing) to enhance security against certain attacks, and it requires the to be zero for deterministic operation. For AES-based implementations, NIST Special Publication 800-38B (updated in 2016) defines the CMAC mode, a refinement of CBC-MAC that securely accommodates variable-length messages through subkey generation for padding the final block, using AES-128, AES-192, or AES-256 with corresponding key sizes of 128, 192, or 256 bits. As of April 2025, NIST has decided to revise SP 800-38B to update guidance on tag lengths and other aspects. This standard specifies that the MAC tag can be truncated to any length from 32 to 128 bits, with full 128-bit tags recommended for optimal security, and mandates a zero initialization vector while providing test vectors for verification. Complementing this, RFC 4493 (2006) from the Internet Engineering Task Force (IETF) standardizes AES-CMAC for Internet protocols, aligning with NIST SP 800-38B by detailing the same subkey derivation process (using AES in CBC mode with specific constants) and emphasizing its use for authenticating binary data up to 2^61 - 1 blocks. The transition to CMAC in these standards addresses vulnerabilities in plain CBC-MAC for variable lengths by ensuring distinct tags for distinct messages, without relying on length prepending. In the context of resource-constrained devices, ISO/IEC 29192-6:2019 specifies lightweight MAC algorithms based on block ciphers, including CBC-MAC variants tailored for low-power environments, supporting ciphers with 64-bit or 80-bit blocks and key sizes as small as 80 or 128 bits. This standard outlines padding rules similar to ISO/IEC 9797-1 but optimized for minimal computational overhead, allows tag truncation to 32 bits or more, and requires secure to achieve at least 80-bit security levels, making it suitable for applications.

Common Implementations

CBC-MAC and its secure variants, such as CMAC, are implemented in prominent cryptographic software libraries to facilitate message authentication in various applications. In , a widely used open-source toolkit, CMAC is supported via the EVP_MAC-CMAC interface, which leverages underlying CBC-mode ciphers like AES-128-CBC for computation. Raw CBC-MAC can also be derived using functions such as EVP_aes_128_cbc with a fixed zero , though this requires careful handling to avoid security pitfalls. Similarly, the Bouncy Castle library for provides the CBCBlockCipherMac class, which constructs a standard MAC from any in CBC mode, defaulting to zero when unspecified. In hardware implementations, CBC-MAC is integrated into FPGA IP cores, particularly for AES-based modes like CCM, which employs CBC-MAC for message integrity. Vendors such as Helion Technologies offer configurable AES-CCM cores supporting ASIC and FPGA platforms, enabling efficient deployment in high-throughput environments. For resource-constrained devices like smart cards, CBC-MAC is utilized in payment standards to generate application cryptograms, ensuring secure transaction authentication during card-reader interactions. Protocol-level deployments of CBC-MAC variants appear in legacy and specialized contexts. In , the AES-XCBC-MAC-96 algorithm, a modified CBC-MAC, provides for Encapsulating Security Payload (ESP) and Authentication Header (AH) protocols, as standardized in RFC 3566. AES-CMAC-96 extends this for broader use in , offering enhanced security for variable-length messages per RFC 4494. While modern protocols increasingly favor alternatives like Poly1305 for speed—such as in —CBC-MAC persists in embedded systems for its simplicity and low overhead in fixed-block scenarios. A key challenge in CBC-MAC implementations is performance overhead relative to hash-based alternatives like , stemming from sequential invocations that limit parallelism and increase latency in software. Benchmarks indicate -SHA256 achieves superior efficiency over AES-CBC-MAC, as shown in evaluations for where -SHA256 outperforms AES-CBC-MAC. To mitigate vulnerabilities in variable-length messages, best practices recommend adopting CMAC, a NIST-approved refinement of CBC-MAC that incorporates subkey tweaks for provable security.

References

Add your contribution
Related Hubs
User Avatar
No comments yet.