2
0

nullprov.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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_dispatch.h>
  13. #include <openssl/core_names.h>
  14. #include <openssl/params.h>
  15. #include "prov/implementations.h"
  16. #include "prov/providercommon.h"
  17. OSSL_provider_init_fn ossl_null_provider_init;
  18. /* Parameters we provide to the core */
  19. static const OSSL_PARAM null_param_types[] = {
  20. OSSL_PARAM_DEFN(OSSL_PROV_PARAM_NAME, OSSL_PARAM_UTF8_PTR, NULL, 0),
  21. OSSL_PARAM_DEFN(OSSL_PROV_PARAM_VERSION, OSSL_PARAM_UTF8_PTR, NULL, 0),
  22. OSSL_PARAM_DEFN(OSSL_PROV_PARAM_BUILDINFO, OSSL_PARAM_UTF8_PTR, NULL, 0),
  23. OSSL_PARAM_DEFN(OSSL_PROV_PARAM_STATUS, OSSL_PARAM_INTEGER, NULL, 0),
  24. OSSL_PARAM_END
  25. };
  26. static const OSSL_PARAM *null_gettable_params(const OSSL_PROVIDER *prov)
  27. {
  28. return null_param_types;
  29. }
  30. static int null_get_params(const OSSL_PROVIDER *provctx, OSSL_PARAM params[])
  31. {
  32. OSSL_PARAM *p;
  33. p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_NAME);
  34. if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, "OpenSSL Null Provider"))
  35. return 0;
  36. p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_VERSION);
  37. if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_VERSION_STR))
  38. return 0;
  39. p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_BUILDINFO);
  40. if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_FULL_VERSION_STR))
  41. return 0;
  42. p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_STATUS);
  43. if (p != NULL && !OSSL_PARAM_set_int(p, ossl_prov_is_running()))
  44. return 0;
  45. return 1;
  46. }
  47. static const OSSL_ALGORITHM *null_query(OSSL_PROVIDER *prov,
  48. int operation_id,
  49. int *no_cache)
  50. {
  51. *no_cache = 0;
  52. return NULL;
  53. }
  54. /* Functions we provide to the core */
  55. static const OSSL_DISPATCH null_dispatch_table[] = {
  56. { OSSL_FUNC_PROVIDER_GETTABLE_PARAMS, (void (*)(void))null_gettable_params },
  57. { OSSL_FUNC_PROVIDER_GET_PARAMS, (void (*)(void))null_get_params },
  58. { OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))null_query },
  59. { 0, NULL }
  60. };
  61. int ossl_null_provider_init(const OSSL_CORE_HANDLE *handle,
  62. const OSSL_DISPATCH *in,
  63. const OSSL_DISPATCH **out,
  64. void **provctx)
  65. {
  66. *out = null_dispatch_table;
  67. /* Could be anything - we don't use it */
  68. *provctx = (void *)handle;
  69. return 1;
  70. }