Chapter 7 Public-Key Operations 245
Performing DSA Operations
properly cast NULL_PTR for the surrender context:
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 megab yte or more), this fu nction i s quic k 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:
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 lo ng, so
make sure the output buffer is big enough. The Reference Manual Chapter 2 entry on
AI_DSAWithSHA1 states:
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
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;
if ((status = B_SignUpdate
(dsaSigner, inputData, inputDataLen,
(A_SURRENDER_CTX *)NULL_PTR)) != 0)
break;
You must pass a random algorithm in B_SignFinal, but may pass
(B_ALGORITHM_OBJ)NULL_PTR for all other
randomAlgorithm
arguments.