A local copy of OpenSSL from GitHub
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
3.4 KiB

  1. /*
  2. * Copyright 2020 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 <string.h>
  10. #include <stdio.h>
  11. #include <openssl/core.h>
  12. #include <openssl/core_numbers.h>
  13. #include <openssl/core_names.h>
  14. #include <openssl/params.h>
  15. #include "prov/implementations.h"
  16. OSSL_provider_init_fn ossl_null_provider_init;
  17. /* Functions provided by the core */
  18. static OSSL_core_gettable_params_fn *c_gettable_params = NULL;
  19. static OSSL_core_get_params_fn *c_get_params = NULL;
  20. /* Parameters we provide to the core */
  21. static const OSSL_ITEM null_param_types[] = {
  22. { OSSL_PARAM_UTF8_PTR, OSSL_PROV_PARAM_NAME },
  23. { OSSL_PARAM_UTF8_PTR, OSSL_PROV_PARAM_VERSION },
  24. { OSSL_PARAM_UTF8_PTR, OSSL_PROV_PARAM_BUILDINFO },
  25. { 0, NULL }
  26. };
  27. static const OSSL_ITEM *null_gettable_params(const OSSL_PROVIDER *prov)
  28. {
  29. return null_param_types;
  30. }
  31. static int null_get_params(const OSSL_PROVIDER *prov, OSSL_PARAM params[])
  32. {
  33. OSSL_PARAM *p;
  34. p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_NAME);
  35. if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, "OpenSSL Null Provider"))
  36. return 0;
  37. p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_VERSION);
  38. if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_VERSION_STR))
  39. return 0;
  40. p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_BUILDINFO);
  41. if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_FULL_VERSION_STR))
  42. return 0;
  43. return 1;
  44. }
  45. static const OSSL_ALGORITHM *null_query(OSSL_PROVIDER *prov,
  46. int operation_id,
  47. int *no_cache)
  48. {
  49. *no_cache = 0;
  50. return NULL;
  51. }
  52. /* Functions we provide to the core */
  53. static const OSSL_DISPATCH null_dispatch_table[] = {
  54. { OSSL_FUNC_PROVIDER_GETTABLE_PARAMS, (void (*)(void))null_gettable_params },
  55. { OSSL_FUNC_PROVIDER_GET_PARAMS, (void (*)(void))null_get_params },
  56. { OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))null_query },
  57. { 0, NULL }
  58. };
  59. int ossl_null_provider_init(const OSSL_PROVIDER *provider,
  60. const OSSL_DISPATCH *in,
  61. const OSSL_DISPATCH **out,
  62. void **provctx)
  63. {
  64. OSSL_core_get_library_context_fn *c_get_libctx = NULL;
  65. for (; in->function_id != 0; in++) {
  66. switch (in->function_id) {
  67. case OSSL_FUNC_CORE_GETTABLE_PARAMS:
  68. c_gettable_params = OSSL_get_core_gettable_params(in);
  69. break;
  70. case OSSL_FUNC_CORE_GET_PARAMS:
  71. c_get_params = OSSL_get_core_get_params(in);
  72. break;
  73. case OSSL_FUNC_CORE_GET_LIBRARY_CONTEXT:
  74. c_get_libctx = OSSL_get_core_get_library_context(in);
  75. break;
  76. /* Just ignore anything we don't understand */
  77. default:
  78. break;
  79. }
  80. }
  81. if (c_get_libctx == NULL)
  82. return 0;
  83. *out = null_dispatch_table;
  84. /*
  85. * We want to make sure that all calls from this provider that requires
  86. * a library context use the same context as the one used to call our
  87. * functions. We do that by passing it along as the provider context.
  88. */
  89. *provctx = c_get_libctx(provider);
  90. return 1;
  91. }