6.3 Modes of Operation

Suppose we have a block cipher. It can encrypt a block of plaintext of a fixed size, for example 64 bits. There are many circumstances, however, where it is necessary to encrypt messages that are either longer or shorter than the cipher’s block length. For example, a bank may be sending a terabyte of data to another bank. Or you might be sending a short message that needs to be encrypted one letter at a time since you want to produce ciphertext output as quickly as you write the plaintext input.

Block ciphers can be run in many different modes of operation, allowing users to choose appropriate modes to meet the requirements of their applications. There are five common modes of operation: electronic codebook (ECB), cipher block chaining (CBC), cipher feedback (CFB), output feedback (OFB), and counter (CTR) modes. We now discuss these modes.

6.3.1 Electronic Codebook (ECB)

The natural manner for using a block cipher is to break a long piece of plaintext into appropriately sized blocks of plaintext and process each block separately with the encryption function EK. This is known as the electronic codebook (ECB) mode of operation. The plaintext P is broken into smaller chunks P=[P1, P2, , PL] and the ciphertext is

C=[C1, C2, , CL]

where Cj=EK(Pj) is the encryption of Pj using the key K.

There is a natural weakness in the ECB mode of operation that becomes apparent when dealing with long pieces of plaintext. Say an adversary Eve has been observing communication between Alice and Bob for a long enough period of time. If Eve has managed to acquire some plaintext pieces corresponding to the ciphertext pieces that she has observed, she can start to build up a codebook with which she can decipher future communication between Alice and Bob. Eve never needs to calculate the key K; she just looks up a ciphertext message in her codebook and uses the corresponding plaintext (if available) to decipher the message.

This can be a serious problem since many real-world messages consist of repeated fragments. E-mail is a prime example. An e-mail between Alice and Bob might start with the following header:

Date: Tue, 29 Feb 2000 13:44:38 -0500 (EST)

The ciphertext starts with the encrypted version of “Date: Tu”. If Eve finds that this piece of ciphertext often occurs on a Tuesday, she might be able to guess, without knowing any of the plaintext, that such messages are e-mail sent on Tuesdays. With patience and ingenuity, Eve might be able to piece together enough of the message’s header and trailer to figure out the context of the message. With even greater patience and computer memory, she might be able to piece together important pieces of the message.

Another problem that arises in ECB mode occurs when Eve tries to modify the encrypted message being sent to Bob. She might be able to extract important portions of the message and use her codebook to construct a false ciphertext message that she can insert in the data stream.

6.3.2 Cipher Block Chaining (CBC)

One method for reducing the problems that occur in ECB mode is to use chaining. Chaining is a feedback mechanism where the encryption of a block depends on the encryption of previous blocks.

In particular, encryption proceeds as

Cj=EK(PjCj1), 

while decryption proceeds as

Pj=DK(Cj)Cj1, 

where C0 is some chosen initial value. As usual, EK and DK denote the encryption and decryption functions for the block cipher.

Thus, in CBC mode, the plaintext is XORed with the previous ciphertext block and the result is encrypted. Figure 6.1 depicts CBC.

Figure 6.1 Cipher Block Chaining Mode.

An illustration shows the stages of cipher block chaining mode.

The initial value C0 is often called the initialization vector, or the IV. If we use a fixed value for C0, say C0=0, and ever have the same plaintext message, the result will be that the resulting ciphertexts will be the same. This is undesirable since it allows the adversary to deduce that the same plaintext was created. This can be very valuable information, and can often be used by the adversary to infer the meaning of the original plaintext.

In practice, this problem is handled by always choosing C0 randomly and sending C0 in the clear along with the first ciphertext C1. By doing so, even if the same plaintext message is sent repeatedly, an observer will see a different ciphertext each time.

6.3.3 Cipher Feedback (CFB)

One of the problems with both the CBC and ECB methods is that encryption (and hence decryption) cannot begin until a complete block of plaintext data is available. The cipher feedback mode operates in a manner that is very similar to the way in which LFSRs are used to encrypt plaintext. Rather than use linear recurrences to generate random bits, the cipher feedback mode is a stream mode of operation that produces pseudorandom bits using the block cipher EK. In general, CFB operates in a k-bit mode, where each application produces k random bits for XORing with the plaintext. For our discussion, however, we focus on the eight-bit version of CFB. Using the eight-bit CFB allows one 8-bit piece of message (e.g., a single character) to be encrypted without having to wait for an entire block of data to be available. This is useful in interactive computer communications, for example.

