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.

This example selects a key and initialization vector at random. Both of these items<br />

need to be communicated to any party that needs to decrypt the data. The caller<br />

therefore needs to be able to recover this information. In this example, we handle<br />

this by having the caller pass in allocated memory, which we fill with the new key<br />

and IV. The caller can then communicate them to the other party in whatever manner<br />

is appropriate.<br />

Note that to make replacing algorithms easier, we always create keys and initialization<br />

vectors of the maximum possible length, using macros defined in the openssl/<br />

evp.h header file.<br />

See Also<br />

Recipes 5.2, 5.9, 5.16, 5.18, 5.20, 5.23<br />

5.18 Using Variable Key-Length Ciphers in<br />

OpenSSL<br />

<strong>Problem</strong><br />

You’re using a cipher with an adjustable key length, yet OpenSSLprovides no<br />

default cipher configuration for your desired key length.<br />

Solution<br />

Initialize the cipher without a key, call EVP_CIPHER_CTX_set_key_length( ) to set the<br />

appropriate key length, then set the key.<br />

Discussion<br />

Many of the ciphers supported by OpenSSLsupport variable key lengths. Whereas<br />

some, such as AES, have an available call for each possible key length, others (in particular,<br />

RC4) allow for nearly arbitrary byte-aligned keys. Table 5-7 lists ciphers supported<br />

by OpenSSL, and the varying key lengths those ciphers can support.<br />

Table 5-7. Variable key sizes<br />

Cipher OpenSSL-supported key sizes Algorithm’s possible key sizes<br />

AES 128, 192, and 256 bits 128, 192, and 256 bits<br />

Blowfish Up to 256 bits Up to 448 bits<br />

CAST5 40–128 bits 40–128 bits<br />

RC2 Up to 256 bits Up to 1,024 bits<br />

RC4 Up to 256 bits Up to 2,048 bits<br />

RC5 Up to 256 bits Up to 2,040 bits<br />

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