The X9.31 Sample Program

316 RSA BSAFE Crypto-C Developers Guide

To create a random algorithm object and set the parameters:
/* ======================================================== */
/* Generate random bytes using AI_X931Random. AI_X931Random
is a SHA-1 based pseudo-random number generator that allows
you to generate multiple streams of randomness. AI_X931Random
satisfies the requirements of independent generation of large
and private prime factors, as specified by the ANSI X.931
standard. */
printf ("Generating random bytes \n");
printf ("======================= \n");
/* Step 1: Create a random algorithm object */
if ((status = B_CreateAlgorithmObject (&randomAlgorithm)) != 0)
break;
/* Step 2: Set the random algorithm object to use AI_X931Random.
Before we can call B_SetAlgorithmInfo, we need to prepare the
X9.31 parameters. The A_X931_RANDOM_PARAMS structure
contains two parameters: the number of independent streams
of randomness and an ITEM containing random seed data to be
divided up among the streams.*/
/* Set the number of streams in the A_X931_RANDOM_PARAMS
structure. For this example, you will specify six streams
of randomness. */
x931Params.numberOfStreams = 6;
/* In order to obtain a seed, we need to allocate space for it,
and then request it from the user. Note that the following
method of seed gathering is insecure. A real application would
use a more secure method of seed gathering to ensure the
security of the application. */
randomSeed.data = T_malloc (384);
if (randomSeed.data == NULL_PTR)
break;