For concreteness, let’s assume that our block cipher encrypts blocks of 64 bits and outputs blocks of 64 bits (the sizes of the registers can easily be adjusted for other block sizes). The plaintext is broken into 8-bit pieces: P=[P1, P2, ], where each Pj has eight bits, rather than the 64 bits used in ECB and CBC. Encryption proceeds as follows. An initial 64-bit X1 is chosen. Then for j=1, 2, 3, , the following is performed:

Oj=L8EK(Xj)Cj=PjOjXj+1=R56(Xj)  Cj, 

where L8(X) denotes the 8 leftmost bits of X, R56(X) denotes the rightmost 56 bits of X, and XY denotes the string obtained by writing X followed by Y. We present the CFB mode of operation in Figure 6.2.

Figure 6.2 Cipher Feedback Mode.

An illustration shows the different stages of cipher feedback mode.

Decryption is done with the following steps:

Pj=CjL8(EK(Xj))Xj+1=R56(Xj)  Cj.

We note that decryption does not involve the decryption function, DK. This would be an advantage of running a block cipher in a stream mode in a case where the decryption function for the block cipher is slower than the encryption function.

Let’s step through one round of the CFB algorithm. First, we have a 64-bit register that is initialized with X1. These 64 bits are encrypted using EK and the leftmost eight bits of EK(X1) are extracted and XORed with the 8-bit P1 to form C1. Then C1 is sent to the recipient. Before working with P2, the 64-bit register X1 is updated by extracting the rightmost 56 bits. The eight bits of C1 are appended on the right to form X2=R56(X1)C1. Then P2 is encrypted by the same process, but using X2 in place of X1. After P2 is encrypted to C2, the 64-bit register is updated to form

X3=R56(X2)C2=R48(X1)C1C2.

By the end of the 8th round, the initial X1 has disappeared from the 64-bit register and X9=C1C2C8. The Cj continue to pass through the register, so for example X20=C12C13C19.

Note that CFB encrypts the plaintext in a manner similar to one-time pads or LFSRs. The key K and the numbers Xj are used to produce binary strings that are XORed with the plaintext to produce the ciphertext. This is a much different type of encryption than the ECB and CBC, where the ciphertext is the output of DES.

In practical applications, CFB is useful because it can recover from errors in transmission of the ciphertext. Suppose that the transmitter sends the ciphertext blocks C1, C2, , Ck, , and C1 is corrupted during transmission, so that the receiver observes C˜1, C2, . Decryption takes C˜1 and produces a garbled version of P1 with bit errors in the locations that C˜1 had bit errors. Now, after decrypting this ciphertext block, the receiver forms an incorrect X2, which we denote X˜2. If X1 was (, , , , , , , ), then X2˜=(, , , , , , , C˜1). When the receiver gets an uncorrupted C2 and decrypts, then a completely garbled version of P2 is produced. When forming X3, the decrypter actually forms X˜3=(, , , , , , C˜1, C2). The decrypter repeats this process, ultimately getting bad versions of P1, P2, , P9. When the decrypter calculates X9, the error block has moved to the leftmost block of X˜9 as X˜9=(C˜1, C2, , C8). At the next step, the error will have been flushed from the X10 register, and X10 and subsequent registers will be uncorrupted. For a simplified version of these ideas, see Exercise 18.

6.3.4 Output Feedback (OFB)

The CBC and CFB modes of operation exhibit a drawback in that errors propagate for a duration of time corresponding to the block size of the cipher. The output feedback mode (OFB) is another example of a stream mode of operation for a block cipher where encryption is performed by XORing the message with a pseudorandom bit stream generated by the block cipher. One advantage of the OFB mode is that it avoids error propagation.

Much like CFB, OFB may work on chunks of different sizes. For our discussion, we focus on the eight-bit version of OFB, where OFB is used to encrypt eight-bit chunks of plaintext in a streaming mode. Just as for CFB, we break our plaintext into eight-bit pieces, with P=P1, P2, , . We start with an initial value X1, which has a length equal to the block length of the cipher, for example, 64 bits (the sizes of the registers can easily be adjusted for other block sizes). X1 is often called the IV, and should be chosen to be random. X1 is encrypted using the key K to produce 64 bits of output, and the leftmost eight bits O1 of the ciphertext are extracted. These are then XORed with the first eight bits P1 of the plaintext to produce eight bits of ciphertext, C1.

