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.

Solution<br />

You can’t be very confident about the security of RC4 for general-purpose use, owing<br />

to theoretical weaknesses. However, if you’re willing to use only a very few RC4 outputs<br />

(a limit of about 100,000 bytes of output), you can take a risk, as long as you<br />

properly set it up.<br />

Before using the standard initialization functions provided by your cryptographic<br />

library, take one of the following two steps:<br />

• Cryptographically hash the key material before using it.<br />

• Discard the first 256 bytes of the generated keystream.<br />

After initialization, RC4 is used just as any block cipher in a streaming mode is used.<br />

Most libraries implement RC4, but it is so simple that we provide an implementation<br />

in the following section.<br />

Discussion<br />

RC4 is a simple cipher that is really easy to use once you have it set up securely,<br />

which is actually difficult to do! Due to this key-setup problem, RC4’s theoretical<br />

weaknesses, and the availability of faster solutions that look more secure, we recommend<br />

you just not use RC4. If you’re looking for a very fast solution, we recommend<br />

SNOW 2.0.<br />

In this recipe, we’ll start off ignoring the RC4 key-setup problem. We’ll show you<br />

how to use RC4 properly, giving a complete implementation. Then, after all that,<br />

we’ll discuss how to set it up securely.<br />

As with any other symmetric encryption algorithm, it is particularly<br />

important to use a MAC along with RC4 to ensure data integrity. We<br />

discuss MACs extensively in Chapter 6.<br />

RC4 requires a little bit of state, including a 256-byte buffer and two 8-bit counters.<br />

Here’s a declaration for an RC4_CTX data type:<br />

typedef struct {<br />

unsigned char sbox[256];<br />

unsigned char i, j;<br />

} RC4_CTX;<br />

In OpenSSL, the same sort of context is named RC4_KEY, which is a bit of a misnomer.<br />

Throughout this recipe, we will use RC4_CTX, but our implementation is otherwise<br />

compatible with OpenSSL’s (our functions have the same names and<br />

parameters). You’ll only need to include the correct header file, and alias RC4_CTX to<br />

RC4_KEY.<br />

234 | Chapter 5: Symmetric Encryption<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!