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.

void spc_pctr_do_odd(SPC_CTR2_CTX *ctx) {<br />

size_t i, j;<br />

unsigned char final[SPC_BLOCK_SZ];<br />

for (i = 0; i + SPC_BLOCK_SZ < ctx->len; i += 2 * SPC_BLOCK_SZ) {<br />

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

pctr_increment(ctx->ctr_odd);<br />

pctr_increment(ctx->ctr_odd);<br />

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

((int *)ctx->outptr_odd)[j] ^= ((int *)ctx->inptr_odd)[j];<br />

ctx->outptr_odd += SPC_BLOCK_SZ * 2;<br />

ctx->inptr_odd += SPC_BLOCK_SZ * 2;<br />

}<br />

if (i < ctx->len) {<br />

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

for (j = 0; j < ctx->len - i; j++)<br />

ctx->outptr_odd[j] = final[j] ^ ctx->inptr_odd[j];<br />

}<br />

}<br />

void spc_pctr_do_even(SPC_CTR2_CTX *ctx) {<br />

size_t i, j;<br />

unsigned char final[SPC_BLOCK_SZ];<br />

for (i = SPC_BLOCK_SZ; i + SPC_BLOCK_SZ < ctx->len; i += 2 * SPC_BLOCK_SZ) {<br />

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

pctr_increment(ctx->ctr_even);<br />

pctr_increment(ctx->ctr_even);<br />

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

((int *)ctx->outptr_even)[j] ^= ((int *)ctx->inptr_even)[j];<br />

ctx->outptr_even += SPC_BLOCK_SZ * 2;<br />

ctx->inptr_even += SPC_BLOCK_SZ * 2;<br />

}<br />

if (i < ctx->len) {<br />

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

for (j = 0; j < ctx->len - i; j++)<br />

ctx->outptr_even[j] = final[j] ^ ctx->inptr_even[j];<br />

}<br />

}<br />

int spc_pctr_final(SPC_CTR2_CTX *ctx) {<br />

spc_memset(&ctx, 0, sizeof(SPC_CTR2_CTX));<br />

return 1;<br />

}<br />

See Also<br />

Recipes 5.5, 5.9, 13.2<br />

Parallelizing Encryption and Decryption in Modes That Allow It (Without Breaking Compatibility) | 211<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!