RSA Security 5.2.2 Projection Television User Manual


 
Introductory Example
12 RSA BSAFE Crypto-C Developers Guide
there is a single stream cipher, the RC4 cipher, and a number of AIs that can be used
to implement it. For this example we will use
AI_RC4; we pass this as the second
argument to
B_SetAlgorithmInfo.
The third argument is information that is specific to the AI we chose. For complex
algorithms, this is input that is required by the algorithm, including parameters for
algorithms that require them, salt and the desired number of iterations for
password-based encryption, or an initialization vector for block ciphers. In our
example,
AI_RC4 is a simple algorithm that does not require any parameters; its entry
in Chapter 2 of the Reference Manual states that the format of the
info
supplied to
B_SetAlgorithmInfo is NULL_PTR.
Thus, we can make the call to B_SetAlgorithmInfo:
Note: Once you have set an algorithm object, do not set it again. If you need an
algorithm object to perform another type of operation, create a new one.
Step 3: Init
Now that we have created and set our algorithm object,
rc4Encrypter
, it is ready to
encrypt. Actually, since we havent called
B_EncryptInit, it is ready to decrypt as
well. In Step 3, we choose the operations our algorithm object can perform by
supplying the desired function pointers to the Crypto-C library; we also create and set
a key object that will supply the key data the algorithm needs.
Note: An algorithm object can be used for either encryption or decryption, but not
for both. You should create separate algorithm objects to handle each case.
Look at the entry for
AI_RC4 in Chapter 2 of the Reference Manual:
Crypto-C procedures to use with algorithm object:
B_EncryptInit, B_EncryptUpdate, B_EncryptFinal;
and
B_DecryptInit, B_DecryptUpdate, and B_DecryptFinal.
You may pass
(B_ALGORITHM_OBJ)NULL_PTR for all randomAlgorithm arguments.
From this, you can see that
AI_RC4 can be used with encryption or decryption
procedures; that is, it can be used to encrypt or to decrypt. We want to encrypt, so in
Step 3, we will call
B_EncryptInit to initialize our algorithm object to perform
encryption. This call will also associate a key with the algorithm object.
if ((status = B_SetAlgorithmInfo
(rc4Encrypter, AI_RC4, NULL_PTR)) != 0)
break;