So far, this is the same as what we were doing in CFB. But OFB differs from CFB in what happens next. In order to iterate, CFB updates the register X2 by extracting the right 56 bits of X1 and appending C1 to the right side. Rather than use the ciphertext, OFB uses the output of the encryption. That is, OFB updates the register X2 by extracting the right 56 bits of X1 and appending O1 to the right side.

In general, the following procedure is performed for j=1, 2, 3, :

Oj=L8EK(Xj)Xj+1=R56(Xj)  OjCj=PjOj.

We depict the steps for the OFB mode of operation in Figure 6.3. Here, the output stream Oj is the encryption of the register containing the previous output from the block cipher. This output is then treated as a keystream and is XORed with the incoming plaintexts Pj to produce a stream of ciphertexts. Decryption is very simple. We get the plaintext Pj by XORing the corresponding ciphertext Cj with the output keystream Oj. Again, just like CFB, we do not need the decryption function DK.

Figure 6.3 Output Feedback Mode.

An illustration shows the different stages of output feedback mode.

So why would one want to build a stream cipher this way as opposed to the way the CFB stream cipher was built? There are a few key advantages to the OFB strategy. First, the generation of the Oj output key stream may be performed completely without any plaintext. What this means is that the key stream can be generated in advance. This might be desirable for applications where we cannot afford to perform encryption operations as the plaintext message arrives.

Another advantage lies in its performance when errors are introduced to the ciphertext. Suppose a few errors are introduced to Cj when it is delivered to the receiver. Then only those corresponding bits in the plaintext are corrupted when decryption is performed. Since we build future output streams using the encryption of the register, and not using the corrupted ciphertext, the output stream will always remain clean and the errors in the ciphertext will not propagate.

To summarize, CFB required the register to completely flush itself of errors, which produced an entire block length of garbled plaintext bits. OFB, on the other hand, will immediately correct itself.

There is one problem associated with OFB, however, that is common to all stream ciphers that are obtained by XORing pseudorandom numbers with plaintext. If Eve knows a particular plaintext Pj and ciphertext Cj, she can conduct the following attack. She first calculates

Oj=CjPj

to get out the key stream. She may then create any false plaintext Pj she wants. Now, to produce a ciphertext, she merely has to XOR with the output stream she calculated:

Cj=PjOj.

This allows her to modify messages.

6.3.5 Counter (CTR)

The counter (CTR) mode builds upon the ideas that were used in the OFB mode. Just like OFB, CTR creates an output key stream that is XORed with chunks of plaintext to produce ciphertext. The main difference between CTR and OFB lies in the fact that the output stream Oj in CTR is not linked to previous output streams.

CTR starts with the plaintext broken into eight-bit pieces, P=P1, P2, . We begin with an initial value X1, which has a length equal to the block length of the cipher, for example, 64 bits. Now, X1 is encrypted using the key K to produce 64 bits of output, and the leftmost eight bits of the ciphertext are extracted and XORed with P1 to produce eight bits of ciphertext, C1.

Now, rather than update the register X2 to contain the output of the block cipher, we simply take X2=X1+1. In this way, X2 does not depend on previous output. CTR then creates new output stream by encrypting X2. Similarly, we may proceed by using X3=X2+1, and so on. The jth ciphertext is produced by XORing the left eight bits from the encryption of the jth register with the corresponding plaintext Pj.

In general, the procedure for CTR is

Xj=Xj1+1Oj=L8EK(Xj)Cj=PjOj

for j=2, 3, , and is presented in Figure 6.4. The reader might wonder what happens to Xj if we continually add 1 to it. Shouldn’t it eventually become too large? This is unlikely to happen, but if it does, we simply wrap around and start back at 0.

Figure 6.4 Counter Mode.

An illustration shows the different stages of counter mode.

Just like OFB, the registers Xj can be calculated ahead of time, and the actual encryption of plaintext is simple in that it involves just the XOR operation. As a result, its performance is identical to OFB’s when errors are introduced in the ciphertext. The advantage of CTR mode compared to OFB, however, stems from the fact that many output chunks Oj may be calculated in parallel. We do not have to calculate Oj before calculating Oj+1. This makes CTR mode ideal for parallelizing.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset