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>
31 #include <openssl/x509v3.h>
39 unsigned char *key = NULL;
40 unsigned char *v = NULL;
41 unsigned char *dt = NULL;
42 unsigned char ret[16];
45 char *keyword, *value;
50 while(fgets(buf,sizeof buf,stdin) != NULL)
53 if(!strncmp(buf,"[AES 128-Key]", 13))
55 else if(!strncmp(buf,"[AES 192-Key]", 13))
57 else if(!strncmp(buf,"[AES 256-Key]", 13))
59 if (!parse_line(&keyword, &value, lbuf, buf))
61 if(!strcmp(keyword,"Key"))
63 key=hex2bin_m(value,&i);
66 fprintf(stderr, "Invalid key length, expecting %ld\n", keylen);
70 else if(!strcmp(keyword,"DT"))
72 dt=hex2bin_m(value,&i);
75 fprintf(stderr, "Invalid DT length\n");
79 else if(!strcmp(keyword,"V"))
81 v=hex2bin_m(value,&i);
84 fprintf(stderr, "Invalid V length\n");
90 fprintf(stderr, "Missing key or DT\n");
94 FIPS_rand_set_key(key, keylen);
97 if (FIPS_rand_bytes(ret,16) <= 0)
99 fprintf(stderr, "Error getting PRNG value\n");
116 unsigned char *key = NULL;
117 unsigned char *v = NULL;
118 unsigned char *dt = NULL;
119 unsigned char ret[16];
122 char *keyword, *value;
128 while(fgets(buf,sizeof buf,stdin) != NULL)
131 if(!strncmp(buf,"[AES 128-Key]", 13))
133 else if(!strncmp(buf,"[AES 192-Key]", 13))
135 else if(!strncmp(buf,"[AES 256-Key]", 13))
137 if (!parse_line(&keyword, &value, lbuf, buf))
139 if(!strcmp(keyword,"Key"))
141 key=hex2bin_m(value,&i);
144 fprintf(stderr, "Invalid key length, expecting %ld\n", keylen);
148 else if(!strcmp(keyword,"DT"))
150 dt=hex2bin_m(value,&i);
153 fprintf(stderr, "Invalid DT length\n");
157 else if(!strcmp(keyword,"V"))
159 v=hex2bin_m(value,&i);
162 fprintf(stderr, "Invalid V length\n");
168 fprintf(stderr, "Missing key or DT\n");
172 FIPS_rand_set_key(key, keylen);
173 FIPS_rand_seed(v,16);
174 for (i = 0; i < 10000; i++)
176 FIPS_rand_set_dt(dt);
177 if (FIPS_rand_bytes(ret,16) <= 0)
179 fprintf(stderr, "Error getting PRNG value\n");
183 for (j = 15; j >= 0; j--)
202 int main(int argc,char **argv)
206 fprintf(stderr,"%s [mct|vst]\n",argv[0]);
209 fips_set_error_print();
210 if(!FIPS_mode_set(1))
213 if (!FIPS_rand_test_mode())
215 fprintf(stderr, "Error setting PRNG test mode\n");
218 if(!strcmp(argv[1],"mct"))
220 else if(!strcmp(argv[1],"vst"))
224 fprintf(stderr,"Don't know how to %s.\n",argv[1]);