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.

key<br />

Pointer to the encryption key to be used.<br />

ivornonce<br />

Pointer to an initialization vector or none, if appropriate (use NULL otherwise).<br />

For CBC, CFB, and OFB modes, the initialization vector or nonce is always the<br />

same size as the block size of the cipher, which is often different from the key<br />

size of the cipher.<br />

There are also deprecated versions of these calls, EVP_EncryptInit( ) and EVP_<br />

DecryptInit( ), that are the same except that they do not take the engine argument,<br />

and they use only the built-in software implementation.<br />

Calling a function that returns an EVP_CIPHER object will cause the cipher’s implementation<br />

to load dynamically and place information about the algorithm into an<br />

internal table if it has not yet done so. Alternatively, you can load all possible symmetric<br />

ciphers at once with a call to the function OpenSSL_add_all_ciphers( ), or all<br />

ciphers and message digest algorithms with a call to the function OpenSSL_add_all_<br />

algorithms( ) (neither function takes any arguments). For algorithms that have been<br />

loaded, you can retrieve pointers to their objects by name using the EVP_get_<br />

cipherbyname( ) function, which takes a single parameter of type char *, representing<br />

the desired cipher configuration.<br />

Table 5-6 summarizes the possible functions that can load ciphers (if necessary) and<br />

return EVP_CIPHER objects. The table also shows the strings that can be used to look<br />

up loaded ciphers.<br />

As noted in Recipe 5.2, we personally recommend AES-based solutions,<br />

or (of the ciphers OpenSSLoffers) Triple-DES if AES is not<br />

appropriate. If you use other algorithms, be sure to research them<br />

thoroughly.<br />

Table 5-6. Cipher instantiation reference<br />

Key strength /<br />

actual size (if<br />

Cipher lookup<br />

Cipher<br />

different) Cipher mode Call for EVP_CIPHER object<br />

string<br />

AES 128 bits ECB EVP_aes_128_ecb( ) aes-128-ecb<br />

AES 128 bits CBC EVP_aes_128_cbc( ) aes-128-cbc<br />

AES 128 bits CFB EVP_aes_128_cfb( ) aes-128-cfb<br />

AES 128 bits OFB EVP_aes_128_ofb( ) aes-128-ofb<br />

AES 192 bits ECB EVP_aes_192_ecb( ) aes-192-ecb<br />

AES 192 bits CBC EVP_aes_192_cbc( ) aes-192-cbc<br />

AES 192 bits CFB EVP_aes_192_cfb( ) aes-192-cfb<br />

AES 192 bits OFB EVP_aes_192_ofb( ) aes-192-ofb<br />

AES 256 bits ECB EVP_aes_256_ecb( ) aes-256-ecb<br />

Performing Block Cipher Setup (for CBC, CFB, OFB, and ECB Modes) in OpenSSL | 223<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!