fips_version_test.c 1.7 KB

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