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.

c->ix = 0;<br />

c->tl = 0;<br />

}<br />

static void spc_mdc2_oneblock(SPC_MDC2_CTX *c, unsigned char bl[SPC_BLOCK_SZ]) {<br />

int i, j;<br />

SPC_KEY_SCHED ks1, ks2;<br />

SPC_ENCRYPT_INIT(&ks1, c->h1, SPC_BLOCK_SZ);<br />

SPC_ENCRYPT_INIT(&ks2, c->h2, SPC_BLOCK_SZ);<br />

SPC_DO_ENCRYPT(&ks1, bl, c->h1);<br />

SPC_DO_ENCRYPT(&ks2, bl, c->h2);<br />

j = SPC_BLOCK_SZ / (sizeof(int) * 2);<br />

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

((int *)c->h1)[i] ^= ((int *)bl)[i];<br />

((int *)c->h2)[i] ^= ((int *)bl)[i];<br />

((int *)c->h1)[i + j] ^= ((int *)bl)[i + j];<br />

((int *)c->h2)[i + j] ^= ((int *)bl)[i + j];<br />

/* Now swap the lower halves using XOR. */<br />

((int *)c->h1)[i + j] ^= ((int *)c->h2)[i + j];<br />

((int *)c->h2)[i + j] ^= ((int *)c->h1)[i + j];<br />

((int *)c->h1)[i + j] ^= ((int *)c->h2)[i + j];<br />

}<br />

}<br />

void spc_mdc2_update(SPC_MDC2_CTX *c, unsigned char *t, size_t l) {<br />

c->tl += l; /* if c->tl < l: abort */<br />

while (c->ix && l) {<br />

c->bf[c->ix++] = *t++;<br />

l--;<br />

if (!(c->ix %= SPC_BLOCK_SZ))<br />

spc_mdc2_oneblock(c, c->bf);<br />

}<br />

while (l > SPC_BLOCK_SZ) {<br />

spc_mdc2_oneblock(c, t);<br />

t += SPC_BLOCK_SZ;<br />

l -= SPC_BLOCK_SZ;<br />

}<br />

c->ix = l;<br />

for (l = 0; l < c->ix; l++)<br />

c->bf[l] = *t++;<br />

}<br />

void spc_mdc2_final(SPC_MDC2_CTX *c, unsigned char output[SPC_BLOCK_SZ * 2]) {<br />

int i;<br />

c->bf[c->ix++] = 0x80;<br />

while (c->ix < SPC_BLOCK_SZ)<br />

c->bf[c->ix++] = 0;<br />

spc_mdc2_oneblock(c, c->bf);<br />

memset(c->bf, 0, SPC_BLOCK_SZ - sizeof(size_t));<br />

c->tl = htonl(c->tl);<br />

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

c->bf[SPC_BLOCK_SZ - sizeof(size_t) + i] = ((unsigned char *)(&c->tl))[i];<br />

Using a Block Cipher to Build a Full-Strength Hash Function | 297<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!