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.

This function has the following arguments:<br />

ctx<br />

Pointer to the SPC_CBC_CTX object being used for the current message.<br />

out<br />

Pointer to the output buffer, if any. It may be NULL when padding is disabled.<br />

ol<br />

The number of output bytes written to the output buffer is placed into this<br />

pointer. This argument may be NULL, in which case the output length is not written.<br />

Incremental decryption<br />

The CBC decryption API is largely similar to the encryption API, with one major<br />

exception. When encrypting, we can output a block of data every time we take in a<br />

block of data. When decrypting, that’s not possible. We can decrypt data, but until<br />

we know that a block isn’t the final block, we can’t output it because part of the<br />

block may be padding. Of course, with padding turned off, that restriction could go<br />

away, but our API acts the same with padding off, just to ensure consistent behavior.<br />

The spc_cbc_decrypt_update( ) function, shown later in this section, has the following<br />

signature:<br />

int spc_decrypt_update(SPC_CBC_CTX *ctx, unsigned char *in, size_t il,<br />

unsigned char *out, size_t *ol);<br />

This function has the following arguments:<br />

ctx<br />

Pointer to the SPC_CBC_CTX object being used for the current message.<br />

in<br />

Pointer to the ciphertext input buffer.<br />

inlen<br />

Number of bytes contained in the ciphertext input buffer.<br />

out<br />

Pointer to a buffer where any incremental plaintext output should be written.<br />

ol<br />

Pointer into which the number of output bytes written to the output buffer is<br />

placed. This argument may be NULL, in which case the output length is not written.<br />

This function can output up to SPC_BLOCK_SZ - 1 bytes more than is input, depending<br />

on how much data has previously been buffered.<br />

int spc_cbc_decrypt_update(SPC_CBC_CTX *ctx, unsigned char *in, size_t il,<br />

unsigned char *out, size_t *ol) {<br />

int i;<br />

Using a Generic CBC Mode Implementation | 183<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!