Performing DSA Operations
242 RSA BSAFE Crypto-C Developers Guide
Generating a DSA Key Pair
The previous code generated the DSA parameters and set an algorithm object. With
that algorithm object, you can generate the key pair. Remember, the algorithm object
has already been created and set, so you can jump directly to Step 3.
Step 3: Init
When it generated the parameters, Crypto-C set the algorithm object
dsaKeyGenObj
to
AI_DSAKeyGen. That means that when you build an algorithm chooser for the Init call,
you need to include AM_DSA_KEY_GEN. Look up the description and prototype for
B_GenerateInit in Chapter 4 of the Reference Manual. For this example, you can use
the following:
This example uses NULL_PTR for the surrender context because B_GenerateInit is a
speedy function. B_GenerateKeypair in Step 5 is the time-consuming function.
Step 4: Update
There is no Step 4 in generating a key pair.
Step 5: Generate
The description and prototype for B_GenerateKeypair in Chapter 4 of the Reference
Manual shows that this function takes five arguments. The first is the algorithm object;
for this example, it is
dsaKeyGenObj
. The second and third are key objects. For this call,
all you have to do is create the key objects; they will be set by B_GenerateKeypair. The
fourth argument is a random algorithm. For this, complete Steps 1 through 4 of
Generating Random Numbers on page 165. You do not need random bytes, only an
algorithm that can generate them. The algorithm chooser you are using (from Step 3)
B_ALGORITHM_METHOD *DSA_KEY_GEN_CHOOSER[] = {
&AM_SHA_RANDOM,
&AM_DSA_KEY_GEN,
(B_ALGORITHM_METHOD *)NULL_PTR
};
if ((status = B_GenerateInit
(dsaKeyGenObj, DSA_KEY_GEN_CHOOSER,
(A_SURRENDER_CTX *)NULL_PTR)) != 0)
break;