RSA Security 5.2.2 Projection Television User Manual


 
Block Ciphers
188 RSA BSAFE Crypto-C Developers Guide
You need an algorithm chooser and a surrender context. This is a speedy function, so
it is reasonable to use a properly cast
NULL_PTR for the surrender context. However,
you do want to build a chooser:
Step 4: Update
Enter the data to encrypt through B_EncryptUpdate. From the Reference Manual
Chapter 2 entry on
AI_FeedbackCipher, you see that you can pass
(B_ALGORITHM_OBJ)NULL_PTR for all
randomAlgorithm
arguments. Once you have your
input, call
B_EncryptUpdate.
Remember that the RC2 cipher is a block cipher and requires that the input be a
multiple of eight bytes. Because you set
fbParams
.paddingMethodName to "pad" (see
page 184), Crypto-C will pad to make the input a multiple of eight bytes. That means
that the output buffer should be at least eight bytes larger than the input length.
The RC2 cipher is a fast algorithm, so for small amounts of data it is reasonable to pass
a properly cast
NULL_PTR for the surrender context. If you want to pass a surrender
context, you can:
B_ALGORITHM_METHOD *RC2_CHOOSER[] = {
&AM_CBC_ENCRYPT,
&AM_RC2_ENCRYPT,
&AM_SHA_RANDOM,
(B_ALGORITHM_METHOD *)NULL_PTR
};
if ((status = B_EncryptInit
(rc2Encrypter, rc2Key, RC2_CHOOSER,
(A_SURRENDER_CTX *)NULL_PTR)) != 0)
break;
/* Assume dataToEncrypt points to already set data and
dataToEncryptLen has been set to the number of bytes
in dataToEncrypt. */
unsigned char *dataToEncrypt;
unsigned char *encryptedData = NULL_PTR;
unsigned int dataToEncryptLen;
unsigned int encryptedDataLen;
unsigned int outputLenUpdate;
encryptedDataLen = dataToEncryptLen + 8;
encryptedData = T_malloc (encryptedDataLen);