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.

To postprocess, we encrypt the hash output with one AES key, encrypt the nonce<br />

with the other AES key, then XOR the two ciphertexts together. This gives us provable<br />

security with good assumptions, plus the additional benefits of a nonce (see<br />

Recipe 6.12).<br />

The core MAC127 data type is SPC_MAC127_CTX. There are only two functions: one to<br />

initialize a context, and one to MAC a message. The initialization function has the<br />

following signature:<br />

void spc_mac127_init(SPC_MAC127_CTX *ctx, unsigned char *key);<br />

This function has the following arguments:<br />

ctx<br />

Context object that holds key material so that several messages may be MAC’d<br />

with a single key.<br />

key<br />

Buffer that contains a 16-byte key.<br />

To MAC a message, we use the function spc_mac127( ):<br />

void spc_mac127(SPC_MAC127_CTX *ctx, unsigned char *m, size_t l,<br />

unsigned char *nonce, unsigned char *out);<br />

This function has the following arguments:<br />

ctx<br />

Context object to be used to perform the MAC.<br />

m<br />

Buffer that contains the message to be authenticated.<br />

l<br />

Length of the message buffer in octets.<br />

nonce<br />

Buffer that contains a 16-byte value that must not be repeated.<br />

out<br />

Buffer into which the output will be placed. It must be at least 16 bytes in size.<br />

No more than 16 bytes will ever be written to it.<br />

Here is our implementation of MAC127:<br />

#include <br />

#ifndef WIN32<br />

#include <br />

#include <br />

#include <br />

#else<br />

#include <br />

#include <br />

#endif<br />

#include <br />

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