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.