RSA Security 5.2.2 Projection Television User Manual


 
Performing RSA Operations
216 RSA BSAFE Crypto-C Developers Guide
Step 3: Init
Look up the description and prototype for B_GenerateInit in Chapter 4 of the
Reference Manual. For this example, you can use the following:
Here, you use
NULL_PTR for the surrender context because B_GenerateInit is a speedy
function.
B_GenerateKeypair in Step 5 is the time-consuming function.
Step 4: Update
There is no Step 4 in generating a key pair.
Step 5: Generate
Find the description and prototype for B_GenerateKeypair in Chapter 4 of the
Reference Manual. This function takes five arguments. The first is the algorithm object:
for this example, it is
keypairGenerator
. The second and third are key objects. For this
call, all you have to do is create the key objects; they will be set by
B_GenerateKeypair. The fourth argument is a random algorithm. For this, complete
Steps 1 through 4 of Generating Random Numbers on page 165. You do not need
random bytes, only an algorithm that can generate them. The algorithm chooser you
are using (defined in Algorithm Choosers on page 116) contains the AM for SHA1
random number generation.
The last argument is the surrender context. This function call can take a while,
although the amount of time is not uniform. On slower machines, it may take over
two or three minutes to generate a 512-bit key pair, or it may take only 17 seconds.
Crypto-C needs to find two primes of the proper size. To find a prime, Crypto-C
keygenParams.modulusBits = 512;
keygenParams.publicExponent.data = f4Data;
keygenParams.publicExponent.len = 3;
if ((status = B_SetAlgorithmInfo
(keypairGenerator, AI_RSAKeyGen,
(POINTER)&keygenParams)) != 0)
break;
if ((status = B_GenerateInit
(keypairGenerator, RSA_SAMPLE_CHOOSER,
(A_SURRENDER_CTX *)NULL_PTR)) != 0)
break;