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
Notation
- Plaintext message
of length blocks -
-th plaintext block for - Ciphertext message
-
-th ciphertext block for - Key
- Initialization vector
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
Decryption
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
for
Decryption
Where
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
That is,
Then, this result is encrypted with the key
Finally, it is XORed with the plaintext block
Decryption
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)
Where
The output
Given both parties share the key
- The sender computes
- The message
and tag are sent - The receiver computes
on the received message and checks that
MAC Properties
Only the sender and receiver can produce
If
It has the basic security property of unforgeability: it is infeasible to produce
Basic CBC-MAC
Using block cipher to create a MAC providing message integrity (but not confidentiality).
If
For
It is unforgeable as long as the message length is fixed.
- If the IV is random, the IV needs to be sent along with the MAC
-
- Hence, the attacker can modify
and together such that XORing them gives the same result. As is not modified, none of the subsequent ciphertexts (and hence the tag) stays unchanged
Cipher-based MAC (CMAC)
Standardized, NIST version of CBC-MAC. The IV is all zeroes. The below is as per RFC4493.
Two keys
For
For the final block:
(That is, 1 and then enough zeros to fill up a block)
Then do the same operation as with the previous blocks , except that
Finally,
NIST allows the length of the tag,
The standard recommends the MAC tag
-
is a limit on how many invalid messages are detected before is changed -
is the acceptable probability that a false message is accepted
Authenticated Encrypted Mode
Two types of input data:
- Payload: both encrypted and authenticated
- Associated data: only authenticated
NIST specifies two modes:
- NIST SP-800-38C (2004) for Counter with CBC-MAC
- NIST SP-800-38D (2007) for Galois/Counter (GCM)
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:
- Nonce
for CTR mode - Payload
of bits - Associated data
Compute the CBC-MAC tag, getting
Split the message
Then, use CTR mode to compute blocks.
From RFC3610:
- Authentication using CBC-MAC:
-
Blocks
generated. contains the metadata such as the nonce, payload length etc. Later blocks contain the payload and associated data.
-
- Encryption using CTR mode:
- Generate a keystream
where is the block number. - Output message
. starts with , not - Output authentication value
- Generate a keystream
- Decryption requires key
, nonce , authenticated data and ciphertext - Authenticated data must be sent separately!
CCM Mode Format
Lengths of
If
e.g. TLS 1.2: