RSA Security 5.2.2 manual Destroy

Models: 5.2.2

1 376
Download 376 pages 13.91 Kb
Page 239
Image 239

Performing RSA Operations

generates a candidate and tests to see if it is prime. If the candidate passes the test, Crypto-C has one of the primes; if not, Crypto-C builds a new number. If you are lucky, two early numbers Crypto-C creates will pass the test. Sometimes, though, Crypto-C has to try many numbers before it finds a pair.

Note: The numbers Crypto-C produces are not provably prime. They are numbers for which the probability is very low that they are not prime. This does not affect the accuracy of the algorithm and will not appreciably decrease security.

When you generate a key pair, it can look as if your program has stopped or as if the machine has frozen up. To help allay fears of disaster, use the surrender function outlined in “The Surrender Context” on page 118. It will print out a dot every second to let you know the program is running properly. If the dots do not appear, then you know something is wrong:

B_KEY_OBJ publicKey = (B_KEY_OBJ)NULL_PTR;

B_KEY_OBJ privateKey = (B_KEY_OBJ)NULL_PTR;

if ((status = B_CreateKeyObject (&publicKey)) != 0) break;

if ((status = B_CreateKeyObject (&privateKey)) != 0) break;

/* generalFlag is for the surrender function. */ generalFlag = 0;

if ((status = B_GenerateKeypair (keypairGenerator, publicKey, privateKey, randomAlgorithm, &generalSurrenderContext)) != 0)

break;

Step 6: Destroy

When you are done with your objects, remember to destroy them:

B_DestroyAlgorithmObject (&randomAlgorithm);

B_DestroyAlgorithmObject (&keypairGenerator);

B_DestroyKeyObject (&publicKey);

B_DestroyKeyObject (&privateKey);

C h a p t e r 7 P u b l i c - K e y O p e r a t i o n s

2 1 7

Page 239
Image 239
RSA Security 5.2.2 manual Destroy