Introductory Example

For this example, call T_free as follows:

T_free (encryptedData);

Note: Using T_free means you can no longer access the data at that address. 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-whilebefore you zeroize and free, these important tasks will still be performed:

if (rc4KeyItem.data != NULL_PTR) {

T_memset (rc4KeyItem.data, 0, rc4KeyItem.len); T_free (rc4KeyItem.data);

rc4KeyItem.data = NULL_PTR; rc4KeyItem.len = 0;

}

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:

#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

};

2 2

R S A B S A F E C r y p t o - C D e v e l o p e r ’s G u i d e

Page 44
Image 44
RSA Security 5.2.2 manual Putting It All Together, For this example, call Tfree as follows, Tfree encryptedData