Rename OPENSSL_CTX prefix to OSSL_LIB_CTX
[openssl.git] / doc / man3 / OSSL_PROVIDER.pod
1 =pod
2
3 =head1 NAME
4
5 OSSL_PROVIDER_set_default_search_path,
6 OSSL_PROVIDER, OSSL_PROVIDER_load, OSSL_PROVIDER_try_load, OSSL_PROVIDER_unload,
7 OSSL_PROVIDER_available, OSSL_PROVIDER_do_all,
8 OSSL_PROVIDER_gettable_params, OSSL_PROVIDER_get_params,
9 OSSL_PROVIDER_query_operation, OSSL_PROVIDER_get0_provider_ctx,
10 OSSL_PROVIDER_add_builtin, OSSL_PROVIDER_name,
11 OSSL_PROVIDER_get_capabilities, OSSL_PROVIDER_self_test
12 - provider routines
13
14 =head1 SYNOPSIS
15
16  #include <openssl/provider.h>
17
18  typedef struct ossl_provider_st OSSL_PROVIDER;
19
20  void OSSL_PROVIDER_set_default_search_path(OSSL_LIB_CTX *libctx,
21                                             const char *path);
22
23  OSSL_PROVIDER *OSSL_PROVIDER_load(OSSL_LIB_CTX *libctx, const char *name);
24  OSSL_PROVIDER *OSSL_PROVIDER_try_load(OSSL_LIB_CTX *libctx, const char *name);
25  int OSSL_PROVIDER_unload(OSSL_PROVIDER *prov);
26  int OSSL_PROVIDER_available(OSSL_LIB_CTX *libctx, const char *name);
27  int OSSL_PROVIDER_do_all(OSSL_LIB_CTX *ctx,
28                           int (*cb)(OSSL_PROVIDER *provider, void *cbdata),
29                           void *cbdata);
30
31  const OSSL_PARAM *OSSL_PROVIDER_gettable_params(OSSL_PROVIDER *prov);
32  int OSSL_PROVIDER_get_params(OSSL_PROVIDER *prov, OSSL_PARAM params[]);
33
34  const OSSL_ALGORITHM *OSSL_PROVIDER_query_operation(const OSSL_PROVIDER *prov,
35                                                      int operation_id,
36                                                      int *no_cache);
37  void *OSSL_PROVIDER_get0_provider_ctx(const OSSL_PROVIDER *prov);
38
39  int OSSL_PROVIDER_add_builtin(OSSL_LIB_CTX *libctx, const char *name,
40                                ossl_provider_init_fn *init_fn);
41
42  const char *OSSL_PROVIDER_name(const OSSL_PROVIDER *prov);
43
44  int OSSL_PROVIDER_get_capabilities(const OSSL_PROVIDER *prov,
45                                     const char *capability,
46                                     OSSL_CALLBACK *cb,
47                                     void *arg);
48  int OSSL_PROVIDER_self_test(const OSSL_PROVIDER *prov);
49
50 =head1 DESCRIPTION
51
52 B<OSSL_PROVIDER> is a type that holds internal information about
53 implementation providers (see L<provider(7)> for information on what a
54 provider is).
55 A provider can be built in to the application or the OpenSSL
56 libraries, or can be a loadable module.
57 The functions described here handle both forms.
58
59 Some of these functions operate within a library context, please see
60 L<OSSL_LIB_CTX(3)> for further details.
61
62 =head2 Functions
63
64 OSSL_PROVIDER_set_default_search_path() specifies the default search B<path>
65 that is to be used for looking for providers in the specified B<libctx>.
66 If left unspecified, an environment variable and a fall back default value will
67 be used instead.
68
69 OSSL_PROVIDER_add_builtin() is used to add a built in provider to
70 B<OSSL_PROVIDER> store in the given library context, by associating a
71 provider name with a provider initialization function.
72 This name can then be used with OSSL_PROVIDER_load().
73
74 OSSL_PROVIDER_load() loads and initializes a provider.
75 This may simply initialize a provider that was previously added with
76 OSSL_PROVIDER_add_builtin() and run its given initialization function,
77 or load a provider module with the given name and run its provider
78 entry point, C<OSSL_provider_init>.
79
80 OSSL_PROVIDER_try_load() functions like OSSL_PROVIDER_load(), except that
81 it does not disable the fall-back providers if the provider cannot be
82 loaded and initialized.
83 If the provider loads successfully, however, the fall-back providers are
84 disabled.
85
86 OSSL_PROVIDER_unload() unloads the given provider.
87 For a provider added with OSSL_PROVIDER_add_builtin(), this simply
88 runs its teardown function.
89
90 OSSL_PROVIDER_available() checks if a named provider is available
91 for use.
92
93 OSSL_PROVIDER_do_all() iterates over all loaded providers, calling
94 I<cb> for each one, with the current provider in I<provider> and the
95 I<cbdata> that comes from the caller.
96
97 OSSL_PROVIDER_gettable_params() is used to get a provider parameter
98 descriptor set as a constant B<OSSL_PARAM> array.
99 See L<OSSL_PARAM(3)> for more information.
100
101 OSSL_PROVIDER_get_params() is used to get provider parameter values.
102 The caller must prepare the B<OSSL_PARAM> array before calling this
103 function, and the variables acting as buffers for this parameter array
104 should be filled with data when it returns successfully.
105
106 OSSL_PROVIDER_self_test() is used to run a provider's self tests on demand.
107 If the self tests fail then the provider will fail to provide any further
108 services and algorithms. L<OSSL_SELF_TEST_set_callback(3)> may be called
109 beforehand in order to display diagnostics for the running self tests.
110
111 OSSL_PROVIDER_query_operation() calls the provider's I<query_operation>
112 function (see L<provider(7)>), if the provider has one. It returns an
113 array of I<OSSL_ALGORITHM> for the given I<operation_id> terminated by an all
114 NULL OSSL_ALGORITHM entry. This is considered a low-level function that most
115 applications should not need to call.
116
117 OSSL_PROVIDER_get0_provider_ctx() returns the provider context for the given
118 provider. The provider context is an opaque handle set by the provider itself
119 and is passed back to the provider by libcrypto in various function calls.
120
121 If it is permissible to cache references to this array then I<*no_store> is set
122 to 0 or 1 otherwise. If the array is not cacheable then it is assumed to
123 have a short lifetime.
124
125 OSSL_PROVIDER_name() returns the name of the given provider.
126
127 OSSL_PROVIDER_get_capabilities() provides information about the capabilities
128 supported by the provider specified in I<prov> with the capability name
129 I<capability>. For each capability of that name supported by the provider it
130 will call the callback I<cb> and supply a set of B<OSSL_PARAM>s describing the
131 capability. It will also pass back the argument I<arg>. For more details about
132 capabilities and what they can be used for please see
133 L<provider-base(7)/CAPABILTIIES>.
134
135 =head1 RETURN VALUES
136
137 OSSL_PROVIDER_add(), OSSL_PROVIDER_unload(), OSSL_PROVIDER_get_params() and
138 OSSL_PROVIDER_get_capabilities() return 1 on success, or 0 on error.
139
140 OSSL_PROVIDER_load() and OSSL_PROVIDER_try_load() return a pointer to a
141 provider object on success, or B<NULL> on error.
142
143 OSSL_PROVIDER_available() returns 1 if the named provider is available,
144 otherwise 0.
145
146 OSSL_PROVIDER_gettable_params() returns a pointer to an array
147 of constant B<OSSL_PARAM>, or NULL if none is provided.
148
149 OSSL_PROVIDER_get_params() and returns 1 on success, or 0 on error.
150
151 OSSL_PROVIDER_query_operation() returns an array of OSSL_ALGORITHM or NULL on
152 error.
153
154 OSSL_PROVIDER_self_test() returns 1 if the self tests pass, or 0 on error.
155
156 =head1 EXAMPLES
157
158 This demonstrates how to load the provider module "foo" and ask for
159 its build number.
160
161  OSSL_PROVIDER *prov = NULL;
162  const char *build = NULL;
163  size_t built_l = 0;
164  OSSL_PARAM request[] = {
165      { "build", OSSL_PARAM_UTF8_STRING_PTR, &build, 0, &build_l },
166      { NULL, 0, NULL, 0, NULL }
167  };
168
169  if ((prov = OSSL_PROVIDER_load(NULL, "foo")) != NULL
170      && OSSL_PROVIDER_get_params(prov, request))
171      printf("Provider 'foo' build %s\n", build);
172  else
173      ERR_print_errors_fp(stderr);
174
175 =head1 SEE ALSO
176
177 L<openssl-core.h(7)>, L<OSSL_LIB_CTX(3)>, L<provider(7)>
178
179 =head1 HISTORY
180
181 The type and functions described here were added in OpenSSL 3.0.
182
183 =head1 COPYRIGHT
184
185 Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
186
187 Licensed under the Apache License 2.0 (the "License").  You may not use
188 this file except in compliance with the License.  You can obtain a copy
189 in the file LICENSE in the source distribution or at
190 L<https://www.openssl.org/source/license.html>.
191
192 =cut