06. Block Cipher Modes of Operation

Block ciphers encrypt single blocks of data, but many applications require multiple blocks to be encrypted sequentially and breaking the plaintext into blocks and encrypting them separately can be insecure.

Modes of operation are standardized with different security and efficiency characteristics.

NIST has many standards (e.g. SP 800-38 series) for this.

Important Features of Different Modes

Different modes can provide confidentiality, authentication (and integrity) or both.

Modes for confidentiality normally include randomization.

Different modes have different efficiency and communication properties.

Randomized Encryption

Problem: the same plaintext block is encrypted to the same ciphertext block every time - allows patterns to be found in long ciphertexts.

Prevention: randomizing encryption schemes by using an initialization vector (IV) which propagates through the entire ciphertext. It may need to be either random or unique.

Alternatively, there could be a variable state which is updated with each block.

Efficiency

Parallel processing: encrypting/decrypting multiple plaintext/ciphertext blocks in parallel.

Error propagation: a bit error in the ciphertext which results in multiple bit errors in the plaintext after decryption.

Padding

Requiring the plaintext to consist of complete blocks.

NIST suggested padding method: append a single 11 bit to the data string, then with 00s until the last block is completed.

Notation

Modes can be applied to any block cipher.

Confidentiality Modes

Electronic Code Book (ECB) Mode

A basic mode of a block cipher; each block is encrypted with a key, IV is not used.

Encryption

Ct=E(Pt,K) C_t = E(P_t, K)

Decryption

Pt=D(Ct,K) P_t = D(C_t, K)

Properties

Randomized Padding IV Parallel encryption Parallel decryption
No Required None Yes Yes

Error propagation: within blocks.

Cipher Block Chaining (CBC) Mode

Blocks chained together: the plaintext XORed with previous ciphertext (or IV for the first block) and then encrypted.

Encryption

Ct=E(PtCt1,K) C_t = E(P_t \oplus C_{t - 1}, K)

for 1tn1 \le t \le n where C0=IVC_0 = IV.

Decryption

Pt=D(Ct,K)Ct1 P_t = D(C_t, K) \oplus C_{t - 1}

Where C0=IVC_0 = IV.

Properties

Randomized Padding IV Parallel encryption Parallel decryption
Yes Required Random No Yes

Error propagation: within blocks and into specific bits in the next block.

Parallel decryption means that decryption does not require the plaintext of previous block. However, it does require the ciphertext of the previous block.

Commonly used for bulk encryption, was often used in TLS up to TLS 1.2.

Counter (CTR) Mode

Synchronous stream cipher mode.

Encryption

The counter and a nonce (IV) are initialized using a random value NN:

Tt=Nt T_t = N \| t

That is, TtT_t is the concatenation of the nonce NN with the block number tt.

Then, this result is encrypted with the key KK:

Ot=E(Tt,K) O_t = E(T_t, K)

Finally, it is XORed with the plaintext block PtP_t:

Ct=OtPt=E(Nt,K)Pt \begin{aligned} C_t &= O_t \oplus P_t \\ &= E(N \| t, K) \oplus P_t \end{aligned}

Decryption

Pt=OtCt P_t = O_t \oplus C_t

Properties

Randomized Padding IV Parallel encryption Parallel decryption
Yes Optional Unique Yes Yes

A one-bit change in ciphertext produces one-bit change in the plaintext at the same location.

This allows access to specific plaintext blocks without decrypting the whole stream.

CTR mode is the basis for authenticated encryption in TLS 1.2.

Authentication Mode

Message Integrity

Ensuring messages are not altered in transmission: preventing an adversary from re-ordering, replacing, replication and deleting message blocks to alter the received message.

Message integrity and authentication are treated as the same thing.

Proving message integrity is independent from using encryption for confidentiality.

Message Authentication Code (MAC)

T=MAC(M,K) T = \mathrm{MAC}(M, K)

Where MM is an arbitrary-length message and KK a secret key KK.

The output TT is a short, fixed-length tag.

Given both parties share the key KK:

MAC Properties

Only the sender and receiver can produce TT from MM.

If T=TT' = T, the receiver can conclude the message received is from the expected sender and has not been modified in transit. Otherwise, the receiver can conclude (M,T)(M', T) was not sent by the expected sender.

It has the basic security property of unforgeability: it is infeasible to produce MM and TT such that T=MAC(M,K)T = \mathrm{MAC}(M, K) without knowledge of KK.

Basic CBC-MAC

Using block cipher to create a MAC providing message integrity (but not confidentiality).

If PP is the message with nn blocks:

Ct=E(PtCt1,K) C_t = E(P_t \oplus C_{t - 1}, K)

For 1tn1 \le t \le n such that C0=IVC_0 = IV.

T=CBC-MAC(P,K)T = \mathrm{CBC\text{-}MAC}(P, K) is the last cyphertext: T=CnT = C_n.

It is unforgeable as long as the message length is fixed.

IVIV must be fixed and public (e.g. all zeroes): CBC-MAC with a random IV is NOT secure:

Cipher-based MAC (CMAC)

Standardized, NIST version of CBC-MAC. The IV is all zeroes. The below is as per RFC4493.

Two keys K1K_1 and K2K_2 are derived from the original key KK.

K1K_1 OR K2K_2 is XORed with MnM_n (with padding as necessary).

For 1tn11 \le t \le n - 1 and C0=IV=0000C_0 = IV = 00\dots00:

Ct=E(PtCt1,K) C_t = E(P_t \oplus C_{t - 1}, K)

For the final block:

Pn={K1Pn,block completeK2(Pn100002),block incomplete P_n' = \begin{cases} K_1 \oplus P_n , & \text{block complete} \\ K_2 \oplus (P_n \| 100\dots00_2), & \text{block incomplete} \end{cases}

(That is, PnP_n concatenated with 1 and then enough zeros to fill up a block)

Then do the same operation as with the previous blocks , except that PnP_n' is used:

Cn=E(PnCn1,K) C_n = E(P_n' \oplus C_{n - 1}, K)

Finally, CMAC(P,K)=MSBTlen(Cn)\mathrm{CMAC}(P, K) = \mathrm{MSB}_{Tlen}(C_n)​​

NIST allows the length of the tag, TlenTlen,​ to be any number of bits, although 64 bits or greater is recommended.

The standard recommends the MAC tag TT to be of at least length log2(lim/R)\mathrm{log}_2(lim/R) where:

Authenticated Encrypted Mode

Two types of input data:

NIST specifies two modes:

Both use CTR mode but add integrity in different ways.

Both are used in TLS 1.2 and 1.3.

Counter with CBC-MAC (CCM) Mode

CBC-MAC for authentication of all data, CTR mode encryption for the payload.

Inputs:

Compute the CBC-MAC tag, getting TT with length TlenTlen.

Split the message MM into blocks of 128128 bits. That is, into m=Plen/128m = \lceil Plen/128 \rceil blocks:

S=S0S1Sm S = S_0 \| S_1 \| \dots S_m

Then, use CTR mode to compute blocks.

C=(PMSBPlen(S))(TMSBTlen(S0)) C = (P \oplus \mathrm{MSB}_{Plen}(S)) \| (T \oplus \mathrm{MSB}_{Tlen}(S_0))

From RFC3610:

CCM Mode Format

Lengths of NN and PP are included in the first block.

If AA is non-zero, then formatted from the second block onwards, including its length.

e.g. TLS 1.2: TT 8 bytes, NN 12 octets, max payload size 22412^{24} - 1 bytes.