RSA Security 5.2.2 manual Destroy, Asurrenderctx *surrenderContext Surrender context

Models: 5.2.2

1 376
Download 376 pages 13.91 Kb
Page 42
Image 42

Introductory Example

int B_EncryptFinal (

 

B_ALGORITHM_OBJ

algorithmObject,

/* algorithm object */

unsigned char

*partOut,

/* output data buffer */

unsigned int

*partOutLen,

/* length of output data */

unsigned int

maxPartOutLen,

/* size of output data buffer */

B_ALGORITHM_OBJ

randomAlgorithm,

/* random byte source */

A_SURRENDER_CTX *surrenderContext

/* surrender context */

);

 

 

 

 

 

For our example, the first argument is rc4Encrypter.

The second argument is a pointer to the output buffer that we created for

B_EncryptUpdate. However, B_EncryptUpdate has already placed some data into that buffer, so we must pass the address of the next byte that is available after the already filled bytes to B_EncryptFinal. That is the address of the beginning of the buffer plus the number of bytes that B_EncryptUpdate filled, or encryptedData + outputLenUpdate.

The third argument is a pointer to an unsigned int; B_EncryptFinal will set that unsigned int to the number of bytes it encrypted.

The fourth argument is the size of the buffer available to B_EncryptFinal. Because B_EncryptUpdate has already written to part of the buffer, this value will be the total size of the buffer minus the number of bytes B_EncryptUpdate has used, or dataToEncryptLen - outputLenUpdate.

Once again, we can pass properly cast null pointers for the fifth and sixth arguments, which are the random algorithm and surrender context.

Then, for our example, we have:

if ((status = B_EncryptFinal

(rc4Encrypter, encryptedData + outputLenUpdate, &outputLenFinal, dataToEncryptLen - outputLenUpdate, (B_ALGORITHM_OBJ)NULL_PTR,

(A_SURRENDER_CTX *)NULL_PTR)) != 0) break;

Step 6: Destroy

When you are done with an algorithm or key object, you must destroy it. The Destroy function frees up any memory that was allocated by Crypto-C and zeroizes any sensitive memory. Because you will always want to destroy the objects, place these

2 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 42
Image 42
RSA Security 5.2.2 manual Destroy, Asurrenderctx *surrenderContext Surrender context