21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Discussion<br />

As a reminder, use a raw mode only if you really know what you’re<br />

doing. For general-purpose use, we recommend a high-level abstraction,<br />

such as that discussed in Recipe 5.16. Additionally, be sure to<br />

include some sort of integrity validation whenever encrypting, as we<br />

discuss throughout Chapter 6.<br />

The signatures for the encryption and decryption routines are identical, and the<br />

actual routines are completely symmetric. Therefore, we’ll only discuss the behavior<br />

of the encryption functions, and you can infer the behavior of the decryption functions<br />

from that.<br />

EVP_EncryptUpdate( ) has the following arguments:<br />

ctx<br />

Pointer to the cipher context previously initialized with EVP_EncryptInit_ex( ).<br />

out<br />

Buffer into which any output is placed.<br />

outl<br />

Pointer to an integer, into which the number of bytes written to the output<br />

buffer is placed.<br />

in<br />

Buffer containing the data to be encrypted.<br />

inl<br />

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

EVP_EncryptFinal_ex( ) takes the following arguments:<br />

ctx<br />

Pointer to the cipher context previously initialized with EVP_EncryptInit_ex( ).<br />

out<br />

Buffer into which any output is placed.<br />

outl<br />

Pointer to an integer, into which the number of bytes written to the output<br />

buffer is placed.<br />

There are two phases to encryption in OpenSSL: update, and finalization. The basic<br />

idea behind update mode is that you’re feeding in data to encrypt, and if there’s<br />

incremental output, you get it. Calling the finalization routine lets OpenSSLknow<br />

that all the data to be encrypted with this current context has already been given to<br />

the library. OpenSSLthen does any cleanup work necessary, and it will sometimes<br />

produce additional output. After a cipher is finalized, you need to reinitialize it if you<br />

plan to reuse it, as described in Recipe 5.17.<br />

Performing Low-Level Encryption and Decryption with OpenSSL | 231<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!