2 * Crude test driver for processing the VST and MCT testvector files
3 * generated by the CMVP RNGVS product.
5 * Note the input files are assumed to have a _very_ specific format
6 * as described in the NIST document "The Random Number Generator
7 * Validation System (RNGVS)", May 25, 2004.
11 #define OPENSSL_FIPSAPI
13 #include <openssl/opensslconf.h>
18 int main(int argc, char **argv)
20 printf("No FIPS RNG support\n");
25 #include <openssl/bn.h>
26 #include <openssl/dsa.h>
27 #include <openssl/fips.h>
28 #include <openssl/err.h>
29 #include <openssl/rand.h>
30 #include <openssl/fips_rand.h>
36 static void vst(FILE *in, FILE *out)
38 unsigned char *key = NULL;
39 unsigned char *v = NULL;
40 unsigned char *dt = NULL;
41 unsigned char ret[16];
44 char *keyword, *value;
49 while(fgets(buf,sizeof buf,in) != NULL)
52 if(!strncmp(buf,"[AES 128-Key]", 13))
54 else if(!strncmp(buf,"[AES 192-Key]", 13))
56 else if(!strncmp(buf,"[AES 256-Key]", 13))
58 if (!parse_line(&keyword, &value, lbuf, buf))
60 if(!strcmp(keyword,"Key"))
62 key=hex2bin_m(value,&i);
65 fprintf(stderr, "Invalid key length, expecting %ld\n", keylen);
69 else if(!strcmp(keyword,"DT"))
71 dt=hex2bin_m(value,&i);
74 fprintf(stderr, "Invalid DT length\n");
78 else if(!strcmp(keyword,"V"))
80 v=hex2bin_m(value,&i);
83 fprintf(stderr, "Invalid V length\n");
89 fprintf(stderr, "Missing key or DT\n");
93 FIPS_x931_set_key(key, keylen);
96 if (FIPS_x931_bytes(ret,16) <= 0)
98 fprintf(stderr, "Error getting PRNG value\n");
102 OutputValue("R", ret, 16, out, 0);
113 static void mct(FILE *in, FILE *out)
115 unsigned char *key = NULL;
116 unsigned char *v = NULL;
117 unsigned char *dt = NULL;
118 unsigned char ret[16];
121 char *keyword, *value;
127 while(fgets(buf,sizeof buf,in) != NULL)
130 if(!strncmp(buf,"[AES 128-Key]", 13))
132 else if(!strncmp(buf,"[AES 192-Key]", 13))
134 else if(!strncmp(buf,"[AES 256-Key]", 13))
136 if (!parse_line(&keyword, &value, lbuf, buf))
138 if(!strcmp(keyword,"Key"))
140 key=hex2bin_m(value,&i);
143 fprintf(stderr, "Invalid key length, expecting %ld\n", keylen);
147 else if(!strcmp(keyword,"DT"))
149 dt=hex2bin_m(value,&i);
152 fprintf(stderr, "Invalid DT length\n");
156 else if(!strcmp(keyword,"V"))
158 v=hex2bin_m(value,&i);
161 fprintf(stderr, "Invalid V length\n");
167 fprintf(stderr, "Missing key or DT\n");
171 FIPS_x931_set_key(key, keylen);
172 FIPS_x931_seed(v,16);
173 for (i = 0; i < 10000; i++)
175 FIPS_x931_set_dt(dt);
176 if (FIPS_x931_bytes(ret,16) <= 0)
178 fprintf(stderr, "Error getting PRNG value\n");
182 for (j = 15; j >= 0; j--)
190 OutputValue("R", ret, 16, out, 0);
201 int main(int argc,char **argv)
206 in = fopen(argv[2], "r");
209 fprintf(stderr, "Error opening input file\n");
212 out = fopen(argv[3], "w");
215 fprintf(stderr, "Error opening output file\n");
226 fprintf(stderr,"%s [mct|vst]\n",argv[0]);
231 if (!FIPS_x931_test_mode())
233 fprintf(stderr, "Error setting PRNG test mode\n");
236 if(!strcmp(argv[1],"mct"))
238 else if(!strcmp(argv[1],"vst"))
242 fprintf(stderr,"Don't know how to %s.\n",argv[1]);