The X9.31 Sample Program
318 RSA BSAFE Crypto-C Developers Guide
Generating a Key Pair
Once you have the random bytes, you can use them to generate an RSA key pair.
Generating a key pair for X9.31 RSA signatures is similar to the general procedure for
RSA key pair generation, except that in X9.31, a special AI, AI_StrongKeyGen, must be
used. Using AI_StrongKeyGen guarantees that the moduli generated are in
conformance with the strength criteria of the ANSI X9.31 standard.
For more information about key pair generation, see steps 1-5 for generating an RSA
key pair in the sample program rsapkcs.c. A description of general key pair
generation is given in Generating a Key Pair on page 214 of this manual.
/* Step 3: Initialize the random algorithm. The only difference
in this example is that X931_SAMPLE_CHOOSER includes
AM_X931_RANDOM. */
if ((status = B_RandomInit
(randomAlgorithm, X931_SAMPLE_CHOOSER,
(A_SURRENDER_CTX *)NULL_PTR)) != 0)
break;
/* Step 4: Since the random seed has already been passed in via
the x931Params structure, we do not have to call
B_RandomUpdate(). */
/* Step 5: Generate. First, prepare a buffer for receiving the
random bytes before calling B_GenerateRandomBytes.
*/
randomByteBuffer = T_malloc (NUMBER_OF_RANDOM_BYTES);
if ((status = (randomByteBuffer == NULL_PTR)) != 0)
break;
T_memset (randomByteBuffer, 0, NUMBER_OF_RANDOM_BYTES);
if ((status = B_GenerateRandomBytes
(randomAlgorithm, randomByteBuffer, NUMBER_OF_RANDOM_BYTES,
(A_SURRENDER_CTX *)NULL_PTR)) != 0)
break;
printf ("%i bytes of random-generated values: \n",
NUMBER_OF_RANDOM_BYTES);
PrintBuf (randomByteBuffer, NUMBER_OF_RANDOM_BYTES);