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.

The function EVP_CIPHER_CTX_ctrl( ) can be used to set or query either of these values,<br />

given a cipher of the appropriate type. This function has the following arguments:<br />

ctx<br />

Pointer to the cipher context to be modified.<br />

type<br />

Value indicating which operation to perform (more on this a little later).<br />

arg<br />

Numerical value to set, if appropriate (it is otherwise ignored).<br />

ptr<br />

Pointer to an integer for querying the numerical value of a property, if appropriate<br />

(the result is placed in the integer being pointed to).<br />

The type argument can be one of the four macros defined in openssl/evp.h:<br />

EVP_CTRL_GET_RC2_KEY_BITS<br />

EVP_CTRL_SET_RC2_KEY_BITS<br />

EVP_CTRL_GET_RC5_ROUNDS<br />

EVP_CTRL_SET_RC5_ROUNDS<br />

For example, to set an RC5 context to use 16 rounds:<br />

EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_SET_RC5_ROUNDS, 16, NULL);<br />

To query the number of rounds, putting the result into an integer named r:<br />

EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GET_RC5_ROUNDS, 0, &r);<br />

5.21 Querying Cipher Configuration Properties<br />

in OpenSSL<br />

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

You want to get information about a particular cipher context in OpenSSL.<br />

Solution<br />

For most properties, OpenSSLprovides macros for accessing them. For other things,<br />

we can access the members of the cipher context structure directly.<br />

To get the actual object representing the cipher:<br />

EVP_CIPHER *EVP_CIPHER_CTX_cipher(EVP_CIPHER_CTX *ctx);<br />

To get the block size of the cipher:<br />

int EVP_CIPHER_CTX_block_size(EVP_CIPHER_CTX *ctx);<br />

To get the key length of the cipher:<br />

int EVP_CIPHER_CTX_key_length(EVP_CIPHER_CTX *ctx);<br />

Querying Cipher Configuration Properties in OpenSSL | 229<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!