A Bluffer’s Guide To AES Modes … ECB, CBC, CFB, and all that jazz!

Well, in its core form AES is a block cipher, but increasingly it is converted into a stream cipher in order to speed things up. For AES…

Photo by Alp Duran on Unsplash

A Bluffer’s Guide To AES Modes … ECB, CBC, CFB, and all that jazz!

Well, in its core form AES is a block cipher, but increasingly it is converted into a stream cipher in order to speed things up. For AES, the main things you need to know are:

  • The block size. The block size is typically either 128 bits (16 bytes) or one bit. With a 16-byte block size, we have a block cipher, and for a one-bit block size we have a stream cipher.
  • The key size. For the key size, we either have 128 bits, 192 bits or 256 bits.
  • The IV (Initialization Vector). With the IV (otherwise known as a salt value), we protect against the same plaintext linking to the same ciphertext. There are many options we can use, but basically, Bob and Alice will use the same encryption key on either side.

So let’s quickly do a quick analysis of the different modes we can get for AES:

  • ECB (Electronic Code Book). This no salt, and should never be seen. With this, the same plaintext will be mapped to the same ciphertext, for the same encryption key. More details here.
  • CBC (Cipher Block Chain): A proper block cipher mode, and where each block chains into the next one. With this, we use a 16-byte IV. More details here.
  • CFB (Cipher Feedback), CFB1, CFB8, OFB (Output Feedback), CTR (Counter). These convert the block mode into a stream cipher, and thus have a block size of just one bit. As with CBC, we use a 16-byte IV. More details here.
  • OCB (Offset codebook mode). This is a stream cipher, and add an authentication tag. It also has a 16-byte IV (128 bits).
  • XTS (XEX-based tweaked-codebook mode with ciphertext stealing). This is used in disk encryption. See here.
  • GCM (Galois Counter Mode). It integrates an authentication tag for AEAD (Authenticated Encryption with Additional Data). It has a 12-byte IV (96 bits). See here.
  • CCM (Cipher block chaining — message authentication code). This is a stream cipher that integrates CBC-MAC authentication and thus creates a message authentication code, along with having a counter mode approach. It has a 12-byte IV (96 bits).

So, I’ve created a Node.js program to implement each of these modes:

I have used PBKDF2 to generate the encryption key, and a fixed salt value (“salt”). A random IV is also generated. Here is a sample run:

https://asecuritysite.com/node/node_encrypt2

and here’s some more AES:

https://asecuritysite.com/aes/