Daily Archives: March 16, 2018


The previous two cipher modes of AES I wrote into WjCryptLib were AES-CTR and AES-OFB. Both of these turn AES into stream ciphers. In both cases only the AES block encrypt function is used. So today I add AES-CBC (Cipher Block Chaining) mode to the library. I don’t particularly like CBC as a mode personally, however it is one of the most common modes used so I wanted to include it in the library.

Cipher Block Chaining mode works by XORing the previous cipher block onto the plaintext before performing the block encrypt. An IV is used as the first “previous cipher block”. A change in a byte of plaintext will cause all the following cipher text to be different. A disadvantage of the mode is that it has to work with whole number of blocks (16 bytes in the case of AES). This limitation is usually overcome by padding the last block and keeping a count value of the actual data. There is also a fancier technique called cipher text stealing which reduces the limitation to only requiring a minimum of a a single block. I have not included this technique I my implementation.

CBC is not a stream cipher mode, as in it does not generate a parallel stream of bytes that are then applied (usually with XOR) onto the input stream. CBC uses the block encrypt and decrypt block functions on the input data.

I have released WjCryptLib 2.3.0 which contains AES-CBC.

The relevant source files needed are:

This is free and unencumbered software released into the public domain.