Chapter 4 Using Crypto-C 145
Using Cryptographic Hardware
Now that you have a key pair, extract the public key, part of the public key is a struct
containing the parameters.
Remember, the data in the A_DSA_PUBLIC_KEY struct belongs to the key object,
once you destroy that object, the data disappears. So either use the data before
B_ALGORITHM_METHOD *DSA_KEY_GEN_CHOOSER[] = {
&AM_DSA_KEY_GEN,
(B_ALGORITHM_METHOD *)NULL_PTR;
};
B_ALGORITHM_OBJ dsaKeyGen = (B_ALGORITHM_OBJ)NULL_PTR;
B_KEY_OBJ pubKey = (B_KEY_OBJ)NULL_PTR;
B_KEY_OBJ priKey = (B_KEY_OBJ)NULL_PTR;
if ((status = B_CreateAlgorithmObject (&dsaKeyGen)) != 0)
break;
if ((status = B_CreateKeyObject (&pubKey)) != 0)
break;
if ((status = B_CreateKeyObject (&priKey)) != 0)
break;
if ((status = B_GenerateParameters
(dsaParamGen, dsaKeyGen, randomObject,
NULL_SURR)) != 0)
break;
if ((status = B_GenerateInit
(dsaKeyGen, DSA_KEY_GEN_CHOOSER, NULL_SURR)) != 0)
break;
if ((status = B_GenerateKeypair
(dsaKeyGen, pubKey, priKey, random, NULL_SURR)) != 0)
break;
A_DSA_PUBLIC_KEY *pubKeyData;
if ((status = B_GetKeyInfo
((POINTER *)&pubKeyData, pubKey, KI_DSAPublic)) != 0)
break;