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.

If you’re using an off-the-shelf HMAC implementation, such as OpenSSL’s or CryptoAPI’s,<br />

you can easily concatenate your nonce to the beginning of your message.<br />

You should use a nonce that’s at least half as large as your key size, if not larger. Ultimately,<br />

we would recommend that any nonce contain a message counter that is 64<br />

bits (it can be smaller if you’re 100% sure you’ll never use every counter value) and a<br />

random portion that is at least 64 bits. The random portion can generally be chosen<br />

per session instead of per message.<br />

Here’s a simple wrapper that provides a nonced all-in-one version of OMAC1, using<br />

the implementation from Recipe 6.11 and a 16-byte nonce:<br />

void spc_OMAC1_nonced(unsigned char key[ ], int keylen, unsigned char in[ ],<br />

size_t l, unsigned char nonce[16], unsigned char out[16]) {<br />

SPC_OMAC_CTX c;<br />

if (!spc_omac1_init(&c, key, keylen)) abort( );<br />

spc_omac_update(&c, nonce, 16);<br />

spc_omac_update(&c, in, l);<br />

spc_omac_final(&c, out);<br />

}<br />

See Also<br />

Recipes 6.11, 6.21<br />

6.13 Using a MAC That’s Reasonably Fast in<br />

Software and Hardware<br />

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

You want to use a MAC that is fast in both software and hardware.<br />

Solution<br />

Use CMAC. It is available from http://www.zork.org/cmac/.<br />

Discussion<br />

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

Recipe 6.9).<br />

286 | 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!