Chapter 9 Putting It All Together: An X9.31 Example 315
The X9.31 Sample Program
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:
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.
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");
typedef struct {
unsigned int numberOfStreams;
ITEM seed;
} A_X931_RANDOM_PARAMS;