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