AI_DSAWithSHA1

Performing DSA Operations

properly cast NULL_PTR for the surrender context:

B_ALGORITHM_METHOD *DSA_SIGN_CHOOSER[] = { &AM_SHA,

&AM_DSA_SIGN,

(B_ALGORITHM_METHOD *)NULL_PTR

};

if ((status = B_SignInit

(dsaSigner, dsaPrivateKey, DSA_SIGN_CHOOSER, (A_SURRENDER_CTX *)NULL_PTR)) != 0)

break;

Step 4: Update

Digest the data to sign with B_SignUpdate, the prototype of which is in Chapter 4 of the Reference Manual. Unless there is an extraordinarily large amount of data (for example, a megabyte or more), this function is quick and a NULL_PTR for the surrender context should be no problem. Assuming you have some input data and you know its length, your call is the following:

if ((status = B_SignUpdate (dsaSigner, inputData, inputDataLen,

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

Step 5: Final

B_SignUpdate digested the data. Create the signature and send the result to a signature buffer with B_SignFinal. The signature will be as many as 48 bytes long, so make sure the output buffer is big enough. The Reference Manual Chapter 2 entry on

states:

You must pass a random algorithm in B_SignFinal, but may pass (B_ALGORITHM_OBJ)NULL_PTR for all other randomAlgorithm arguments.

This function does not return immediately, so a surrender context can be helpful. For this example, use the surrender context described in “The Surrender Context” on

C h a p t e r 7 P u b l i c - K e y O p e r a t i o n s

2 4 5

Page 267
Image 267
RSA Security 5.2.2 manual Properly cast Nullptr for the surrender context, If status = BSignInit