RSA Security 4.3 Home Security System User Manual


 
Generating Random Numbers
16 RSA BSAFE Crypto-C Intel Hardware User’s Guide
Generating Random Numbers
This example demonstrates how to use the Intel Hardware Random Number
Generator to seed a software-based pseudo-random number generator (PRNG). To
generate random numbers, do the following:
1. Use the Intel Random Number Generator to generate a random seed. In general,
you should use a seed that is at least 256 bits long.
2. Seed a pseudo-random number generator with the random value that you
retrieved in the first step. Once you have provided a seed, you can use the PRNG
to generate your random numbers.
If you are already using a Crypto-C PRNG in your applications, making the change to
use the Intel Random Number Generator is easy. All you have to do is gather the seed
as in 1 above, then make some minor changes to your existing implementation so that
it can use the seed supplied by the Intel RNG.
Obtaining a Random Seed from Hardware
First, use the Intel Random Number Generator to acquire a random seed. To do this,
you can write a function,
GenerateSeed, that will retrieve random bytes from
hardware.
Step 0: Create the Session Chooser
Before you can create an application that can access the Intel Random Number
Generator, you need to create the session chooser that associates Intel’s hardware
method,
HW_INTEL_RANDOM, with Crypto-C’s generic method for hardware random
number generation,
AM_HW_RANDOM. First set up your software and hardware choosers,
then call
B_CreateSessionChooser. This call will combine the elements of the
software chooser with those in the hardware chooser, associating Intel’s hardware
method (
HW_INTEL_RANDOM) with AM_HW_RANDOM, so that when AM_HW_RANDOM is called,
Crypto-C turns to the hardware. For more information see “The Session Chooser” on
page 7.
B_ALGORITHM_METHOD *SOFTWARE_CHOOSER[] = {
&AM_HW_RANDOM,
(B_ALGORITHM_METHOD *)NULL_PTR
};