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.

Without going into the technical details of the problems with RC4 key setup, it’s sufficient<br />

to say that the real problem occurs when you key multiple RC4 instances with<br />

related keys. For example, in some circles it is common to use a truncated base key,<br />

then concatenate a counter for each message (which is not a good idea in and of itself<br />

because it reduces the effective key strength).<br />

The first way to solve this problem is to use a cryptographic hash function to randomize<br />

the key. If your key is 128 bits, you can use MD5 and take the entire digest<br />

value, or you can use a hash function with a larger digest, such as SHA1 or SHA-256,<br />

truncating the result to the appropriate size.<br />

Here’s some code for setting up an RC4 context by hashing key material using MD5<br />

(include openssl/md5.h to have this work directly with OpenSSL’s implementation).<br />

MD5 is fine for this purpose; you can also use SHA1 and truncate to 16 bytes.<br />

/* Assumes you have not yet initialized the context, but have allocated it. */<br />

void secure_rc4_setup1(RC4_CTX *ctx, char *key) {<br />

char res[16]; /* 16 is the size in bytes of the resulting MD5 digest. */<br />

MD5(key, 16, res);<br />

RC4_set_key(ctx, 16, res);<br />

}<br />

Note that RC4 does not use an initialization vector.<br />

Another option is to start using RC4, but throw away the first 256 bytes worth of<br />

keystream. One easy way to do that is to encrypt 256 bits of garbage and ignore the<br />

results:<br />

/* Assumes an already instantiated RC4 context. */<br />

void secure_rc4_setup2(RC4_CTX *ctx) {<br />

char buf[256] = {0,};<br />

RC4(ctx, sizeof(buf), buf, buf);<br />

spc_memset(buf, 0, sizeof(buf));<br />

}<br />

5.24 Using One-Time Pads<br />

<strong>Problem</strong><br />

You want to use an encryption algorithm that has provable secrecy properties, and<br />

deploy it in a fashion that does not destroy the security properties of the algorithm.<br />

Solution<br />

Settle for more realistic security goals. Do not use a one-time pad.<br />

236 | 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!