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.

cryptographic one-way hash from a theoretical security point of view, and indeed,<br />

such a one-way hash is often good as a PRF.<br />

There are many different ad hoc solutions for doing key derivation, ranging from the<br />

simple to the complex. On the simple side of the spectrum, you can concatenate a<br />

base key with unique data and pass the string through SHA1. On the complex side is<br />

the PBKDF2 function from PKCS #5 (described in Recipe 4.10).<br />

The simple SHA1 approach is perhaps too simple for general-purpose requirements.<br />

In particular, there are cases where you one might need a key that is larger than the<br />

SHA1 output length (i.e., if you’re using AES with 192-bit keys but are willing to<br />

have only 160 bits of strength). A general-purpose hash function maps n bits to a<br />

fixed number of bits, whereas we would like a function capable of mapping n bits to<br />

m bits.<br />

PBKDF2 can be overkill. Its interface includes functionality to thwart passwordguessing<br />

attacks, which is unnecessary when deriving keys from secrets that were<br />

themselves randomly generated.<br />

Fortunately, it is easy to build an n-bit to m-bit PRF that is secure for key derivation.<br />

The big difficulty is often in selecting good distinguishers (i.e., information that differentiates<br />

parties). Generally, it is okay to send differentiating information that one side<br />

does not already have and cannot compute in the clear, because if an attacker tampers<br />

with the information in traffic, the two sides will not be able to agree on a working<br />

key. (Of course, you do need to be prepared to handle such attacks.) Similarly, it is<br />

okay to send a salt. See the sidebar, “Distinguisher Selection,” for a discussion.<br />

The easiest way to get a solid solution that will resist potentially practical attacks is<br />

to use HMAC in counter mode. (Other MACs are not as well suited for this task,<br />

because they tend not to handle variable-length keys.) You can also use this solution<br />

if you want an all-block cipher solution, because you can use a construction to convert<br />

a block cipher into a hash function (see Recipes 6.15 and 6.16).<br />

More specifically, key HMAC with the base secret. Then, for every block of output<br />

you need (where the block size is the size of the HMAC output), MAC the distinguishers<br />

concatenated with a fixed-size counter at the end. The counter should indicate<br />

the number of blocks of output previously processed. The basic idea is to make<br />

sure that each MAC input is unique.<br />

If the desired output length is not a multiple of the MAC output length, simply generate<br />

blocks until you have sufficient bytes, then truncate.<br />

The security level of this solution is limited by the minimum of the<br />

number of bits of entropy in the base secret and the output size of the<br />

MAC. For example, if you use a key with 256 bits of entropy, and you<br />

use HMAC-SHA1 to produce a 256-bit derived key, never assume that<br />

you have more than 160 bits of effective security (that is the output<br />

size of HMAC-SHA1).<br />

Algorithmically Generating Symmetric Keys from One Base Secret | 143<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!