Introductory Example
16 RSA BSAFE Crypto-C Developers Guide
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:

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 page118 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:
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
AM_RC4_ENCRYPT for encryption
B_ALGORITHM_METHOD*rc4EncryptChooser[]={
& AM_RC4_ENCRYPT, NULL};
if ((status = B_EncryptInit
(rc4Encrypter, rc4Key, rc4EncryptChooser,
(A_SURRENDER_CTX *)NULL_PTR)) != 0)
break;