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.

Discussion<br />

Be sure to look at our generic recommendations for using a MAC (see<br />

Recipe 6.9).<br />

The hash127 algorithm is a universal hash function that can be turned into a secure<br />

MAC using AES. It is available from Dan Bernstein’s web page: http://cr.yp.to/<br />

hash127.html. Follow the directions on how to install the hash127 library. Once the<br />

library is compiled, just include the directory containing hash127.h in your include<br />

path and link against hash127.a.<br />

Unfortunately, at the time of this writing, the hash127 implementation<br />

has not been ported to Windows. Aside from differences in inline<br />

assembler syntax between GCC and Microsoft Visual C++, some constants<br />

used in the implementation overflow Microsoft Visual C++'s<br />

internal token buffer. When a port becomes available, we will update<br />

the book’s web site with the relevant information.<br />

The way to use hash127 as a MAC is to hash the message you want to authenticate<br />

(the hash function takes a key and a nonce as inputs, as well as the message), then<br />

encrypt the result of the hash function using AES.<br />

In this recipe, we present an all-in-one MAC API based on hash127, which we call<br />

MAC127. This construction first hashes a message using hash127, then uses two<br />

constant-time postprocessing operations based on AES. The postprocessing operations<br />

give this MAC excellent provable security under strong assumptions.<br />

When initializing the MAC, a 16-byte key is turned into three 16-byte keys by AESencrypting<br />

three constant values. The first two derived keys are AES keys, used for<br />

postprocessing. The third derived key is the hash key (though the hash127 algorithm<br />

will actually ignore one bit of this key).<br />

Note that Bernstein’s hash127 interface has some practical limitations:<br />

• The entire message must be present at the time hash127( ) is called. That is,<br />

there’s no incremental interface. If you need a fast incremental MAC, use CMAC<br />

(discussed in Recipe 6.13) instead.<br />

• The API takes an array of 32-bit values as input, meaning that it cannot accept<br />

an arbitrary character string.<br />

However, we can encode the leftover bytes of input in the last parameter passed to<br />

hash127( ). Bernstein expects the last parameter to be used for additional per-message<br />

keying material. We’re not required to use that parameter for keying material<br />

(i.e., our construction is still a secure MAC). Instead, we encode any leftover bytes,<br />

then unambiguously encode the length of the message.<br />

288 | Chapter 6: Hashes and Message Authentication<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!