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.

ing the all-zero data block. Each precomputed value is computed by using a 128-bit<br />

shift and a conditional XOR. The last block of data is padded, if necessary, and<br />

XOR’d with one of these two values, depending on its length.<br />

Here is an all-in-one wrapper to OMAC, exporting both OMAC1 and OMAC2:<br />

int SPC_OMAC1(unsigned char key[ ], int keylen, unsigned char in[ ], size_t l,<br />

unsigned char out[16]) {<br />

SPC_OMAC_CTX c;<br />

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

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

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

return 1;<br />

}<br />

int SPC_OMAC2(unsigned char key[ ], int keylen, unsigned char in[ ], size_t l,<br />

unsigned char out[16]) {<br />

SPC_OMAC_CTX c;<br />

if (!spc_omac2_init(&c, key, keylen)) return 0;<br />

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

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

return 1;<br />

}<br />

See Also<br />

Recipes 5.5, 6.7, 6.9, 13.2<br />

6.12 Using HMAC or OMAC with a Nonce<br />

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

You want to use HMAC or OMAC, but improve its resistance to birthday attacks<br />

and capture replay attacks.<br />

Solution<br />

Use an ever-incrementing nonce that is concatenated to your message.<br />

Discussion<br />

Be sure to actually test the nonce when validating the nonce value, so<br />

as to thwart capture replay attacks. (See Recipe 6.21.)<br />

Using HMAC or OMAC with a Nonce | 285<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!