provider.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Copyright 2019-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 <openssl/err.h>
  10. #include <openssl/cryptoerr.h>
  11. #include <openssl/provider.h>
  12. #include "internal/provider.h"
  13. OSSL_PROVIDER *OSSL_PROVIDER_load(OPENSSL_CTX *libctx, const char *name)
  14. {
  15. OSSL_PROVIDER *prov = NULL;
  16. /* Find it or create it */
  17. if ((prov = ossl_provider_find(libctx, name, 0)) == NULL
  18. && (prov = ossl_provider_new(libctx, name, NULL, 0)) == NULL)
  19. return NULL;
  20. if (!ossl_provider_activate(prov)) {
  21. ossl_provider_free(prov);
  22. return NULL;
  23. }
  24. return prov;
  25. }
  26. int OSSL_PROVIDER_unload(OSSL_PROVIDER *prov)
  27. {
  28. ossl_provider_free(prov);
  29. return 1;
  30. }
  31. int OSSL_PROVIDER_available(OPENSSL_CTX *libctx, const char *name)
  32. {
  33. OSSL_PROVIDER *prov = NULL;
  34. int available = 0;
  35. /* Find it or create it */
  36. prov = ossl_provider_find(libctx, name, 0);
  37. available = ossl_provider_available(prov);
  38. ossl_provider_free(prov);
  39. return available;
  40. }
  41. const OSSL_PARAM *OSSL_PROVIDER_gettable_params(const OSSL_PROVIDER *prov)
  42. {
  43. return ossl_provider_gettable_params(prov);
  44. }
  45. int OSSL_PROVIDER_get_params(const OSSL_PROVIDER *prov, OSSL_PARAM params[])
  46. {
  47. return ossl_provider_get_params(prov, params);
  48. }
  49. const OSSL_ALGORITHM *OSSL_PROVIDER_query_operation(const OSSL_PROVIDER *prov,
  50. int operation_id,
  51. int *no_cache)
  52. {
  53. return ossl_provider_query_operation(prov, operation_id, no_cache);
  54. }
  55. void *OSSL_PROVIDER_get0_provider_ctx(const OSSL_PROVIDER *prov)
  56. {
  57. return ossl_provider_prov_ctx(prov);
  58. }
  59. int OSSL_PROVIDER_get_capabilities(const OSSL_PROVIDER *prov,
  60. const char *capability,
  61. OSSL_CALLBACK *cb,
  62. void *arg)
  63. {
  64. return ossl_provider_get_capabilities(prov, capability, cb, arg);
  65. }
  66. int OSSL_PROVIDER_add_builtin(OPENSSL_CTX *libctx, const char *name,
  67. OSSL_provider_init_fn *init_fn)
  68. {
  69. OSSL_PROVIDER *prov = NULL;
  70. if (name == NULL || init_fn == NULL) {
  71. CRYPTOerr(CRYPTO_F_OSSL_PROVIDER_ADD_BUILTIN,
  72. ERR_R_PASSED_NULL_PARAMETER);
  73. return 0;
  74. }
  75. /* Create it */
  76. if ((prov = ossl_provider_new(libctx, name, init_fn, 0)) == NULL)
  77. return 0;
  78. /*
  79. * It's safely stored in the internal store at this point,
  80. * free the returned extra reference
  81. */
  82. ossl_provider_free(prov);
  83. return 1;
  84. }
  85. const char *OSSL_PROVIDER_name(const OSSL_PROVIDER *prov)
  86. {
  87. return ossl_provider_name(prov);
  88. }
  89. int OSSL_PROVIDER_do_all(OPENSSL_CTX *ctx,
  90. int (*cb)(OSSL_PROVIDER *provider,
  91. void *cbdata),
  92. void *cbdata)
  93. {
  94. return ossl_provider_forall_loaded(ctx, cb, cbdata);
  95. }