RSA Security 5.2.2 Where Pointer is defined in aglobal.h, Nullptr is also defined in aglobal.h

Models: 5.2.2

1 376
Download 376 pages 13.91 Kb
Page 32
Image 32

Introductory Example

specify the type of algorithm that is being used, supply any special information or parameters that the algorithm requires, and generate or supply a key for algorithms that need one.

In Step 1, we simply create the object. We do this by declaring a variable to be an algorithm object and calling B_CreateAlgorithmObject.

In this case, we name our algorithm object rc4Encrypter and declare it as follows:

B_ALGORITHM_OBJ rc4Encrypter = (B_ALGORITHM_OBJ)NULL_PTR;

The data type B_ALGORITHM_OBJ is defined in bsafe.h: typedef POINTER B_ALGORITHM_OBJ;

where POINTER is defined in aglobal.h:

typedef unsigned char *POINTER;

and NULL_PTR is also defined in aglobal.h:

#define NULL_PTR ((POINTER)0)

So our variable, rc4Encrypter, is a pointer. To prevent problems when the algorithm object is destroyed, it is a good idea to initialize it to NULL_PTR. See Step 6 for details.

To create an algorithm object, we call B_CreateAlgorithmObject. Chapter 4 of the Reference Manual gives the function prototypes and descriptions of all the Crypto-C calls. For B_CreateAlgorithmObject, we find:

int B_CreateAlgorithmObject (

 

B_ALGORITHM_OBJ *algorithmObject

/* new algorithm object */

);

 

 

 

Because B_CreateAlgorithmObject takes a pointer to a B_ALGORITHM_OBJ as its argument, we have to pass the address of rc4Encrypter. The return value is an int. Most Crypto-C calls return either a 0 (zero), which indicates success, or a non-zero error code. After the call, look at the return value: if it is 0, continue; if not, stop. At RSA Security, the tradition is to name the return value status:

1 0

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 32
Image 32
RSA Security 5.2.2 Where Pointer is defined in aglobal.h, Nullptr is also defined in aglobal.h, #define Nullptr POINTER0