ossl_provider_new.pod 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. =pod
  2. =head1 NAME
  3. ossl_provider_find, ossl_provider_new, ossl_provider_upref,
  4. ossl_provider_free, ossl_provider_add_module_location,
  5. ossl_provider_set_fallback, ossl_provider_activate,
  6. ossl_provider_ctx, ossl_provider_forall_loaded,
  7. ossl_provider_name, ossl_provider_dso,
  8. ossl_provider_module_name, ossl_provider_module_path,
  9. ossl_provider_teardown, ossl_provider_get_param_types,
  10. ossl_provider_get_params, ossl_provider_query_operation
  11. - internal provider routines
  12. =head1 SYNOPSIS
  13. #include "internal/provider.h"
  14. OSSL_PROVIDER *ossl_provider_find(OPENSSL_CTX *libctx, const char *name);
  15. OSSL_PROVIDER *ossl_provider_new(OPENSSL_CTX *libctx, const char *name,
  16. ossl_provider_init_fn *init_function);
  17. int ossl_provider_upref(OSSL_PROVIDER *prov);
  18. void ossl_provider_free(OSSL_PROVIDER *prov);
  19. /* Setters */
  20. int ossl_provider_add_module_location(OSSL_PROVIDER *prov, const char *loc);
  21. int ossl_provider_set_fallback(OSSL_PROVIDER *prov);
  22. /* Load and initialize the Provider */
  23. int ossl_provider_activate(OSSL_PROVIDER *prov);
  24. /* Return pointer to the provider's context */
  25. void *ossl_provider_ctx(const OSSL_PROVIDER *prov);
  26. /* Iterate over all loaded providers */
  27. int ossl_provider_forall_loaded(OPENSSL_CTX *,
  28. int (*cb)(OSSL_PROVIDER *provider,
  29. void *cbdata),
  30. void *cbdata);
  31. /* Getters for other library functions */
  32. const char *ossl_provider_name(OSSL_PROVIDER *prov);
  33. const DSO *ossl_provider_dso(OSSL_PROVIDER *prov);
  34. const char *ossl_provider_module_name(OSSL_PROVIDER *prov);
  35. const char *ossl_provider_module_path(OSSL_PROVIDER *prov);
  36. /* Thin wrappers around calls to the provider */
  37. void ossl_provider_teardown(const OSSL_PROVIDER *prov);
  38. const OSSL_ITEM *ossl_provider_get_param_types(const OSSL_PROVIDER *prov);
  39. int ossl_provider_get_params(const OSSL_PROVIDER *prov,
  40. const OSSL_PARAM params[]);
  41. const OSSL_ALGORITHM *ossl_provider_query_operation(const OSSL_PROVIDER *prov,
  42. int operation_id,
  43. int *no_cache);
  44. =head1 DESCRIPTION
  45. C<OSSL_PROVIDER> is a type that holds all the necessary information
  46. to handle a provider, regardless of if it's built in to the
  47. application or the OpenSSL libraries, or if it's a loadable provider
  48. module.
  49. Instances of this type are commonly refered to as I<provider object>s.
  50. A I<provider object> is always stored in a set of I<provider object>s
  51. in the library context.
  52. I<provider object>s are reference counted.
  53. I<provider object>s are initially inactive, i.e. they are only
  54. recorded in the store, but are not used.
  55. They are activated with the first call to ossl_provider_activate(),
  56. and are inactivated when ossl_provider_free() has been called as many
  57. times as ossl_provider_activate() has.
  58. =head2 Functions
  59. ossl_provider_find() finds an existing I<provider object> in the
  60. I<provider object> store by C<name>.
  61. The I<provider object> it finds gets its reference count
  62. incremented.
  63. ossl_provider_new() creates a new I<provider object> and stores it in
  64. the I<provider object> store, unless there already is one there with
  65. the same name.
  66. The reference counter of a newly created I<provider object> will
  67. always be 2; one for being added to the store, and one for the
  68. returned reference.
  69. To indicate a built-in provider, the C<init_function> argument must
  70. point at the provider initialization function for that provider.
  71. ossl_provider_free() decrements a I<provider object>'s reference
  72. counter; if it drops below 2, the I<provider object> is assumed to
  73. have fallen out of use and will be inactivated (its teardown function
  74. is called); if it drops down to zero, the I<provider object> is
  75. assumed to have been taken out of the store, and the associated module
  76. will be unloaded if one was loaded, and the I<provider object> will be
  77. freed.
  78. ossl_provider_add_module_location() adds a location to look for a
  79. provider module.
  80. ossl_provider_set_fallback() marks an available provider as fallback.
  81. Note that after this call, the I<provider object> pointer that was
  82. used can simply be dropped, but not freed.
  83. ossl_provider_activate() "activates" the provider for the given
  84. I<provider object>.
  85. What "activates" means depends on what type of I<provider object> it
  86. is:
  87. =over 4
  88. =item *
  89. If an initialization function was given with ossl_provider_new(), that
  90. function will get called.
  91. =item *
  92. If no intialization function was given with ossl_provider_new(), a
  93. loadable module with the C<name> that was given to ossl_provider_new()
  94. will be located and loaded, then the symbol C<OSSL_provider_init> will
  95. be located in that module, and called.
  96. =back
  97. ossl_provider_ctx() returns a context created by the provider.
  98. Outside of the provider, it's completely opaque, but it needs to be
  99. passed back to some of the provider functions.
  100. ossl_provider_forall_loaded() iterates over all the currently
  101. "activated" providers, and calls C<cb> for each of them.
  102. If no providers have been "activated" yet, it tries to activate all
  103. available fallback providers and tries another iteration.
  104. ossl_provider_name() returns the name that was given with
  105. ossl_provider_new().
  106. ossl_provider_dso() returns a reference to the module, for providers
  107. that come in the form of loadable modules.
  108. ossl_provider_module_name() returns the file name of the module, for
  109. providers that come in the form of loadable modules.
  110. ossl_provider_module_path() returns the full path of the module file,
  111. for providers that come in the form of loadable modules.
  112. ossl_provider_teardown() calls the provider's C<teardown> function, if
  113. the provider has one.
  114. ossl_provider_get_param_types() calls the provider's C<get_param_types>
  115. function, if the provider has one.
  116. It should return an array of C<OSSL_ITEM> to describe all the
  117. parameters that the provider has for the I<provider object>.
  118. ossl_provider_get_params() calls the provider's parameter request
  119. responder.
  120. It should treat the given C<OSSL_PARAM> array as described in
  121. L<OSSL_PARAM(3)>.
  122. ossl_provider_query_operation() calls the provider's
  123. C<query_operation> function, if the provider has one.
  124. It should return an array of C<OSSL_ALGORITHM> for the given
  125. C<operation_id>.
  126. =head1 NOTES
  127. Locating a provider module happens as follows:
  128. =over 4
  129. =item 1.
  130. Look in each directory given by ossl_provider_add_module_location().
  131. =item 2.
  132. Look in the directory given by the environment variable
  133. B<OPENSSL_MODULES>.
  134. =item 3.
  135. Look in the directory given by the OpenSSL built in macro
  136. B<MODULESDIR>.
  137. =back
  138. =head1 RETURN VALUES
  139. ossl_provider_find() and ossl_provider_new() return a pointer to a
  140. I<provider object> (C<OSSL_PROVIDER>) on success, or B<NULL> on error.
  141. ossl_provider_upref() returns the value of the reference counter after
  142. it has been incremented.
  143. ossl_provider_free() doesn't return any value.
  144. ossl_provider_add_module_location(), ossl_provider_set_fallback() and
  145. ossl_provider_activate() return 1 on success, or 0 on error.
  146. ossl_provider_name(), ossl_provider_dso(),
  147. ossl_provider_module_name(), and ossl_provider_module_path() return a
  148. pointer to their respective data if it's available, otherwise B<NULL>
  149. is returned.
  150. ossl_provider_teardown() doesnt't return any value.
  151. ossl_provider_get_param_types() returns a pointer to an C<OSSL_ITEM>
  152. array if this function is available in the provider, otherwise
  153. B<NULL>.
  154. ossl_provider_get_params() returns 1 on success, or 0 on error.
  155. If this function isn't available in the provider, 0 is returned.
  156. =head1 SEE ALSO
  157. L<OSSL_PROVIDER(3)>, L<provider(7)>
  158. =head1 HISTORY
  159. The functions described here were all added in OpenSSL 3.0.
  160. =head1 COPYRIGHT
  161. Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
  162. Licensed under the Apache License 2.0 (the "License"). You may not use
  163. this file except in compliance with the License. You can obtain a copy
  164. in the file LICENSE in the source distribution or at
  165. L<https://www.openssl.org/source/license.html>.
  166. =cut