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.

Remember to use a MAC anytime you encrypt, even though this<br />

expands your message length. The MAC is almost always necessary<br />

for security! For databases, you can always base64-encode the MAC<br />

output and stick it in another field. (See Recipe 6.9 for how to MAC<br />

data securely.)<br />

Note that encrypt_within_charset( ) can be used for both encryption and decryption.<br />

For clarity’s sake, we alias decrypt_within_charset( ) using a macro.<br />

The previous code works for fixed-size wide characters if you operate on the appropriate<br />

sized values, even though we only operate on single characters. As written,<br />

however, our code isn’t useful for variable-byte character sets. With such data, we<br />

recommend that you accept a solution that involves message expansion, such as<br />

encrypting, then base64-encoding the result.<br />

See Also<br />

Recipes 5.2, 6.9<br />

4.13 Managing Key Material Securely<br />

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

You want to minimize the odds of someone getting your raw key material, particularly<br />

if they end up with local access to the machine.<br />

Solution<br />

There are a number of things you can do to reduce these risks:<br />

• Securely erase keys as soon as you have finished using them. Use the spc_<br />

memzero( ) function from Recipe 13.2.<br />

• When you need to store key material, password-protect it, preferably using a<br />

scheme to provide encryption and message integrity so that you can detect it if<br />

the encrypted key file is ever modified. For example, you can use PBKD2 (see<br />

Recipe 4.10) to generate a key from a password and then use that key to encrypt<br />

using a mode that also provides integrity, such as CWC (see Recipe 5.10). For<br />

secret keys in public key cryptosystems, use PEM-encoding, which affords password<br />

protection (see Recipe 7.17).<br />

• Store differentiating information with your medium- or long-term symmetric<br />

keys to make sure you don’t reuse keys. (See Recipe 4.11.)<br />

See Also<br />

Recipes 4.10, 4.11, 5.10, 7.17, 13.2<br />

Managing Key Material Securely | 149<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!