Performing DSA Operations

Computing a Digital Signature

Step 1: Creating An Algorithm Object

Declare a variable to be B_ALGORITHM_OBJ. As defined in the function prototype in Chapter 4 of the Reference Manual, its address is the argument for B_CreateAlgorithmObject:

B_ALGORITHM_OBJ dsaSigner = (B_ALGORITHM_OBJ)NULL_PTR;

if ((status = B_CreateAlgorithmObject (&dsaSigner)) != 0) break;

Step 2: Setting The Algorithm Object

There is only one Crypto-C choice for computing DSA digital signatures,

AI_DSAWithSHA1 (or its BER counterpart). The Reference Manual Chapter 2 entry for this AI states that the format of info supplied to B_SetAlgorithmInfo is NULL_PTR.

if ((status = B_SetAlgorithmInfo

(dsaSigner, AI_DSAWithSHA1, NULL_PTR)) != 0) break;

Step 3: Init

Associate a key and algorithm method with the algorithm object through B_SignInit. The Chapter 4 Reference Manual entry on this function shows that it takes four arguments: the algorithm object, a key object, an algorithm chooser and a surrender context. The algorithm object in this example is dsaSigner. For a key object you want to use a DSA private key. See the previous section on generating a DSA key pair.

Build an algorithm chooser, the elements being the AMs listed in the Reference Manual Chapter 2 entry for the AI in use. B_SignInit is fast, so it is reasonable to pass a

2 4 4

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 266
Image 266
RSA Security 5.2.2 manual Computing a Digital Signature Creating An Algorithm Object, Setting The Algorithm Object