RSA Security 5.2.2 manual Balgorithmmethod *DSAKEYGENCHOOSER = &AMDSAKEYGEN

Models: 5.2.2

1 376
Download 376 pages 13.91 Kb
Page 167
Image 167

Using Cryptographic Hardware

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;

Now that you have a key pair, extract the public key, part of the public key is a struct containing the parameters.

A_DSA_PUBLIC_KEY *pubKeyData;

if ((status = B_GetKeyInfo

((POINTER *)&pubKeyData, pubKey, KI_DSAPublic)) != 0) break;

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

C h a p t e r 4 U s i n g C r y p t o - C

1 4 5

Page 167
Image 167
RSA Security 5.2.2 manual Balgorithmmethod *DSAKEYGENCHOOSER = &AMDSAKEYGEN