RSA Security 5.2.2 Projection Television User Manual


 
Block Ciphers
194 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 through B_EncryptUpdate. From the Reference Manual
Chapter 2 entry on
AI_RC5_CBCPad, you learn that you may pass
(B_ALGORITHM_OBJ)NULL_PTR for all randomAlgorithm arguments. Assuming you have
some input, call
B_EncryptUpdate.
Remember that the RC5 cipher is a block cipher and requires input that is a multiple
of eight bytes. Because you are using
AI_RC5_CBCPad, 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 RC5 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 *RC5_CHOOSER[] = {
&AM_RC5_CBC_ENCRYPT,
(B_ALGORITHM_METHOD *)NULL_PTR
};
if ((status = B_EncryptInit
(rc5Encrypter, rc5Key, RC5_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;