provider.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright 2019 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. int OSSL_PROVIDER_add_builtin(OPENSSL_CTX *libctx, const char *name,
  50. OSSL_provider_init_fn *init_fn)
  51. {
  52. OSSL_PROVIDER *prov = NULL;
  53. if (name == NULL || init_fn == NULL) {
  54. CRYPTOerr(CRYPTO_F_OSSL_PROVIDER_ADD_BUILTIN,
  55. ERR_R_PASSED_NULL_PARAMETER);
  56. return 0;
  57. }
  58. /* Create it */
  59. if ((prov = ossl_provider_new(libctx, name, init_fn, 0)) == NULL)
  60. return 0;
  61. /*
  62. * It's safely stored in the internal store at this point,
  63. * free the returned extra reference
  64. */
  65. ossl_provider_free(prov);
  66. return 1;
  67. }
  68. const char *OSSL_PROVIDER_name(const OSSL_PROVIDER *prov)
  69. {
  70. return ossl_provider_name(prov);
  71. }