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.

CMAC is the message-integrity component of the CWC encryption mode. It is based<br />

on a universal hash function that is similar to hash127. It requires an 11-byte nonce<br />

per message. The Zork implementation has the following API:<br />

int cmac_init(cmac_t *ctx, unsigned char key[16]);<br />

void cmac_mac(cmac_t *ctx, unsigned char *msg, u_int32 msglen,<br />

unsigned char nonce[11], unsigned char output[16]);<br />

void cmac_cleanup(cmac_t *ctx);<br />

void cmac_update(cmac_t *ctx, unsigned char *msg, u_int32 msglen);<br />

void cmac_final(cmac_t *ctx, unsigned char nonce[11], unsigned char output[16]);<br />

The cmac_t type keeps track of state and needs to be initialized only when you key<br />

the algorithm. You can then make messages interchangeably using the all-in-one API<br />

or the incremental API.<br />

The all-in-one API consists of the cmac_mac( ) function. It takes an entire message and<br />

a nonce as arguments and produces a 16-byte output. If you want to use the incremental<br />

API, cmac_update( ) is used to pass in part of the message, and cmac_final( )<br />

is used to set the nonce and get the resulting tag. The cmac_cleanup( ) function<br />

securely erases the context object.<br />

To use the CMAC API, just copy the cmac.h and cmac.c files, and compile and link<br />

against cmac.c.<br />

See Also<br />

• The CMAC home page: http://www.zork.org/cmac/<br />

• Recipe 6.9<br />

6.14 Using a MAC That’s Optimized for Software<br />

Speed<br />

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

You want to use the MAC that is fastest in software.<br />

Solution<br />

Use a MAC based on Dan Bernstein’s hash127, as discussed in the next section. The<br />

hash127 library is available from http://cr.yp.to.<br />

Using a MAC That’s Optimized for Software Speed | 287<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!