Introductory Example
22 RSA BSAFE Crypto-C Developers Guide
For this example, call T_free as follows:
Note: Using T_free means you can no longer acce ss the data a t that addres s. Do not
free a buffer until you no longer need the data it contains. If you will need the
data later, you might want to save it to a file first.
You may want to zeroize any sensitive data before you free it. To do this, duplicate
the following sequence after the do-while. If there is an error inside the do-while
before you zeroize and free, these important tasks will still be performed:
Putting It All Together
Now we can put Steps 0 through 6 into a program. This program can be found in the
file introex.c:
T_free (encryptedData);
if (rc4KeyItem.data != NULL_PTR) {
T_memset (rc4KeyItem.data, 0, rc4KeyItem.len);
T_free (rc4KeyItem.data);
rc4KeyItem.data = NULL_PTR;
rc4KeyItem.len = 0;
}
#include "bsafe.h"
void PrintBuf PROTO_LIST ((unsigned char *, unsigned int));
void main()
{
B_KEY_OBJ rc4Key = (B_KEY_OBJ)NULL_PTR;
B_ALGORITHM_OBJ rc4Encrypter = (B_ALGORITHM_OBJ)NULL_PTR;
/* The RC4 key is hard-coded in this example. In a real application,
use a random number generator to produce the key. */
unsigned char rc4KeyData[10] = {
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10
};