1 /* test/fips_algvs.c */
3 * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
6 /* ====================================================================
7 * Copyright (c) 2011 The OpenSSL Project. All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
21 * 3. All advertising materials mentioning features or use of this
22 * software must display the following acknowledgment:
23 * "This product includes software developed by the OpenSSL Project
24 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
26 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27 * endorse or promote products derived from this software without
28 * prior written permission. For written permission, please contact
29 * licensing@OpenSSL.org.
31 * 5. Products derived from this software may not be called "OpenSSL"
32 * nor may "OpenSSL" appear in their names without prior written
33 * permission of the OpenSSL Project.
35 * 6. Redistributions of any form whatsoever must retain the following
37 * "This product includes software developed by the OpenSSL Project
38 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
40 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51 * OF THE POSSIBILITY OF SUCH DAMAGE.
52 * ====================================================================
54 * This product includes cryptographic software written by Eric Young
55 * (eay@cryptsoft.com). This product includes software written by Tim
56 * Hudson (tjh@cryptsoft.com).
61 #include <openssl/crypto.h>
62 #include <openssl/opensslconf.h>
67 int main(int argc, char **argv)
69 printf("No FIPS ALGVS support\n");
76 extern int fips_aesavs_main(int argc, char **argv);
77 extern int fips_cmactest_main(int argc, char **argv);
78 extern int fips_desmovs_main(int argc, char **argv);
79 extern int fips_dhvs_main(int argc, char **argv);
80 extern int fips_drbgvs_main(int argc, char **argv);
81 extern int fips_dssvs_main(int argc, char **argv);
82 extern int fips_ecdhvs_main(int argc, char **argv);
83 extern int fips_ecdsavs_main(int argc, char **argv);
84 extern int fips_gcmtest_main(int argc, char **argv);
85 extern int fips_hmactest_main(int argc, char **argv);
86 extern int fips_rngvs_main(int argc, char **argv);
87 extern int fips_rsagtest_main(int argc, char **argv);
88 extern int fips_rsastest_main(int argc, char **argv);
89 extern int fips_rsavtest_main(int argc, char **argv);
90 extern int fips_shatest_main(int argc, char **argv);
91 extern int fips_test_suite_main(int argc, char **argv);
93 # include "fips_aesavs.c"
94 # include "fips_cmactest.c"
95 # include "fips_desmovs.c"
96 # include "fips_dhvs.c"
97 # include "fips_drbgvs.c"
98 # include "fips_dssvs.c"
99 # include "fips_ecdhvs.c"
100 # include "fips_ecdsavs.c"
101 # include "fips_gcmtest.c"
102 # include "fips_hmactest.c"
103 # include "fips_rngvs.c"
104 # include "fips_rsagtest.c"
105 # include "fips_rsastest.c"
106 # include "fips_rsavtest.c"
107 # include "fips_shatest.c"
108 # 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 {
142 static int chopup_args(ARGS *arg, char *buf, int *argc, char **argv[])
151 if (arg->count == 0) {
153 arg->data = (char **)OPENSSL_malloc(sizeof(char *) * arg->count);
155 for (i = 0; i < arg->count; i++)
161 /* first scan over white space */
164 while (*p && ((*p == ' ') || (*p == '\t') || (*p == '\n')))
169 /* The start of something good :-) */
170 if (num >= arg->count) {
171 fprintf(stderr, "Too many arguments!!\n");
174 arg->data[num++] = p;
176 /* now look for the end of this */
177 if ((*p == '\'') || (*p == '\"')) { /* scan for closing quote */
179 arg->data[num - 1]++; /* jump over quote */
180 while (*p && (*p != i))
184 while (*p && ((*p != ' ') && (*p != '\t') && (*p != '\n')))
199 static int run_prg(int argc, char **argv)
202 const char *prg_name;
203 prg_name = strrchr(argv[0], '/');
208 for (t = algvs; t->name; t++) {
209 if (!strcmp(prg_name, t->name))
210 return t->func(argc, argv);
215 int main(int argc, char **argv)
218 char **args = argv + 1;
219 const char *sname = "fipstests.sh";
223 int lineno = 0, badarg = 0;
224 int nerr = 0, quiet = 0, verbose = 0;
227 # ifdef FIPS_ALGVS_MEMCHECK
228 CRYPTO_malloc_debug_init();
230 CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
231 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
234 if (*args && *args[0] != '-') {
235 rv = run_prg(argc - 1, args);
236 # ifdef FIPS_ALGVS_MEMCHECK
237 CRYPTO_mem_leaks_fp(stderr);
241 while (!badarg && *args && *args[0] == '-') {
242 if (!strcmp(*args, "-script")) {
248 } else if (!strcmp(*args, "-quiet"))
250 else if (!strcmp(*args, "-verbose"))
258 fprintf(stderr, "Error processing arguments\n");
262 in = fopen(sname, "r");
264 fprintf(stderr, "Error opening script file \"%s\"\n", sname);
271 while (fgets(buf, sizeof(buf), in)) {
273 if (!chopup_args(&arg, buf, &xargc, &xargv))
274 fprintf(stderr, "Error processing line %d\n", lineno);
278 int narg = verbose ? xargc : xargc - 2;
279 printf("Running command line:");
280 for (i = 0; i < narg; i++)
281 printf(" %s", xargv[i]);
284 rv = run_prg(xargc, xargv);
285 if (FIPS_module_mode())
286 FIPS_module_mode_set(0, NULL);
290 fprintf(stderr, "ERROR: Command not found\n");
292 fprintf(stderr, "ERROR: returned %d\n", rv);
294 printf("\tCommand run successfully\n");
299 printf("Completed with %d errors\n", nerr);
302 OPENSSL_free(arg.data);
305 # ifdef FIPS_ALGVS_MEMCHECK
306 CRYPTO_mem_leaks_fp(stderr);