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.

unsigned char *next_iv, *start = out;<br />

/* If there's not enough stuff to fit in ctbuf, dump it in there and return */<br />

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

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

if (ol) *ol = 0;<br />

return 1;<br />

}<br />

/* If there's stuff in ctbuf, fill it. */<br />

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

while (ctx->ix < SPC_BLOCK_SZ) {<br />

ctx->ctbuf[ctx->ix++] = *in++;<br />

--il;<br />

}<br />

}<br />

if (!il) {<br />

if (ol) *ol = 0;<br />

return 1;<br />

}<br />

/* If we get here, and the ctbuf is full, it can't be padding. Spill it. */<br />

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

SPC_DO_DECRYPT(&(ctx->ks), ctx->ctbuf, out);<br />

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

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

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

}<br />

out += SPC_BLOCK_SZ;<br />

}<br />

if (il > SPC_BLOCK_SZ) {<br />

SPC_DO_DECRYPT(&(ctx->ks), in, out);<br />

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

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

next_iv = in;<br />

out += SPC_BLOCK_SZ;<br />

in += SPC_BLOCK_SZ;<br />

il -= SPC_BLOCK_SZ;<br />

} else next_iv = ctx->iv;<br />

while (il > SPC_BLOCK_SZ) {<br />

SPC_DO_DECRYPT(&(ctx->ks), in, out);<br />

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

((int *)out)[i] ^= ((int *)next_iv)[i];<br />

next_iv = in;<br />

out += SPC_BLOCK_SZ;<br />

in += SPC_BLOCK_SZ;<br />

il -= SPC_BLOCK_SZ;<br />

}<br />

/* Store the IV. */<br />

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

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

ctx->ix = 0;<br />

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

184 | Chapter 5: Symmetric Encryption<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!