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.

spc_omac1_init(&c, k, 16);<br />

if (*last_nonce) {<br />

for (i = 0; i < 16; i++)<br />

if (sent_nonce[i] > (*last_nonce)[i]) goto nonce_okay;<br />

return 0; /* Nonce is equal to or less than last nonce. */<br />

}<br />

nonce_okay:<br />

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

spc_omac_update(&c, ct, ctlen);<br />

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

for (i = 0; i < 16; i++)<br />

if (calc_tag[i] != sent_tag[i]) return 0;<br />

if (sent_nonce) {<br />

if (!*last_nonce) *last_nonce = (unsigned char *)malloc(16);<br />

if (!*last_nonce) abort(); /* Consider an exception instead. */<br />

memcpy(*last_nonce, sent_nonce, 16);<br />

}<br />

return 1;<br />

}<br />

This code requires you to pass in a char ** to track the last nonce that was received.<br />

You’re expected to allocate your own char *, set it to NULL, and pass in the address of<br />

that char *. The validate function will update that memory with the last valid nonce<br />

it saw, so that it can check the new nonce against the last nonce to make sure it got<br />

bigger. The function will return 1 if the MAC validates; otherwise, it will return 0.<br />

See Also<br />

Recipes 6.11, 6.12, 6.18<br />

6.22 Parallelizing MACs<br />

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

You want to use a MAC, but parallelize the computation.<br />

Solution<br />

Run multiple MACs at the same time, then MAC the resulting tags together (and in<br />

order) to yield one tag.<br />

Discussion<br />

If you want to perform message authentication in parallel, you can do so with a variation<br />

of interleaving (which we discussed for block ciphers in Recipes 5.12 through<br />

5.14) Basically, you can run multiple MACs keyed separately at the same time and<br />

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