RSA Security 5.2.2 manual Generating Independent Streams of Randomness, Typedef struct

Models: 5.2.2

1 376
Download 376 pages 13.91 Kb
Page 192
Image 192
AI_X931Random

Generating Random Numbers

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:

B_DestroyAlgorithmObject (&randomAlgorithm);

T_memset (randomSeed, 0, randomSeedLen);

T_free (randomSeed);

T_free (randomByteBuffer);

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

. 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.

typedef struct

 

 

{

 

 

unsigned int numberOfStreams;

/* number of independent streams */

ITEM

seed;

/* additional seeding */

 

/* to be equally divided among the streams */

} A_X931_RANDOM_PARAMS;

 

 

 

 

1 7 0

R S A B S A F E C r y p t o - C D e v e l o p e r ’s G u i d e

Page 192
Image 192
RSA Security 5.2.2 manual Generating Independent Streams of Randomness, This step is identical to the previous example