Sitemap
Press enter or click to view image in full size

Member-only story

CTR Mode in AES

5 min readJan 11, 2025

--

In its purest form, AES is a block cipher of 128 bits, but most current applications convert it into a stream cipher mode, where we just need to use an XOR with the plaintext stream to create our ciphertext. Two of the most popular stream modes for AES are GCM and CTR.

It was in 1995 that Diffie and Hellman created the CTR mode [here]:

Press enter or click to view image in full size

Basically it converts the block cipher into a stream by creating a keystream using counter. This keystream should not repeat for a long time, as if it does, the ciphertext stream can be cracked. We can use any method to create the counter, but we mostly just increment it by one each time:

Reference: [here]

In the above, we can see we use a simple XOR operation between the plaintext and the block cipher. This makes the cipher fast, and easy to implement in hardware. Overall, though, we need to add a MAC (Message Authentication Code) to the ciphertext, as Eve can flip bits in the cipher:

--

--

Prof Bill Buchanan OBE FRSE
Prof Bill Buchanan OBE FRSE

Written by Prof Bill Buchanan OBE FRSE

Professor of Cryptography. Serial innovator. Believer in fairness, justice & freedom. Based in Edinburgh. Old World Breaker. New World Creator. Building trust.