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.

Another downside is that there is generally more data to send. Systems that use<br />

sequential nonces can often avoid sending the nonce, as it can be calculated from the<br />

sequence number already sent with the message.<br />

Initialization vectors can be generated using the techniques discussed in Chapter 11.<br />

See Also<br />

• Chapter 11<br />

• Recipes 5.6, 6.21, 8.1<br />

4.10 Deriving Symmetric Keys from a Password<br />

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

You do not want passwords to be stored on disk. Instead, you would like to convert<br />

a password into a cryptographic key.<br />

Solution<br />

Use PBKDF2, the password-based key derivation function 2, specified in PKCS #5. *<br />

Discussion<br />

You can also use this recipe to derive keys from other keys. See Recipe<br />

4.1 for considerations; that recipe also discusses considerations for<br />

choosing good salt values.<br />

Passwords can generally vary in length, whereas symmetric keys are almost always a<br />

fixed size. Passwords may be vulnerable to guessing attacks, but ultimately we’d prefer<br />

symmetric keys not to be as easily guessable.<br />

The function spc_pbkdf2( ) in the following code is an implementation of PKCS #5,<br />

Version 2.0. PKCS #5 stands for “Public Key Cryptography Standard #5,” although<br />

there is nothing public-key-specific about this standard. The standard defines a way<br />

to turn a password into a symmetric key. The name of the function stands for “password-based<br />

key derivation function 2,” where the 2 indicates that the function<br />

implements Version 2.0 of PKCS #5.<br />

#include <br />

#include <br />

#include <br />

* This standard is available from RSA Security at http://www.rsasecurity.com/rsalabs/pkcs/pkcs-5/.<br />

136 | Chapter 4: Symmetric Cryptography Fundamentals<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!