Block cipher simulator

AES Engine Lab

AES, the Advanced Encryption Standard (NIST FIPS-197), is the cipher an encrypting SSD runs on every block it writes. Walk one block through it, then see what the drive adds: a tweak from each sector’s address, a media key locked under your password, and an erase that takes no time at all.

The example block after AES: 16 scrambled bytes, shown in hex.00112233...eeff under key 00010203...0f, after 10 rounds

The walkthrough

From one block to a locked drive

Five steps, all live

Every step is on screen from the start. Change a setting and only the picture beside it changes.

One block, every step

AES lays 16 bytes out as a 4 by 4 grid and runs it through rounds of four moves. Step through them, then pick a byte in the After grid to see its arithmetic.

Key size
Direction

Demo only: the key goes into the address bar and any link you copy. Never type a real key here.

Step 1

Before

Round key

After pick a byte

Ciphertext

Round keys

One key in, one round key per round out. The row for the step on screen is marked, and any word shows how it was made.

Why so many rounds?

Flip one bit of the plaintext or the key and count how many of the 128 output bits change after each round. A strong cipher spreads the change to about half the bits and keeps it there.

Flip a bit of the

The two ciphertexts, bit by bit (marked where they differ)

Bits that differ between the two runs after each round. The dashed line is 64, half the block.
Bits that differ after each round
RoundBits that differ

Inside the SSD

AES-XTS, key wrapping, crypto erase

A self-encrypting SSD runs AES in hardware between the host interface and the flash, so the NAND only ever holds ciphertext. This is a demo, and its keys are predictable on purpose.

Why not encrypt every block the same way?

ECB encrypts each 16-byte block on its own, so equal blocks give equal ciphertext and the shape survives. XTS also mixes in the sector number and the block position, and the shape is gone.

How the drive encrypts
What the host writes
What the flash holds
What the host reads back

Same data, different address

XTS encrypts the sector's LBA into a tweak and folds it into every block. Write the same 512 bytes to two addresses and the flash holds unrelated ciphertext.

First tweak

Ciphertext, first 32 bytes

First tweak

Ciphertext, first 32 bytes

Passwords and instant erase

The password only unlocks a media key that never leaves the drive. Changing it rewrites the wrapped key, and a crypto erase replaces the media key so the old data reads as noise.

Demo only: shown in clear, with a fixed salt. Never type a real password here.

Wrapped media key (what the drive stores)
Key in use
On the flash at LBA 8
What the host reads

How the model works

The cipher is real AES as FIPS-197 defines it, for 128, 192 and 256-bit keys, and its outputs are checked against the standard's test vectors. XTS follows IEEE 1619 and the key wrap follows RFC 3394; both are checked against published vectors and against OpenSSL.

Each round is four moves, with the FIPS-197 name beside each plain one. SubBytes swaps each byte through the S-box, ShiftRows slides rows 1, 2 and 3 left by one, two and three places, MixColumns blends each column, and AddRoundKey mixes in a round key with XOR. The last round skips MixColumns.

The key schedule stretches the key into one 16-byte round key per round, four 32-bit words at a time. The key itself fills the first words: all of round key 0, and for AES-192 and AES-256 part or all of round key 1 as well.

One round only stirs part of the block, because a change in one byte reaches one column at most. A key bit that first enters a later round key starts spreading later, which is why a key flip can lag a plaintext flip.

The picture is stored the way a drive stores data. Each row is one 512-byte sector and each 4 by 4 tile is one 16-byte block, and each ciphertext tile is drawn as one flat gray taken from its block's first byte, so equal blocks look equal. The pictures use their own fixed demo keys, not the key in step 1.

XTS takes the LBA as its tweak. The drive encrypts the sector number with the second half of the key, then shifts that value along for every block, so the same 512 bytes at two LBAs share nothing on the flash.

The media key is made inside the drive and never leaves it. The drive stores it wrapped (RFC 3394) under a key derived from the password, and in this lab's drive the 64-byte media key becomes 72 bytes once wrapped. Changing the password rewrites those 72 bytes, and replacing the media key makes every sector unreadable at once.

Terms

Sector
A sector is the smallest piece of a drive the host reads or writes, here 512 bytes. The drive encrypts each one on its own.
Ciphertext
Ciphertext is data after encryption. Without the key it looks like random bytes; with the key it turns back into the original, the plaintext.
Block
AES works on blocks of 16 bytes (128 bits). Longer data is cut into blocks, and a mode such as XTS decides how each one is encrypted.
Key
The key is the secret that steers the cipher. AES keys are 16, 24 or 32 bytes, and the same key encrypts and decrypts.
Hex
Hex writes each byte as two digits from 0 to 9 and a to f, so 255 is ff. Sixteen bytes take 32 hex digits.
Bit
A bit is a single 0 or 1. A byte is 8 bits, so a 16-byte AES block is 128 bits.
S-box
The S-box is a fixed table of 256 bytes. SubBytes swaps every byte for its entry, the one step in AES that is not simple arithmetic.
XOR
XOR compares two bits and gives 1 when they differ. XORing data with a key byte scrambles it, and XORing again with the same byte undoes it.
Round key
A round key is 16 bytes made from your key by the key schedule. AES-128 makes 11 of them: one before the first round and one for each round.
LBA
An LBA (logical block address) is the number of a sector as the host sees it. The drive decides where on the flash it really goes.
Tweak
A tweak is a public value mixed into the encryption next to the key. XTS uses the LBA, so the same data at two addresses encrypts differently.
ECB
ECB (electronic codebook) encrypts every block on its own with the same key. Equal blocks give equal ciphertext, which is why no drive uses it for data.
XTS
XTS is the AES mode self-encrypting drives use (IEEE 1619). It mixes the sector number and the block position into every block.
Self-encrypting drive
A self-encrypting drive (SED) encrypts everything it stores, in its controller, with a key that never leaves the drive.
Media key
The media key is the key that actually encrypts your data. The drive makes it inside and stores it only wrapped under a key from your password.

What it leaves out

  • It is a teaching model, not a crypto library.
  • Its table lookups depend on the data, so it is not constant-time.
  • Its drive keys are generated the same way every time, so the demo gives the same result on every visit.
  • Real controllers pipeline AES in hardware and manage keys through TCG Opal or similar.
  • Real controllers handle partial blocks with ciphertext stealing, and many report crypto-erased LBAs as unmapped.