MultiPrime

Step 6: Destroy

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

B_DestroyAlgorithmObject (&randomAlgorithm);

B_DestroyAlgorithmObject (&rsaEncryptor);

B_DestroyKeyObject (&publicKey);

RSA Private-Key Decryption

This example shows how to decrypt using an RSA private key. Remember that with Crypto-C, you have the choice of doing your private-key operations normally or utilizing the blinding technique (see “Timing Attacks and Blinding” on page 95). You make this choice in the algorithm chooser. For normal decryption operations, use AM_RSA_CRT_DECRYPT; to execute blinding, use AM_RSA_CRT_DECRYPT_BLIND.

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 rsaDecryptor = (B_ALGORITHM_OBJ)NULL_PTR;

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

Step 2: Setting the Algorithm Object

Because you used AI_PKCS_RSAPublic to encrypt, it is easiest to use

AI_PKCS_RSAPrivate to decrypt. Crypto-C padded the data before encrypting; when you use the “matching” AI to decrypt, Crypto-C will automatically strip the padding. The Reference Manual Chapter 2 entry on this AI indicates the info supplied to B_SetAlgorithmInfo is NULL_PTR:

if ((status = B_SetAlgorithmInfo

(rsaDecryptor, AI_PKCS_RSAPrivate, NULL_PTR)) != 0) break;

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 2 9

Page 251
Image 251
RSA Security 5.2.2 manual RSA Private-Key Decryption, Destroy