21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

that the state function is always replaced by the ciphertext of the previous block. See<br />

Figure 5-2 for a graphical view of CFB mode.<br />

1<br />

2<br />

Figure 5-2. CFB mode<br />

key<br />

leftmost<br />

byte<br />

Buffer<br />

Block<br />

cipher<br />

p c<br />

Encrypted buffer<br />

Buffer<br />

= XOR<br />

3 p = input plaintext byte<br />

byte shift<br />

c = output ciphertext byte<br />

c<br />

The block size of the cipher is important to CFB mode because keystream is produced<br />

in block-sized chunks and therefore requires keeping track of block-sized portions<br />

of the ciphertext. CFB is fundamentally a streaming mode, however, because<br />

the plaintext is encrypted simply by XOR’ing with the CFB keystream.<br />

In Recipe 5.4, we discuss the advantages and drawbacks of CFB and compare it to<br />

other popular modes.<br />

These days, CFB mode is rarely used because CTR and OFB modes (CTR mode in<br />

particular) provide more advantages, with no additional drawbacks. Of course, we<br />

recommend a higher-level mode over all of these, one that provides stronger security<br />

guarantees—for example, CWC or CCM mode.<br />

Many libraries already come with an implementation of CFB mode for any ciphers<br />

they support. However, some don’t. For example, you may only get an implementation<br />

of the raw block cipher when you obtain reference code for a new cipher.<br />

In the following sections we present a reasonably optimized implementation of CFB<br />

mode that builds upon the raw block cipher interface presented in Recipe 5.5. It also<br />

requires the spc_memset( ) function from Recipe 13.2.<br />

Using a Generic CFB Mode Implementation | 187<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!