RSA Security 5.2.2 Projection Television User Manual


 
Chapter 2 Quick Start 11
Introductory Example
Standard RSA Security coding practices use the above do-while construct 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 the
do-while and
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 functions prototype and description:
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,
int status;
do {
if ((status = B_CreateAlgorithmObject (&rc4Encrypter)) != 0)
break;
.
.
.
} while (0);
int B_SetAlgorithmInfo (
B_ALGORITHM_OBJ algorithmObject, /* algorithm object */
B_INFO_TYPE infoType, /* type of algorithm information */
POINTER info /* algorithm information */
);