RSA Security 5.2.2 Setting the Algorithm Object, Balgorithmobj algorithmObject Algorithm object

Models: 5.2.2

1 376
Download 376 pages 13.91 Kb
Page 33
Image 33
do-while

Introductory Example

int status; do {

if ((status = B_CreateAlgorithmObject (&rc4Encrypter)) != 0) break;

.

.

.

} while (0);

Standard RSA Security coding practices use the above do-whileconstruct to make it easy to break out of a sequence when encountering an error. If a Crypto-C function returns a non-zero value, break will exit the do-while, and further code dependent on the offending call will not be executed. However, any clean-up code, such as

overwriting sensitive memory with zeroes (see Step 6), can follow theand will always execute, whether or not there was an error.

Step 2: Setting the Algorithm Object

The variable rc4Encrypter is now an algorithm object, but we have not yet determined what type of operations it can perform. In Step 2, we associate the algorithm object with an algorithm and supply any special information or parameters the algorithm requires. We do this with B_SetAlgorithmInfo. Chapter 4 of the Reference Manual gives this function’s prototype and description:

int B_SetAlgorithmInfo (

 

B_ALGORITHM_OBJ algorithmObject,

/* algorithm object */

B_INFO_TYPE

infoType,

/* type of algorithm information */

POINTER

info

/* algorithm information */

);

 

 

 

 

 

The first argument is rc4Encrypter. The second argument is an algorithm info type, or AI. In Crypto-C, you specify the type of operation an algorithm object performs by setting the object to a particular AI. Chapter 2 of the Reference Manual describes the available AIs. Each AI description also lists the information that must accompany that AI when setting an algorithm object. That accompanying information is the third argument of B_SetAlgorithmInfo.

For our example, we want to choose a stream cipher AI. A stream cipher processes data in a stream of arbitrary length. This is in contrast to another common type of cipher, the block cipher, which processes data in blocks of a fixed size. In Crypto-C,

C h a p t e r 2 Q u i c k S t a r t

1 1

Page 33
Image 33
RSA Security 5.2.2 Setting the Algorithm Object, Balgorithmobj algorithmObject Algorithm object, Algorithm information