5 ossl_provider_find, ossl_provider_new, ossl_provider_up_ref,
7 ossl_provider_set_fallback, ossl_provider_set_module_path,
8 ossl_provider_add_parameter,
9 ossl_provider_activate, ossl_provider_available,
11 ossl_provider_forall_loaded,
12 ossl_provider_name, ossl_provider_dso,
13 ossl_provider_module_name, ossl_provider_module_path,
14 ossl_provider_library_context,
15 ossl_provider_teardown, ossl_provider_gettable_params,
16 ossl_provider_get_params, ossl_provider_query_operation,
17 ossl_provider_set_operation_bit, ossl_provider_test_operation_bit,
18 ossl_provider_get_capabilities
19 - internal provider routines
23 #include "internal/provider.h"
25 OSSL_PROVIDER *ossl_provider_find(OSSL_LIB_CTX *libctx, const char *name,
27 OSSL_PROVIDER *ossl_provider_new(OSSL_LIB_CTX *libctx, const char *name,
28 ossl_provider_init_fn *init_function
30 int ossl_provider_up_ref(OSSL_PROVIDER *prov);
31 void ossl_provider_free(OSSL_PROVIDER *prov);
34 int ossl_provider_set_fallback(OSSL_PROVIDER *prov);
35 int ossl_provider_set_module_path(OSSL_PROVIDER *prov, const char *path);
36 int ossl_provider_add_parameter(OSSL_PROVIDER *prov, const char *name,
39 /* Load and initialize the Provider */
40 int ossl_provider_activate(OSSL_PROVIDER *prov);
41 /* Check if provider is available */
42 int ossl_provider_available(OSSL_PROVIDER *prov);
44 /* Return pointer to the provider's context */
45 void *ossl_provider_ctx(const OSSL_PROVIDER *prov);
47 /* Iterate over all loaded providers */
48 int ossl_provider_forall_loaded(OSSL_LIB_CTX *,
49 int (*cb)(OSSL_PROVIDER *provider,
53 /* Getters for other library functions */
54 const char *ossl_provider_name(OSSL_PROVIDER *prov);
55 const DSO *ossl_provider_dso(OSSL_PROVIDER *prov);
56 const char *ossl_provider_module_name(OSSL_PROVIDER *prov);
57 const char *ossl_provider_module_path(OSSL_PROVIDER *prov);
58 OSSL_LIB_CTX *ossl_provider_library_context(const OSSL_PROVIDER *prov);
60 /* Thin wrappers around calls to the provider */
61 void ossl_provider_teardown(const OSSL_PROVIDER *prov);
62 const OSSL_PARAM *ossl_provider_gettable_params(const OSSL_PROVIDER *prov);
63 int ossl_provider_get_params(const OSSL_PROVIDER *prov, OSSL_PARAM params[]);
64 int ossl_provider_get_capabilities(const OSSL_PROVIDER *prov,
65 const char *capability,
68 const OSSL_ALGORITHM *ossl_provider_query_operation(const OSSL_PROVIDER *prov,
72 int ossl_provider_set_operation_bit(OSSL_PROVIDER *provider, size_t bitnum);
73 int ossl_provider_test_operation_bit(OSSL_PROVIDER *provider, size_t bitnum,
78 I<OSSL_PROVIDER> is a type that holds all the necessary information
79 to handle a provider, regardless of if it's built in to the
80 application or the OpenSSL libraries, or if it's a loadable provider
82 Instances of this type are commonly referred to as "provider objects".
84 A provider object is always stored in a set of provider objects
85 in the library context.
87 Provider objects are reference counted.
89 Provider objects are initially inactive, i.e. they are only recorded
90 in the store, but are not used.
91 They are activated with the first call to ossl_provider_activate(),
92 and are inactivated when ossl_provider_free() has been called as many
93 times as ossl_provider_activate() has.
97 ossl_provider_find() finds an existing provider object in the provider
98 object store by I<name>.
99 The config file will be automatically loaded unless I<noconfig> is set.
100 Typically I<noconfig> should be 0.
101 We set I<noconfig> to 1 only when calling these functions while processing a
102 config file in order to avoid recursively attempting to load the file.
103 The provider object it finds has its reference count incremented.
105 ossl_provider_new() creates a new provider object named I<name> and
106 stores it in the provider object store, unless there already is one
107 there with the same name.
108 If there already is one with the same name, it's returned with its
109 reference count incremented.
110 The config file will be automatically loaded unless I<noconfig> is set.
111 Typically I<noconfig> should be 0.
112 We set I<noconfig> to 1 only when calling these functions while processing a
113 config file in order to avoid recursively attempting to load the file.
114 The reference count of a newly created provider object will always
115 be 2; one for being added to the store, and one for the returned
117 If I<init_function> is NULL, the provider is assumed to be a
118 dynamically loadable module, with the symbol B<OSSL_provider_init> as
119 its initialisation function.
120 If I<init_function> isn't NULL, the provider is assumed to be built
121 in, with I<init_function> being the pointer to its initialisation
123 For further description of the initialisation function, see the
124 description of ossl_provider_activate() below.
126 ossl_provider_up_ref() increments the provider object I<prov>'s
129 ossl_provider_free() decrements the provider object I<prov>'s
130 reference count; if it drops below 2, the provider object is assumed
131 to have fallen out of use and will be deactivated (its I<teardown>
132 function is called); if it drops down to zero, I<prov> is assumed to
133 have been taken out of the store, and the associated module will be
134 unloaded if one was loaded, and I<prov> itself will be freed.
136 ossl_provider_set_fallback() marks an available provider I<prov> as
138 Note that after this call, the provider object pointer that was
139 used can simply be dropped, but not freed.
141 ossl_provider_set_module_path() sets the module path to load the
142 provider module given the provider object I<prov>.
143 This will be used in preference to automatically trying to figure out
144 the path from the provider name and the default module directory (more
145 on this in L</NOTES>).
147 ossl_provider_library_context() returns the library context the given
148 provider I<prov> is registered in.
150 ossl_provider_add_parameter() adds a global parameter for the provider
151 to retrieve as it sees fit.
152 The parameters are a combination of I<name> and I<value>, and the
153 provider will use the name to find the value it wants.
154 Only text parameters can be given, and it's up to the provider to
157 ossl_provider_activate() "activates" the provider for the given
158 provider object I<prov>.
159 What "activates" means depends on what type of provider object it
166 If an initialization function was given with ossl_provider_new(), that
167 function will get called.
171 If no initialization function was given with ossl_provider_new(), a
172 loadable module with the I<name> that was given to ossl_provider_new()
173 will be located and loaded, then the symbol B<OSSL_provider_init> will
174 be located in that module, and called.
178 ossl_provider_available() activates all fallbacks if no provider is
179 activated yet, then checks if given provider object I<prov> is
182 ossl_provider_ctx() returns a context created by the provider.
183 Outside of the provider, it's completely opaque, but it needs to be
184 passed back to some of the provider functions.
186 ossl_provider_forall_loaded() iterates over all the currently
187 "activated" providers, and calls I<cb> for each of them.
188 If no providers have been "activated" yet, it tries to activate all
189 available fallback providers and tries another iteration.
191 ossl_provider_name() returns the name that was given with
194 ossl_provider_dso() returns a reference to the module, for providers
195 that come in the form of loadable modules.
197 ossl_provider_module_name() returns the filename of the module, for
198 providers that come in the form of loadable modules.
200 ossl_provider_module_path() returns the full path of the module file,
201 for providers that come in the form of loadable modules.
203 ossl_provider_teardown() calls the provider's I<teardown> function, if
204 the provider has one.
206 ossl_provider_gettable_params() calls the provider's I<gettable_params>
207 function, if the provider has one.
208 It should return an array of I<OSSL_PARAM> to describe all the
209 parameters that the provider has for the provider object.
211 ossl_provider_get_params() calls the provider's parameter request
213 It should treat the given I<OSSL_PARAM> array as described in
216 ossl_provider_get_capabilities() calls the provider's I<get_capabilities> function,
217 if the provider has one. It provides the name of the I<capability> and a
218 callback I<cb> parameter to call for each capability that has a matching name in
219 the provider. The callback gets passed OSSL_PARAM details about the capability as
220 well as the caller supplied argument I<arg>.
222 ossl_provider_query_operation() calls the provider's
223 I<query_operation> function, if the provider has one.
224 It should return an array of I<OSSL_ALGORITHM> for the given
227 ossl_provider_set_operation_bit() registers a 1 for operation I<bitnum>
228 in a bitstring that's internal to I<provider>.
230 ossl_provider_tests_operation_bit() checks if the bit operation I<bitnum>
231 is set (1) or not (0) in the internal I<provider> bitstring, and sets
232 I<*result> to 1 or 0 accorddingly.
236 Locating a provider module happens as follows:
242 If a path was given with ossl_provider_set_module_path(), use that as
244 Otherwise, use the provider object's name as module path, with
245 platform specific standard extensions added.
249 If the environment variable B<OPENSSL_MODULES> is defined, assume its
250 value is a directory specification and merge it with the module path.
251 Otherwise, merge the value of the OpenSSL built in macro B<MODULESDIR>
252 with the module path.
256 When this process is done, the result is used when trying to load the
259 The command C<openssl version -m> can be used to find out the value
260 of the built in macro B<MODULESDIR>.
264 ossl_provider_find() and ossl_provider_new() return a pointer to a
265 provider object (I<OSSL_PROVIDER>) on success, or NULL on error.
267 ossl_provider_up_ref() returns the value of the reference count after
268 it has been incremented.
270 ossl_provider_free() doesn't return any value.
272 ossl_provider_set_module_path(), ossl_provider_set_fallback() and
273 ossl_provider_activate() return 1 on success, or 0 on error.
275 ossl_provider_available() return 1 if the provider is available,
278 ossl_provider_name(), ossl_provider_dso(),
279 ossl_provider_module_name(), and ossl_provider_module_path() return a
280 pointer to their respective data if it's available, otherwise NULL
283 ossl_provider_library_context() return a pointer to the library context.
284 This may be NULL, and is perfectly valid, as it denotes the default
285 global library context.
287 ossl_provider_teardown() doesn't return any value.
289 ossl_provider_gettable_params() returns a pointer to a constant
290 I<OSSL_PARAM> array if this function is available in the provider,
293 ossl_provider_get_params() returns 1 on success, or 0 on error.
294 If this function isn't available in the provider, 0 is returned.
296 ossl_provider_set_operation_bit() and ossl_provider_test_operation_bit()
297 return 1 on success, or 0 on error.
299 ossl_provider_get_capabilities() returns 1 on success, or 0 on error.
300 If this function isn't available in the provider or the provider does not
301 support the requested capability then 0 is returned.
305 L<OSSL_PROVIDER(3)>, L<provider(7)>, L<openssl(1)>
309 The functions described here were all added in OpenSSL 3.0.
313 Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
315 Licensed under the Apache License 2.0 (the "License"). You may not use
316 this file except in compliance with the License. You can obtain a copy
317 in the file LICENSE in the source distribution or at
318 L<https://www.openssl.org/source/license.html>.