21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

you might use a library such as OpenSSLor CryptoAPI that provides very narrow<br />

choices. For this reason, the next several recipes provide implementations of MACs<br />

we recommend for general-purpose use, particularly OMAC, CMAC, and HMAC.<br />

Security Recommendations for MACs<br />

MACs are not quite as low-level as cryptographic hash functions. Yet they are still<br />

fairly low-level constructs, and there are some common pitfalls associated with them.<br />

We discuss these elsewhere in the book, but here’s a summary of steps you should take<br />

to defend yourself against common problems:<br />

• Don’t use the same MAC key as an encryption key. If you’d like to have a system<br />

with a single key, key your MAC and encryption separately, using the technique<br />

from Recipe 4.11.<br />

• Use a securely generated, randomly chosen key for your MAC, not something<br />

hardcoded or otherwise predictable!<br />

• Be sure to read Recipe 6.18 on how to use a MAC and encryption together<br />

securely, as it can be difficult to do.<br />

• Use an always-increasing nonce, and use this to actively thwart capture replay<br />

attacks. Do this even if the MAC doesn’t have built-in support for nonces. (See<br />

Recipe 6.21 for information on how to thwart capture replay attacks, and Recipe<br />

6.12 for using a nonce with MACs that don’t have direct support for them.)<br />

• It is of vital importance that any parties computing a MAC agree on exactly what<br />

data is to be processed. To that end, it pays to get very detailed in specifying the<br />

content of messages, including any fields you have and how they are encoded<br />

before the MAC is computed. Any encoding should be unambiguous.<br />

Some MAC interfaces may not remove key material from memory when done. Be<br />

sure to check the particular implementation you’re using.<br />

OpenSSLprovides only a single MAC implementation, HMAC, while CryptoAPI<br />

supports both CBC-MAC and HMAC. Neither quite follows the API outlined in this<br />

recipe, though they stray in different ways. OpenSSLperforms the reset operation<br />

the same way as the initialization operation (you just pass in 0 in place of the key and<br />

the algorithm arguments). CryptoAPI does not allow resetting the context object,<br />

and instead requires that a completely new context object be created.<br />

OMAC and HMAC do not take a nonce by default. See Recipe 6.12 to see how to<br />

use these algorithms with a nonce. To see how to use the incremental HMAC interface<br />

in OpenSSLand CryptoAPI, see Recipe 6.10. CryptoAPI does not have an all-inone<br />

interface, but instead requires use of its incremental API.<br />

Most libraries also provide an all-in-one interface to the MACs they provide. For<br />

example, the HMAC all-in-one function for OpenSSL looks like this:<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.<br />

Checking Message Integrity | 275

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!