xref: /freebsd/crypto/openssl/test/fips_version_test.c (revision e0c4386e7e71d93b0edc0c8fa156263fc4a8b0b6)
1*e0c4386eSCy Schubert /*
2*e0c4386eSCy Schubert  * Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
3*e0c4386eSCy Schubert  *
4*e0c4386eSCy Schubert  * Licensed under the Apache License 2.0 (the "License").  You may not use
5*e0c4386eSCy Schubert  * this file except in compliance with the License.  You can obtain a copy
6*e0c4386eSCy Schubert  * in the file LICENSE in the source distribution or at
7*e0c4386eSCy Schubert  * https://www.openssl.org/source/license.html
8*e0c4386eSCy Schubert  */
9*e0c4386eSCy Schubert 
10*e0c4386eSCy Schubert #include <openssl/evp.h>
11*e0c4386eSCy Schubert #include <openssl/provider.h>
12*e0c4386eSCy Schubert #include "testutil.h"
13*e0c4386eSCy Schubert 
14*e0c4386eSCy Schubert static OSSL_LIB_CTX *libctx = NULL;
15*e0c4386eSCy Schubert static OSSL_PROVIDER *libprov = NULL;
16*e0c4386eSCy Schubert 
17*e0c4386eSCy Schubert typedef enum OPTION_choice {
18*e0c4386eSCy Schubert     OPT_ERR = -1,
19*e0c4386eSCy Schubert     OPT_EOF = 0,
20*e0c4386eSCy Schubert     OPT_CONFIG_FILE,
21*e0c4386eSCy Schubert     OPT_TEST_ENUM
22*e0c4386eSCy Schubert } OPTION_CHOICE;
23*e0c4386eSCy Schubert 
test_get_options(void)24*e0c4386eSCy Schubert const OPTIONS *test_get_options(void)
25*e0c4386eSCy Schubert {
26*e0c4386eSCy Schubert     static const OPTIONS test_options[] = {
27*e0c4386eSCy Schubert         OPT_TEST_OPTIONS_DEFAULT_USAGE,
28*e0c4386eSCy Schubert         { "config", OPT_CONFIG_FILE, '<',
29*e0c4386eSCy Schubert           "The configuration file to use for the libctx" },
30*e0c4386eSCy Schubert         { NULL }
31*e0c4386eSCy Schubert     };
32*e0c4386eSCy Schubert     return test_options;
33*e0c4386eSCy Schubert }
34*e0c4386eSCy Schubert 
test_fips_version(int n)35*e0c4386eSCy Schubert static int test_fips_version(int n)
36*e0c4386eSCy Schubert {
37*e0c4386eSCy Schubert     const char *version = test_get_argument(n);
38*e0c4386eSCy Schubert 
39*e0c4386eSCy Schubert     if (!TEST_ptr(version))
40*e0c4386eSCy Schubert         return 0;
41*e0c4386eSCy Schubert     return TEST_int_eq(fips_provider_version_match(libctx, version), 1);
42*e0c4386eSCy Schubert }
43*e0c4386eSCy Schubert 
setup_tests(void)44*e0c4386eSCy Schubert int setup_tests(void)
45*e0c4386eSCy Schubert {
46*e0c4386eSCy Schubert     char *config_file = NULL;
47*e0c4386eSCy Schubert     OPTION_CHOICE o;
48*e0c4386eSCy Schubert     int n;
49*e0c4386eSCy Schubert 
50*e0c4386eSCy Schubert     while ((o = opt_next()) != OPT_EOF) {
51*e0c4386eSCy Schubert         switch (o) {
52*e0c4386eSCy Schubert         case OPT_CONFIG_FILE:
53*e0c4386eSCy Schubert             config_file = opt_arg();
54*e0c4386eSCy Schubert             break;
55*e0c4386eSCy Schubert         case OPT_TEST_CASES:
56*e0c4386eSCy Schubert            break;
57*e0c4386eSCy Schubert         default:
58*e0c4386eSCy Schubert         case OPT_ERR:
59*e0c4386eSCy Schubert             return 0;
60*e0c4386eSCy Schubert         }
61*e0c4386eSCy Schubert     }
62*e0c4386eSCy Schubert 
63*e0c4386eSCy Schubert     if (!test_get_libctx(&libctx, NULL, config_file, &libprov, NULL))
64*e0c4386eSCy Schubert         return 0;
65*e0c4386eSCy Schubert 
66*e0c4386eSCy Schubert     n = test_get_argument_count();
67*e0c4386eSCy Schubert     if (n == 0)
68*e0c4386eSCy Schubert         return 0;
69*e0c4386eSCy Schubert 
70*e0c4386eSCy Schubert     ADD_ALL_TESTS(test_fips_version, n);
71*e0c4386eSCy Schubert     return 1;
72*e0c4386eSCy Schubert }
73*e0c4386eSCy Schubert 
cleanup_tests(void)74*e0c4386eSCy Schubert void cleanup_tests(void)
75*e0c4386eSCy Schubert {
76*e0c4386eSCy Schubert     OSSL_PROVIDER_unload(libprov);
77*e0c4386eSCy Schubert     OSSL_LIB_CTX_free(libctx);
78*e0c4386eSCy Schubert }
79