Performing RSA Operations

Performing RSA Operations

The RSA algorithm is a public-key algorithm that relies on the difficulty of factoring a number that is the product of two large primes. If you are not familiar with the RSA algorithm and terminology, you may want to read “The RSA Algorithm” on page 51 before you continue.

The algorithm chooser used throughout the sections concerning executing the RSA algorithm can be found in “Algorithm Choosers” on page 116.

The example in this section corresponds to the file rsapkcs.c.

Note: For an example of how to perform RSA operations in conformance with the ANSI X9.31 standard, see Chapter 9, “Putting It All Together: An X9.31 Example” on page 313. The example in Chapter 9 is similar to this one; however, due to the additional constraints required by X9.31, some of the operations are more time-consuming.

Generating a Key Pair

Before you can encrypt and decrypt, you need a key pair. The key pair consists of a private key and its associated public key. Generating a key pair is not trivial. The RSA algorithm relies on very large prime numbers, which are produced during key pair generation. This could be fairly time-consuming, so we recommend you use a surrender context. The surrender context used below is the one in “The Surrender Context” on page 118.

Most Crypto-C operations follow the six-step procedure outlined in the “Introductory Example” on page 9. Generating a key pair needs only five of the steps; there is no Update call.

Step 1: Creating An Algorithm Object

Declare a variable to be B_ALGORITHM_OBJ. As defined in the function prototype in Chapter 4 of the Reference Manual, its address is the argument for B_CreateAlgorithmObject:

B_ALGORITHM_OBJ keypairGenerator = (B_ALGORITHM_OBJ)NULL_PTR;

if ((status = B_CreateAlgorithmObject (&keypairGenerator)) != 0) break;

2 1 4

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 236
Image 236
RSA Security 5.2.2 manual Performing RSA Operations, Generating a Key Pair