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.

You’re responsible for making sure the proper init, update, and final<br />

calls are made, and that they do not happen out of order.<br />

Incremental encrypting<br />

The function spc_cbc_encrypt_update( ) has the following signature:<br />

int spc_cbc_encrypt_update(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 associated with the current message.<br />

in<br />

Pointer to the plaintext data to be encrypted.<br />

il<br />

Number indicating how many bytes of plaintext are to be encrypted.<br />

out<br />

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

ol<br />

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

placed. This argument may be NULL, in which case the caller is already expected<br />

to know the length of the output.<br />

Our implementation of this function always returns 1, but a hardwarebased<br />

implementation might have an unexpected failure, so it’s important<br />

to check the return value!<br />

This API is in the spirit of PKCS #11, * which provides a standard cryptographic<br />

interface to hardware. We do this so that the above functions can have the bulk of<br />

their implementations replaced with calls to PKCS #11–compliant hardware. Generally,<br />

PKCS #11 reverses the order of input and output argument sets. Also, it does<br />

not securely wipe key material.<br />

Because this API is PKCS #11–compliant, it’s somewhat more lowlevel<br />

than it needs to be and therefore is a bit difficult to use properly.<br />

First, you need to be sure that the output buffer is big enough to hold<br />

the input; otherwise, you will have a buffer overflow. Second, you<br />

need to make sure the out argument always points to the first unused<br />

byte in the output buffer; otherwise, you will keep overwriting the<br />

same data every time spc_cbc_encrypt_update( ) outputs data.<br />

* PKCS #11 is available from http://www.rsasecurity.com/rsalabs/pkcs/pkcs-11/.<br />

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