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.
10 #include <openssl/opensslconf.h>
15 int main(int argc, char **argv)
17 printf("No FIPS RNG support\n");
22 # include <openssl/bn.h>
23 # include <openssl/dsa.h>
24 # include <openssl/fips.h>
25 # include <openssl/err.h>
26 # include <openssl/rand.h>
27 # include <openssl/fips_rand.h>
28 # include <openssl/x509v3.h>
32 # include "fips_utl.h"
36 unsigned char *key = NULL;
37 unsigned char *v = NULL;
38 unsigned char *dt = NULL;
39 unsigned char ret[16];
42 char *keyword, *value;
47 while (fgets(buf, sizeof buf, stdin) != NULL) {
49 if (!strncmp(buf, "[AES 128-Key]", 13))
51 else if (!strncmp(buf, "[AES 192-Key]", 13))
53 else if (!strncmp(buf, "[AES 256-Key]", 13))
55 if (!parse_line(&keyword, &value, lbuf, buf))
57 if (!strcmp(keyword, "Key")) {
58 key = hex2bin_m(value, &i);
60 fprintf(stderr, "Invalid key length, expecting %ld\n",
64 } else if (!strcmp(keyword, "DT")) {
65 dt = hex2bin_m(value, &i);
67 fprintf(stderr, "Invalid DT length\n");
70 } else if (!strcmp(keyword, "V")) {
71 v = hex2bin_m(value, &i);
73 fprintf(stderr, "Invalid V length\n");
78 fprintf(stderr, "Missing key or DT\n");
82 FIPS_rand_set_key(key, keylen);
83 FIPS_rand_seed(v, 16);
85 if (FIPS_rand_bytes(ret, 16) <= 0) {
86 fprintf(stderr, "Error getting PRNG value\n");
103 unsigned char *key = NULL;
104 unsigned char *v = NULL;
105 unsigned char *dt = NULL;
106 unsigned char ret[16];
109 char *keyword, *value;
115 while (fgets(buf, sizeof buf, stdin) != NULL) {
117 if (!strncmp(buf, "[AES 128-Key]", 13))
119 else if (!strncmp(buf, "[AES 192-Key]", 13))
121 else if (!strncmp(buf, "[AES 256-Key]", 13))
123 if (!parse_line(&keyword, &value, lbuf, buf))
125 if (!strcmp(keyword, "Key")) {
126 key = hex2bin_m(value, &i);
128 fprintf(stderr, "Invalid key length, expecting %ld\n",
132 } else if (!strcmp(keyword, "DT")) {
133 dt = hex2bin_m(value, &i);
135 fprintf(stderr, "Invalid DT length\n");
138 } else if (!strcmp(keyword, "V")) {
139 v = hex2bin_m(value, &i);
141 fprintf(stderr, "Invalid V length\n");
146 fprintf(stderr, "Missing key or DT\n");
150 FIPS_rand_set_key(key, keylen);
151 FIPS_rand_seed(v, 16);
152 for (i = 0; i < 10000; i++) {
153 FIPS_rand_set_dt(dt);
154 if (FIPS_rand_bytes(ret, 16) <= 0) {
155 fprintf(stderr, "Error getting PRNG value\n");
159 for (j = 15; j >= 0; j--) {
177 int main(int argc, char **argv)
180 fprintf(stderr, "%s [mct|vst]\n", argv[0]);
183 if (!FIPS_mode_set(1)) {
188 if (!FIPS_rand_test_mode()) {
189 fprintf(stderr, "Error setting PRNG test mode\n");
193 if (!strcmp(argv[1], "mct"))
195 else if (!strcmp(argv[1], "vst"))
198 fprintf(stderr, "Don't know how to %s.\n", argv[1]);