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.

int spc_omac1_init(SPC_OMAC_CTX *ctx, unsigned char *key, int keylen);<br />

int spc_omac2_init(SPC_OMAC_CTX *ctx, unsigned char *key, int keylen);<br />

These functions have the following arguments:<br />

ctx<br />

Context object to be initialized.<br />

key<br />

Block cipher key.<br />

keylen<br />

Length of the key in bytes. The length of the key must be 16, 24, or 32 bytes; any<br />

other key length is invalid.<br />

Once initialized, spc_omac_update( ) can be used to process data. Note that the only<br />

differences between OMAC1 and OMAC2 in this implementation are handled at key<br />

setup time, so they both use the same functions for updating and finalization. Multiple<br />

calls to spc_omac_update( ) act just like making a single call where all of the data<br />

was concatenated together. Here is its signature:<br />

void spc_omac_update(SPC_OMAC_CTX *ctx, unsigned char *in, size_t il);<br />

This function has the following arguments:<br />

ctx<br />

Context object to use for the current message.<br />

in<br />

Buffer that contains the data to be processed.<br />

il<br />

Length of the data buffer to be processed in bytes.<br />

To obtain the output of the MAC operation, call spc_omac_final( ), which has the<br />

following signature:<br />

int spc_omac_final(SPC_OMAC_CTX *ctx, unsigned char *out);<br />

This function has the following arguments:<br />

ctx<br />

Context object to be finalized.<br />

out<br />

Buffer into which the output will be placed. This buffer must be at least 16 bytes<br />

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

Here is the code implementing OMAC:<br />

#include <br />

typedef struct {<br />

SPC_KEY_SCHED ks;<br />

int ix;<br />

unsigned char iv[SPC_BLOCK_SZ];<br />

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