Chapter 9 Putting It All Together: An X9.31 Example 323

The X9.31 Sample Program
Verifying the Signature

Verifying an X9.31 RSA signature is almost identical to signing, except that you pass

"rsaVerifyX931" for
encryptionMethodName

in Ai_SignVerify.

/* ======================================================== */
printf ("Verifying the Digital Signature \n");
printf ("=============================== \n");
/* Step 1: Create an algorithm object */
if ((status = B_CreateAlgorithmObject (&digitalVerifier)) != 0)
break;
/* Step 2: Set the algorithm object to the same AI */
/* To verify the signature created above, you need to use the
same AI you used for signing. Again, you must set up the
appropriate structures containing the information for the
algorithm you wish to use. The x931params structure is
the same as the one used for signing, but you need to use
"rsaVerifyX931" for the encryptionMethodName. */
signVerifyParams.encryptionMethodName = (unsigned char *)"rsaVerifyX931";
signVerifyParams.encryptionParams = NULL_PTR;
signVerifyParams.digestMethodName = (unsigned char *)"sha1";
signVerifyParams.digestParams = NULL_PTR;
signVerifyParams.formatMethodName = (unsigned char *)"formatX931";
signVerifyParams.formatParams = (POINTER)&x931params;
if ((status = B_SetAlgorithmInfo (digitalVerifier, AI_SignVerify,
(POINTER)&signVerifyParams)) != 0)
break;
/* Step 3: Init */
/* Again, the only change required in the Init step is to
include the appropriate algorithm methods in the chooser.
These are the same methods included in the X931_SAMPLE_CHOOSER
above. */
if ((status = B_VerifyInit
(digitalVerifier, publicKey, X931_SAMPLE_CHOOSER,
(A_SURRENDER_CTX *)NULL_PTR)) != 0)
break;