Definition
A block cipher is a pair of keyed algorithms §14.1, encryption and decryption, that work on blocks: bit strings of one fixed length . Encryption turns a secret key and an -bit plaintext block into an -bit ciphertext block; decryption with the same key returns the plaintext block. For each key, encryption is therefore a permutation, a one-to-one rearrangement of all -bit blocks. AES (Advanced Encryption Standard), with and keys of 128, 192 or 256 bits, is the standard example. A mode of operation extends a block cipher to messages.
The idea
A block cipher solves a narrow problem. It transforms one short block so that, without the key, the result looks unrelated to the input, and with the key, the transformation can be undone exactly. Cryptographers study this small building block intensely and model a good block cipher as a pseudorandom permutation §15.2: under a random secret key, it cannot feasibly be told apart from a rearrangement of all -bit blocks chosen uniformly at random.
For one key, a block cipher acts as a codebook: a table that pairs each of the possible plaintext blocks with its ciphertext block. The table is far too large to write down, since for it has rows, so the cipher computes any row from the key. The picture shows the weakness of using the codebook directly: the same plaintext block always looks up to the same ciphertext block.
Real data is not one block. A sender has a 20-byte sensor reading, a 32-byte command or a 1-MiB file. Turning one-block encryption into a secure message format raises questions that the block cipher does not answer: how to split a message and fill a last block that is too short, how to make equal blocks and equal messages encrypt differently, how to let the receiver detect a changed or rearranged ciphertext, and how to reject an old message sent again. A mode of operation, a rule for applying the block cipher to many blocks, answers the first two questions. Authentication §1.6 and replay protection need further mechanisms.
How it works
The interface.
Encryption inputs: a key of bits and a plaintext block of bits.
Encryption output: a ciphertext block of bits.
Decryption: , with the same key.
Inside. Almost every block cipher repeats a simple transformation, called a round, many times. A key schedule expands the key into one round key per round. Two designs dominate. A substitution-permutation network replaces small pieces of the block through fixed tables and then mixes the pieces, and every one of its steps is invertible; AES works this way, as the AES round structure §15.4 entry describes. A Feistel network splits the block into two halves and in each round combines a keyed function of one half into the other half, which is invertible whatever that function is; DES (Data Encryption Standard), the United States standard block cipher of 1977 [364], works this way.
From block to message. NIST Special Publication (SP) 800-38A defines five modes of operation for confidentiality §1.8. Three of them show the main ideas. Here are the plaintext blocks, the ciphertext blocks, and is bitwise XOR (exclusive or), which gives 1 in each bit position where the two inputs differ.
ECB (electronic codebook) encrypts each block separately: . Equal plaintext blocks give equal ciphertext blocks.
CBC §15.6 (cipher block chaining) XORs each plaintext block with the previous ciphertext block before encrypting it: . The first block uses an initialization vector , a block that is sent with the message and must be unpredictable to an attacker. The message must be padded to a whole number of blocks.
CTR §15.5 (counter mode) encrypts a sequence of distinct counter blocks and XORs the outputs onto the message. It needs no padding, and decryption uses only .
None of these modes lets the receiver detect a change to the ciphertext. Authenticated encryption §5.16 closes that gap: it adds a tag, a short value computed with the key that the receiver checks before accepting the plaintext. GCM (Galois/Counter Mode) and CCM §5.17 (counter with cipher block chaining message authentication code) are the common schemes built on a block cipher. Replay protection, such as a message counter that the receiver checks, comes from the protocol on top.
Worked example
ECB shows equal blocks. FIPS 197, the AES standard, gives this example for AES with a 128-bit key : the plaintext block encrypts to the ciphertext block , all written in hexadecimal.
=
000102030405060708090a0b0c0d0e0f
=00112233445566778899aabbccddeeff
=69c4e0d86a7b0430d8cdb78070b4c55a
Now encrypt a 32-byte message that consists of twice. AES blocks are 16 bytes, so the message is blocks. ECB encrypts each block separately, so the ciphertext is twice: , where joins two blocks end to end. An observer without the key sees two equal ciphertext blocks and learns that the two plaintext blocks are equal. In a table of records or a bitmap image, such equalities reveal the structure of the plaintext.
A short last block. A 20-byte message needs blocks, where means rounded up to a whole number: one full block of 16 bytes and further bytes. ECB and CBC can encrypt only whole blocks, so the second block must be filled. The padding rule of PKCS #7 (Public-Key Cryptography §5.15 Standards number 7) appends bytes, each with the value 12 (0x0c); the receiver reads the last byte and removes that many bytes. A message that already fills whole blocks gets a full extra block of 16 bytes with the value 16, so that the rule is never ambiguous. The ciphertext is 32 bytes. CTR instead uses the first 20 bytes of a 32-byte keystream and produces 20 bytes of ciphertext.
Correct is not secure. Take a toy block cipher with 4-bit blocks and 4-bit keys: . With and , the ciphertext is . Decryption XORs the key again: , the original block. The toy cipher is correct. One known pair of plaintext and ciphertext breaks it: .
Stated precisely
A block cipher with key length and block length is a pair of deterministic algorithms such that This correctness condition forces to be one-to-one, hence a permutation of the blocks, for every key .
Security is a separate claim, stated as pseudorandom-permutation security: when is chosen uniformly at random and kept secret, no adversary that runs for at most steps and asks for at most encryptions can tell apart from a uniformly random permutation with advantage above . The advantage is the difference between the probabilities that the adversary answers “real” in the two cases, and , and are stated together. Nobody proves this for a real block cipher. For AES it is a conjecture supported by more than two decades of public analysis, and the security proofs of modes of operation assume it.
Encryption of messages has a different and stronger contract. The usual one is indistinguishability under chosen-plaintext attack. An attacker who may obtain encryptions of messages of the attacker’s choice picks two messages and of equal length. A hidden fair coin selects one of them, and the attacker receives its encryption. The attacker must not be able to guess which message was encrypted with probability above , for a small stated . No deterministic scheme, one in which the same key and message always give the same ciphertext, meets this contract: the attacker obtains the encryption of beforehand and compares. ECB is deterministic and fails. A secure mode adds a random initialization vector or a nonce §5.18, a value never used twice with one key.
Ciphertext integrity §1.9, meaning that the receiver rejects every ciphertext that the key holder did not produce, is a third contract. Neither the block cipher nor ECB, CBC or CTR provides it.
Limits and common mistakes
A longer key does not give a larger block. AES-256 still encrypts 16-byte blocks. The block length, not the key length, sets how much data one key may protect before the birthday bound §5.6 makes repeated blocks likely: about blocks, which is blocks for AES and blocks for 64-bit block ciphers such as Triple DES.
Do not invent modes or use them outside their rules. ECB reveals equal blocks. CBC without a message authentication code §5.7 falls to padding oracle attacks, in which the receiver’s different reactions to correct and incorrect padding let an attacker decrypt a message byte by byte (Vaudenay, 2002 [365]). CTR with a repeated counter block reveals the XOR of two plaintexts.
An attacker can reorder, delete or repeat ECB ciphertext blocks, and the receiver decrypts the result without noticing. In CBC and CTR, flipping chosen ciphertext bits flips predictable plaintext bits.
A block cipher is neither a hash function nor a message authentication code, although both can be built from one. CMAC §15.7 (cipher-based message authentication code) is a message authentication code built from a block cipher.
Correct mathematics can still leak the key through a side channel §1.29. AES implemented with lookup tables indexed by secret data leaks key bits through cache timing (Bernstein, 2005 [336]). Use processor instructions for AES or a constant-time implementation §5.36, one whose timing and memory accesses do not depend on secret data.
The security model assumes independent, uniformly random keys. A key taken directly from a password, or keys with a known relation to one another, fall outside it.
Questions answered
Why is a block cipher alone not an arbitrary-length secure-message format?
A block cipher alone is not a secure message format because it encrypts exactly one block of a fixed length, bits (128 bits for AES, the Advanced Encryption Standard), and encrypts it deterministically, whereas a message format must handle any length, hide repetition and let the receiver reject altered or replayed messages. Applying the cipher to each block separately, the electronic codebook (ECB) mode, shows the gaps. A message whose length is not a multiple of needs padding or a different construction. Equal plaintext blocks give equal ciphertext blocks, so patterns in the plaintext show through. An attacker can reorder, delete or repeat blocks without detection. Nothing stops a recorded message from being accepted again.
A secure format therefore adds three things: a mode of operation that uses a nonce (a value never repeated under one key) or a random initialization vector; a tag that the receiver checks, which covers the ciphertext and its header and is usually provided by one authenticated encryption scheme; and a replay rule, such as a message counter that the receiver checks.
Related entries: Pseudorandom permutation (PRP) (§15.2), AES round structure (§15.4), Authenticated encryption (AEAD) (§5.16), Counter mode (CTR) (§15.5), Cipher block chaining (CBC) (§15.6), Cipher-based MAC (CMAC) (§15.7). Further reading: [47, 66, 137, 336, 364, 365].