RSA Security 5.2.2 Projection Television User Manual


 
Block Ciphers
182 RSA BSAFE Crypto-C Developers Guide
Now that you have a key, you need an algorithm chooser and a surrender context.
This is a speedy function, so you can use a properly cast
NULL_PTR for the surrender
context; but you do want to build a chooser:
Step 4: Update
Enter the data to encrypt with B_EncryptUpdate. The Reference Manual Chapter 2 entry
for
AI_FeedbackCipher states that you may pass (B_ALGORITHM_OBJ)NULL_PTR for all
randomAlgorithm
arguments. Once you have your input, call B_EncryptUpdate.
Remember that DES is a block cipher and requires input that is a multiple of eight
bytes. Because you set
fbParams.paddingMethodName
to "pad" (see page 180), 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 longer than the input length. DES 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, refer to
the following code sample:
B_ALGORITHM_METHOD *DES_CBC_CHOOSER[] = {
&AM_CBC_ENCRYPT,
&AM_DES_ENCRYPT,
&AM_SHA_RANDOM,
(B_ALGORITHM_METHOD *)NULL_PTR
};
if ((status = B_EncryptInit
(encryptionObject, desKey, DES_CBC_CHOOSER,
(A_SURRENDER_CTX *)NULL_PTR)) != 0)
break;
static char *dataToEncrypt = "Encrypt this sentence.";
unsigned char *encryptedData = NULL_PTR;
unsigned int outputBufferSize;
unsigned int outputLenUpdate, outputLenFinal;
unsigned int encryptedDataLen;
encryptedDataLen = dataToEncryptLen + 8;
encryptedData = T_malloc (encryptedDataLen);
if ((status = (encryptedData == NULL_PTR)) != 0)
break;