Introductory Example

See the description and prototype in Chapter 4 of the Reference Manual for B_EncryptInit:

int B_EncryptInit (

 

 

B_ALGORITHM_OBJ

algorithmObject,

/* algorithm object */

B_KEY_OBJ

keyObject,

/* key object */

B_ALGORITHM_CHOOSER

algorithmChooser,

/* algorithm chooser */

A_SURRENDER_CTX

*surrenderContext

/* surrender context */

);

 

 

 

 

 

As in Step 2, the first argument is the algorithm object; once again, we use rc4Encrypter. The next three arguments are new.

Step 3a: Creating a Key Object

The second argument is a key object, which is used to hold any key-related information, such as the RC4 key, and to supply this information to functions that require it. Before we can pass a key object as an argument, we must create and set it. Creating a key object is similar to creating an algorithm object. We name our key object rc4Key and declare it as follows:

B_KEY_OBJ rc4Key = (B_KEY_OBJ)NULL_PTR;

where B_KEY_OBJ is defined in bsafe.h: typedef POINTER B_KEY_OBJ;

Chapter 4 of the Reference Manual gives the description and prototype of B_CreateKeyObject:

int B_CreateKeyObject (

 

B_KEY_OBJ *keyObject

/* new key object */

);

 

 

 

For our example, we use:

if ((status = B_CreateKeyObject (&rc4Key)) != 0) break;

Step 3b: Setting a Key Object

We have a key object, but it is not yet distinguished as an RC4 key. To distinguish the

C h a p t e r 2 Q u i c k S t a r t

1 3

Page 35
Image 35
RSA Security 5.2.2 manual Creating a Key Object, Setting a Key Object, For our example, we use