Skip to content
Trapdoor·Lab

AES: rounds and modes of operation

1Toy

A block through the rounds

AES is a block cipher: it transforms one 128-bit block at a time, and the key is 128, 192 or 256 bits long — which sets the number of rounds: 10, 12 or 14. Each round has four steps: SubBytes replaces bytes using the S-box, ShiftRows shifts the rows, MixColumns mixes the columns, and AddRoundKey adds (XOR) the round key; before the first round the block also gets round key 0, and the last round skips MixColumns.

Toy implementation — not for production useThis AES only shows the rounds of one block: no mode of operation, no protection against timing attacks. Real encryption on this site uses WebCrypto.

AES-128 step by step

16 / 16 B

AES encrypts 16-byte blocks. I pad shorter text with 00 bytes — this is about one block, not a mode of operation.

Too long by 0 B. Shorten the text — AES encrypts one 16-byte block.

Pplaintext 16 B of text + 0 B of 00 padding
00 4d656574206d65206174206e6f6f6e2e

Generating a key…

2Break it

The ECB penguin

A mode of operation decides how a block cipher handles a message longer than one block. ECB encrypts every block separately, so identical plaintext blocks give identical ciphertext blocks and patterns show through the ciphertext — hence the “ECB penguin”. CBC with an unpredictable IV and CTR with a counter that never repeats hide those patterns, but on their own they do not protect integrity: CBC without a MAC allows a padding oracle attack (Vaudenay, 2002), in which an attacker reads the data by sending modified ciphertexts and watching whether the receiver accepts the padding.

The ECB penguin

ECB encrypts each 16-byte block on its own, with the same key.

Encrypting the image…

Pplaintext image

Repeated blocks: 3935 of 4096 (distinct: 161)

CECB ciphertext

Image 256 × 256 px, 1 byte per pixel: each row is 16 blocks of 16 pixels. A ciphertext byte = a shade of grey.

3In the real world

Where AES and its modes run

  • FIPS 197The 2001 NIST standard — updated in 2023 with no change to the algorithm itself — defines AES-128, AES-192 and AES-256, which transform data in 128-bit blocks.Source (FIPS 197)
  • NIST SP 800-38AThe 2001 NIST recommendation describes five confidentiality modes — ECB, CBC, CFB, OFB and CTR — and warns that in ECB the same plaintext block always gives the same ciphertext block.Source (NIST SP 800-38A)
  • Zoom (2020)Citizen Lab found that Zoom encrypted audio and video with a single AES-128 key in ECB mode, shared by all participants in a meeting, although its documentation spoke of AES-256.Source (Zoom (2020))
  • Zoom 5.0In April 2020 Zoom 5.0 added 256-bit AES-GCM encryption, with enablement for all accounts announced for 30 May 2020.Source (Zoom 5.0)
  • TLS 1.3TLS 1.3 removed legacy symmetric algorithms, including the AES-CBC suites — only AEAD algorithms remain: AES-GCM, AES-CCM and ChaCha20-Poly1305.Source (TLS 1.3)
  • BitLockerWindows drive encryption uses the XTS-AES mode — with a 128-bit key by default — and Microsoft recommends XTS-AES for all drives.Source (BitLocker)
4Take it to your project

Choose an authenticated mode

Good practice

Encrypt with an AEAD mode — AES-GCM or ChaCha20-Poly1305 — which produces, along with the ciphertext, a tag that detects any change (details at the AES-GCM station). If you have to stay with CBC or CTR, do encrypt-then-MAC: compute an HMAC over the IV and ciphertext and check it before you decrypt anything — as Microsoft advises.

JavaScript
const iv = crypto.getRandomValues(new Uint8Array(12));
const ciphertext = await crypto.subtle.encrypt(
  { name: 'AES-GCM', iv },
  key,
  data,
);
Anti-pattern

Do not use ECB for anything longer than one block, CBC without a MAC, or CTR with a counter that can repeat — two ciphertexts under the same counter reveal the XOR of their plaintexts.

C#
// ✕ ECB: identical blocks, identical ciphertext
using var aes = Aes.Create();
aes.Key = key;
byte[] c = aes.EncryptEcb(data, PaddingMode.PKCS7);
JavaScript
// ✕ CTR: the same counter for every message
const counter = new Uint8Array(16);
await crypto.subtle.encrypt(
  { name: 'AES-CTR', counter, length: 64 },
  key,
  data,
);