ECB vs. CBC – Pros and Cons of These Block Cipher Modes
Block nothing modes of process are designed to allow encoding of data that is besides long to fit in a single block of a block zero. While a assortment of auction block ciphers exist, this article will explore the pros and cons of the ECB and CBC block cipher modes of operation .
What is a Block Cipher Mode of Operation?
Cryptographic algorithms come in a few different forms. The major breakdown is between symmetrical and asymmetrical cryptography. symmetrical encoding uses the lapp secret key for both encoding and decoding, while asymmetrical cryptanalysis ( besides known as public keystone cryptanalysis ) uses a match of relate public and secret keys .
Within the symmetrical encoding category are blocking and current ciphers. Block ciphers encrypt data in fixed-size blocks, while stream ciphers generate a pour of bits that are exclusive-ored with the plaintext to produce the ciphertext .
Block ciphers are designed to encrypt a single fixed-size collocate of data, which presents issues for plaintexts that are not precisely the correct length. Padding helps to solve the offspring of undersize plaintexts, while block cipher modes of operation handle ones that span multiple blocks.
A freeze code mode of operation defines how the different blocks of a multi-block plaintext should be encrypted and decrypted. By agreeing on a block nothing mode of operation ( like ECB or CBC mode ), the transmitter and recipient role of a message ensure that they do things the same way and that the data decrypts correctly .
How Does ECB Mode Work?
ECB mode is the simplest block cipher mode of operation in being. Its approach to multi-block plaintexts is to treat each engine block of the plaintext individually .
Figure 1. The image above shows how ECB manner works. Note that encryption/decryption of one block has no effect on the encryption/decryption of any other. While ECB is the simplest obstruct code mood of mathematical process to implement, it besides has its issues .
Figure 2. The prototype above shows the ciphertext result from the encoding of Tux, the Linux penguin, using ECB mode. Notice that the penguin is silent visible even though the colors are distorted .
The reason that this happens is that, with ECB manner, encrypting identical plaintext blocks produces identical ciphertext blocks. In this lawsuit, each pixel is an autonomous freeze of plaintext containing the color of that pixel. Since, in this image, many of the pixels have the same color, those identical blocks encrypt to identical ciphertext blocks. As a result, Tux is still visible in the ciphertext .
While this is an extreme example, it demonstrates the limitations of ECB mode for data encoding. While ECB manner is faster, easier, and more parallelizable to implement, it leaks data about the implicit in message being encrypted. Simply by observing the ciphertexts ( which are public information ), an eavesdropper can identify identical blocks and make guesses about the original plaintext .
How Does CBC Mode Work?
ECB mood ’ s issues arise from the fact that each stuff of the plaintext is encrypted wholly independently. CBC mode eliminates this trouble by carrying information from the encoding or decoding of one obstruct to the next.
Read more: A Few Thoughts on Cryptographic Engineering
Figure 3. The prototype above shows how CBC modality works. For the encoding of the initial block, an IV is generated. This IV should be an irregular, alone value that is openly transmitted to the recipient. It is not a confidential .
This IV is XORed with the plaintext before passing it to the encoding algorithm. The resulting ciphertext is then used to carry information to the encoding of the next forget and so on .
This relationship between blocks helps to protect against identical plaintext blocks producing identical ciphertext blocks. Since each block of the plaintext is XORed with a different IV before encoding, it produces a alone ciphertext. This means that an attacker observing the string of ciphertexts can ’ triiodothyronine learn anything from the fact that two ciphertext blocks are identical .
A major advantage of CBC mode is that, while encoding must be performed consecutive, decoding can be parallelized. The foremost IV is a public value and all early blocks use a ciphertext as an IV, which are public. This can make decoding faster than other blocking cipher modes of operation .
Which One Should I Choose?
ECB and CBC are two of several different block nothing modes of operation. Each of these modes has its own pros and cons and selecting the right one depends on the needs of the project. For exercise, ECB and CBC mode provide confidentiality, while other modes, such as Galois Counter Mode ( GCM ), provide both confidentiality and integrity security .
Between ECB and CBC mode, it is always better to choose CBC mode. As discussed above, ECB mode leaks information about the plaintext because identical plaintext blocks produce identical ciphertext blocks. A ciphertext should never leak any information about the plaintext used to create it, so ECB mode is insecure and should never be used.
CBC modality, on the other hand, is one of the most normally secondhand block cipher modes of process due to its ease of implementation and support for parallelize decoding. however, when using CBC mood, it is essential that it be implemented correctly. improperly implemented pad of ciphertexts can leave the organization vulnerable to attacks like POODLE .
While CBC modality is better than ECB, GCM is better than both. In addition to providing hard confidentiality protections without the security issues known to exist in ECB and CBC mood, it besides protects the integrity of the encrypted data by generating a message authentication code ( MAC ) as separate of the encoding algorithm .
For this reason, the Ubiq platform uses the GCM stuff cipher manner of operation. For more information about painlessly integrating hard cryptography into your applications, check out the Ubiq cryptanalysis libraries .