Chapter 7 Public-Key Operations 229
MultiPrime
Step 6: Destroy
When you are done with all your objects, remember to destroy them.
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:
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:
B_DestroyAlgorithmObject (&randomAlgorithm);
B_DestroyAlgorithmObject (&rsaEncryptor);
B_DestroyKeyObject (&publicKey);
B_ALGORITHM_OBJ rsaDecryptor = (B_ALGORITHM_OBJ)NULL_PTR;
if ((status = B_CreateAlgorithmObject (&rsaDecryptor)) != 0)
break;
if ((status = B_SetAlgorithmInfo
(rsaDecryptor, AI_PKCS_RSAPrivate, NULL_PTR)) != 0)
break;