A SERVICE OF

logo

Generating Random Numbers
170 RSA BSAFE Crypto-C Developers Guide
Step 6: Destroy
Remember to destroy all objects when done with them. You must also call T_free
once for each call to
T_malloc. For security reasons, overwrite the seed buffer with
zeros as well:
Generating Independent Streams of Randomness
AI_X931Random is a SHA1-based pseudo-random number generator that allows you to
generate multiple streams of randomness. This means that the Crypto-C
implementation of the X9.31 random algorithm is somewhat different from the
implementation of the other PRNGs in Crypto-C. This section describes the
modifications you would have to make to the previous example to use
AI_X931Random. These modifications take place at Step 2, Set and Step 3, Init.
The example in this section corresponds to the file
x931rand.c.
Step 1: Create
This step is identical to the previous example.
Step 2: Set
Setting the X9.31 random algorithm object is the main difference working with the
other random algorithms.
AI_X931Random requires you to pass in a structure
describing the number of independent streams of randomness and a seed which will
be divided between the streams.
B_DestroyAlgorithmObject (&randomAlgorithm);
T_memset (randomSeed, 0, randomSeedLen);
T_free (randomSeed);
T_free (randomByteBuffer);
typedef struct
{
unsigned int numberOfStreams; /* number of independent streams */
ITEM seed; /* additional seeding */
/* to be equally divided among the streams */
} A_X931_RANDOM_PARAMS;