2
0

provider.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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)) == NULL
  18. && (prov = ossl_provider_new(libctx, name, NULL)) == 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. const OSSL_ITEM *OSSL_PROVIDER_get_param_types(const OSSL_PROVIDER *prov)
  32. {
  33. return ossl_provider_get_param_types(prov);
  34. }
  35. int OSSL_PROVIDER_get_params(const OSSL_PROVIDER *prov,
  36. const OSSL_PARAM params[])
  37. {
  38. return ossl_provider_get_params(prov, params);
  39. }
  40. int OSSL_PROVIDER_add_builtin(OPENSSL_CTX *libctx, const char *name,
  41. OSSL_provider_init_fn *init_fn)
  42. {
  43. OSSL_PROVIDER *prov = NULL;
  44. if (name == NULL || init_fn == NULL) {
  45. CRYPTOerr(CRYPTO_F_OSSL_PROVIDER_ADD_BUILTIN,
  46. ERR_R_PASSED_NULL_PARAMETER);
  47. return 0;
  48. }
  49. /* Create it */
  50. if ((prov = ossl_provider_new(libctx, name, init_fn)) == NULL)
  51. return 0;
  52. /*
  53. * It's safely stored in the internal store at this point,
  54. * free the returned extra reference
  55. */
  56. ossl_provider_free(prov);
  57. return 1;
  58. }