A SERVICE OF

logo

Chapter 9 Putting It All Together: An X9.31 Example 319
The X9.31 Sample Program
/* ======================================================== */
printf ("\n Generating a Keypair \n");
printf (" ==================== \n");
if ((status = B_CreateAlgorithmObject (&keypairGenerator)) != 0)
break;
keygenParams.modulusBits = RSA_MODULUS_BITS;
keygenParams.publicExponent.data = f4Data;
keygenParams.publicExponent.len = 3;
/* For this example, AI_RSAStrongKeyGen is used, rather than
AI_RSAKeyGen. AI_RSAStrongKeyGen allows you to
specify the parameters for generating an RSA public/private
key pair as defined in PKCS#1. The moduli generated
are in conformance with the strength criteria of the ANSI
X9.31 standard.*/
if ((status = B_SetAlgorithmInfo (keypairGenerator, AI_RSAStrongKeyGen,
(POINTER)&keygenParams)) != 0)
break;
if ((status = B_GenerateInit
(keypairGenerator, X931_SAMPLE_CHOOSER,
(A_SURRENDER_CTX *)NULL_PTR)) != 0)
break;
if ((status = B_CreateKeyObject (&publicKey)) != 0)
break;
if ((status = B_CreateKeyObject (&privateKey)) != 0)
break;
/* generalFlag is for the surrender function */
generalFlag = 0;
if ((status = B_GenerateKeypair
(keypairGenerator, publicKey, privateKey,
randomAlgorithm, &generalSurrenderContext)) != 0)
break;