1 /* test/fips_algvs.c */
2 /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
5 /* ====================================================================
6 * Copyright (c) 2011 The OpenSSL Project. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
34 * 6. Redistributions of any form whatsoever must retain the following
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
60 #include <openssl/crypto.h>
61 #include <openssl/opensslconf.h>
66 int main(int argc, char **argv)
68 printf("No FIPS ALGVS support\n");
75 extern int fips_aesavs_main(int argc, char **argv);
76 extern int fips_cmactest_main(int argc, char **argv);
77 extern int fips_desmovs_main(int argc, char **argv);
78 extern int fips_dhvs_main(int argc, char **argv);
79 extern int fips_drbgvs_main(int argc,char **argv);
80 extern int fips_dssvs_main(int argc, char **argv);
81 extern int fips_ecdhvs_main(int argc, char **argv);
82 extern int fips_ecdsavs_main(int argc, char **argv);
83 extern int fips_gcmtest_main(int argc, char **argv);
84 extern int fips_hmactest_main(int argc, char **argv);
85 extern int fips_rngvs_main(int argc, char **argv);
86 extern int fips_rsagtest_main(int argc, char **argv);
87 extern int fips_rsastest_main(int argc, char **argv);
88 extern int fips_rsavtest_main(int argc, char **argv);
89 extern int fips_shatest_main(int argc, char **argv);
90 extern int fips_test_suite_main(int argc, char **argv);
92 #include "fips_aesavs.c"
93 #include "fips_cmactest.c"
94 #include "fips_desmovs.c"
95 #include "fips_dhvs.c"
96 #include "fips_drbgvs.c"
97 #include "fips_dssvs.c"
98 #include "fips_ecdhvs.c"
99 #include "fips_ecdsavs.c"
100 #include "fips_gcmtest.c"
101 #include "fips_hmactest.c"
102 #include "fips_rngvs.c"
103 #include "fips_rsagtest.c"
104 #include "fips_rsastest.c"
105 #include "fips_rsavtest.c"
106 #include "fips_shatest.c"
107 #include "fips_test_suite.c"
112 int (*func)(int argc, char **argv);
115 static ALGVS_FUNCTION algvs[] = {
116 {"fips_aesavs", fips_aesavs_main},
117 {"fips_cmactest", fips_cmactest_main},
118 {"fips_desmovs", fips_desmovs_main},
119 {"fips_dhvs", fips_dhvs_main},
120 {"fips_drbgvs", fips_drbgvs_main},
121 {"fips_dssvs", fips_dssvs_main},
122 {"fips_ecdhvs", fips_ecdhvs_main},
123 {"fips_ecdsavs", fips_ecdsavs_main},
124 {"fips_gcmtest", fips_gcmtest_main},
125 {"fips_hmactest", fips_hmactest_main},
126 {"fips_rngvs", fips_rngvs_main},
127 {"fips_rsagtest", fips_rsagtest_main},
128 {"fips_rsastest", fips_rsastest_main},
129 {"fips_rsavtest", fips_rsavtest_main},
130 {"fips_shatest", fips_shatest_main},
131 {"fips_test_suite", fips_test_suite_main},
135 /* Argument parsing taken from apps/apps.c */
137 typedef struct args_st
143 static int chopup_args(ARGS *arg, char *buf, int *argc, char **argv[])
155 arg->data=(char **)OPENSSL_malloc(sizeof(char *)*arg->count);
157 for (i=0; i<arg->count; i++)
164 /* first scan over white space */
166 while (*p && ((*p == ' ') || (*p == '\t') || (*p == '\n')))
170 /* The start of something good :-) */
171 if (num >= arg->count)
173 fprintf(stderr, "Too many arguments!!\n");
178 /* now look for the end of this */
179 if ((*p == '\'') || (*p == '\"')) /* scan for closing quote */
182 arg->data[num-1]++; /* jump over quote */
183 while (*p && (*p != i))
189 while (*p && ((*p != ' ') &&
190 (*p != '\t') && (*p != '\n')))
205 static int run_prg(int argc, char **argv)
208 const char *prg_name;
209 prg_name = strrchr(argv[0], '/');
214 for (t = algvs; t->name; t++)
216 if (!strcmp(prg_name, t->name))
217 return t->func(argc, argv);
222 int main(int argc, char **argv)
225 char **args = argv + 1;
226 const char *sname = "fipstests.sh";
230 int lineno = 0, badarg = 0;
231 int nerr = 0, quiet = 0, verbose = 0;
234 #ifdef FIPS_ALGVS_MEMCHECK
235 CRYPTO_malloc_debug_init();
237 CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
238 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
241 if (*args && *args[0] != '-')
243 rv = run_prg(argc - 1, args);
244 #ifdef FIPS_ALGVS_MEMCHECK
245 CRYPTO_mem_leaks_fp(stderr);
249 while (!badarg && *args && *args[0] == '-')
251 if (!strcmp(*args, "-script"))
261 else if (!strcmp(*args, "-quiet"))
263 else if (!strcmp(*args, "-verbose"))
272 fprintf(stderr, "Error processing arguments\n");
276 in = fopen(sname, "r");
279 fprintf(stderr, "Error opening script file \"%s\"\n", sname);
286 while (fgets(buf, sizeof(buf), in))
289 if (!chopup_args(&arg, buf, &xargc, &xargv))
290 fprintf(stderr, "Error processing line %d\n", lineno);
296 int narg = verbose ? xargc : xargc - 2;
297 printf("Running command line:");
298 for (i = 0; i < narg; i++)
299 printf(" %s", xargv[i]);
302 rv = run_prg(xargc, xargv);
303 if (FIPS_module_mode())
304 FIPS_module_mode_set(0, NULL);
308 fprintf(stderr, "ERROR: Command not found\n");
310 fprintf(stderr, "ERROR: returned %d\n", rv);
312 printf("\tCommand run successfully\n");
317 printf("Completed with %d errors\n", nerr);
320 OPENSSL_free(arg.data);
323 #ifdef FIPS_ALGVS_MEMCHECK
324 CRYPTO_mem_leaks_fp(stderr);