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 (condition) ctx->c1[SPC_BLOCK_SZ - 1] ^= 0x87;<br />

/* Compute L * u ^ -1, storing it in c2 */<br />

condition = L[SPC_BLOCK_SZ - 1] & 0x01;<br />

i = SPC_BLOCK_SZ;<br />

while (--i) ctx->c2[i] = (L[i] >> 1) | (L[i - 1] c2[0] = L[0] >> 1;<br />

L[0] >>= 1;<br />

if (condition) {<br />

ctx->c2[0] ^= 0x80;<br />

ctx->c2[SPC_BLOCK_SZ - 1] ^= 0x43;<br />

}<br />

spc_memset(L, 0, SPC_BLOCK_SZ);<br />

return 1;<br />

}<br />

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

int i;<br />

if (il < SPC_BLOCK_SZ - ctx->ix) {<br />

while (il--) ctx->iv[ctx->ix++] ^= *in++;<br />

return;<br />

}<br />

if (ctx->ix) {<br />

while (ctx->ix < SPC_BLOCK_SZ) --il, ctx->iv[ctx->ix++] ^= *in;<br />

SPC_DO_ENCRYPT(&(ctx->ks), ctx->iv, ctx->iv);<br />

}<br />

while (il > SPC_BLOCK_SZ) {<br />

for (i = 0; i < SPC_BLOCK_SZ / sizeof(int); i++)<br />

((unsigned int *)(ctx->iv))[i] ^= ((unsigned int *)in)[i];<br />

SPC_DO_ENCRYPT(&(ctx->ks), ctx->iv, ctx->iv);<br />

in += SPC_BLOCK_SZ;<br />

il -= SPC_BLOCK_SZ;<br />

}<br />

for (i = 0; i < il; i++) ctx->iv[i] ^= in[i];<br />

ctx->ix = il;<br />

}<br />

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

int i;<br />

if (ctx->ix != SPC_BLOCK_SZ) {<br />

ctx->iv[ctx->ix] ^= 0x80;<br />

for (i = 0; i < SPC_BLOCK_SZ / sizeof(int); i++)<br />

((int *)ctx->iv)[i] ^= ((int *)ctx->c2)[i];<br />

} else {<br />

for (i = 0; i < SPC_BLOCK_SZ / sizeof(int); i++)<br />

((int *)ctx->iv)[i] ^= ((int *)ctx->c1)[i];<br />

}<br />

SPC_DO_ENCRYPT(&(ctx->ks), ctx->iv, out);<br />

return 1;<br />

}<br />

For those interested in the algorithm itself, note that we precompute two special values<br />

at key setup time, both of which are derived from the value we get from encrypt-<br />

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