Introductory Example

instructions on writing an algorithm chooser. For the purposes of our example, we see that the Reference Manual entry for AI_RC4 states that we should use AM_RC4_ENCRYPT in our chooser. Include the following algorithm methods in your chooser:

AM_RC4_ENCRYPT for encryption

B_ALGORITHM_METHOD*rc4EncryptChooser[]={ & AM_RC4_ENCRYPT, NULL};

Surrender Context

The fourth argument of B_EncryptInit is a surrender context, which controls when and how the application surrenders control during time-consuming operations. The application developer can put together an A_SURRENDER_CTX structure containing a surrender function and other information. Crypto-C applications call this surrender function at regular intervals.

The surrender function can simply print out information to the user that indicates that the Crypto-C operation is currently executing, or it can provide the user with a means of halting the operation if it is taking too much time. A surrender context is not required; if none is desired, simply pass a properly cast NULL_PTR. See “The Surrender Context” on page 118 for a more detailed description of the A_SURRENDER_CTX structure. For this example, we will use (A_SURRENDER_CTX *)NULL_PTR.

We can now complete our call to B_EncryptInit:

if ((status = B_EncryptInit

(rc4Encrypter, rc4Key, rc4EncryptChooser, (A_SURRENDER_CTX *)NULL_PTR)) != 0)

break;

Saving the Object State (optional)

This step is optional. Refer to “Saving State” on page 120 for information on how to receive a buffer that contains all of the data necessary to reconstruct the object, using the call B_SetAlgorithmState, to the state it was in at the time of calling the Get routine. This can be done after B_EncryptInit and B_EncryptUpdate, or B_DecryptInit and B_DecryptUpdate.

Step 4: Update

In Steps 1 through 3, we created our algorithm object and initialized it with the

1 6

R S A B S A F E C r y p t o - C D e v e l o p e r ’s G u i d e

Page 38
Image 38
RSA Security 5.2.2 manual Saving the Object State optional, Update, Surrender Context