The X9.31 Sample Program

static unsigned char f4Data[] = {0x01, 0x00, 0x01};

A_SURRENDER_CTX generalSurrenderContext; int generalFlag;

char *inputData = "Sign this sentence."; unsigned int inputDataLen;

unsigned char signature[64]; unsigned int signatureLen;

unsigned int status;

generalSurrenderContext.Surrender = GeneralSurrenderFunction; generalSurrenderContext.handle = (POINTER)&generalFlag; generalSurrenderContext.reserved = NULL_PTR;

do {

printf ("Digital Signature Generation and Verification in\n"); printf ("compliance with the X9.31 Standard.\n");

printf ("================================================\n");

Generating Random Bytes

The first thing the application must do is to generate the random bytes. The Crypto-C implementation of the X9.31 random algorithm is somewhat different from the implementation of other PRNGs in Crypto-C. The main difference appears in Step 2, which sets the algorithm object. Unlike other PRNGs, AI_X931Random requires you to pass in a structure describing the number of independent streams of randomness and a seed which will be divided between the streams.

The structure, A_X931_RANDOM_PARAMS, is defined as follows:

typedef struct {

unsigned int numberOfStreams; ITEM seed;

} A_X931_RANDOM_PARAMS;

Where numberOfStreams is the number of independent streams and seed is additional seeding to be equally divided among the streams. For X9.31, the number of streams must be six.

C h a p t e r 9 P u t t i n g I t A l l To g e t h e r : A n X 9 . 3 1 E x a m p l e

3 1 5

Page 337
Image 337
RSA Security 5.2.2 manual Generating Random Bytes, Static unsigned char f4Data = 0x01, 0x00, Unsigned int status