Generating Random Numbers
Step 3: Initialize the Random Algorithm
To initialize the random algorithm, you must pass the algorithm object, the algorithm chooser, and a surrender context. As mentioned before, the algorithm chooser does not need to be a session chooser; a simple software chooser will suffice, so this call is also identical to a software implementation.
B_ALGORITHM_METHOD *RANDOM_CHOOSER[] = { &AM_SHA_RANDOM, (B_ALGORITHM_METHOD *)NULL_PTR
};
if ((status = B_RandomInit (randomAlgorithm, RANDOM_CHOOSER, (A_SURRENDER_CTX *)NULL_PTR)) != 0)
break;
Step 4: Seed the Random Object
In this step, you will seed the random object using the seed generated by the Intel RNG. If the RNG cannot be found, or fails during processing, you can ask the user to enter a seed value.
Note: If the Intel RNG is not working at
First, acquire the random seed. To do this you must supply a function, GenerateSeed, to retrieve the random seed from hardware. An example of the GenerateSeed function is shown in the previous section, “Obtaining a Random Seed from Hardware” on page 16:
#define BYTES_TO_GENERATE = 128
randomSeedLen = BYTES_TO_GENERATE;
randomSeed = (unsigned char *)T_malloc (randomSeedLen); GenerateSeed (randomSeed, randomSeedLen);
Once you have the random seed and its length, pass both into B_RandomUpdate. This
C h a p t e r 3 U s i n g t h e I n t e l R a n d o m N u m b e r G e n e r a t o r | 2 1 |