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_teardown, ossl_provider_get_param_types,
15 ossl_provider_get_params, ossl_provider_query_operation
16 - internal provider routines
20 #include "internal/provider.h"
22 OSSL_PROVIDER *ossl_provider_find(OPENSSL_CTX *libctx, const char *name);
23 OSSL_PROVIDER *ossl_provider_new(OPENSSL_CTX *libctx, const char *name,
24 ossl_provider_init_fn *init_function);
25 int ossl_provider_up_ref(OSSL_PROVIDER *prov);
26 void ossl_provider_free(OSSL_PROVIDER *prov);
29 int ossl_provider_set_fallback(OSSL_PROVIDER *prov);
30 int ossl_provider_set_module_path(OSSL_PROVIDER *prov, const char *path);
31 int ossl_provider_add_parameter(OSSL_PROVIDER *prov, const char *name,
34 /* Load and initialize the Provider */
35 int ossl_provider_activate(OSSL_PROVIDER *prov);
36 /* Check if provider is available */
37 int ossl_provider_available(OSSL_PROVIDER *prov);
39 /* Return pointer to the provider's context */
40 void *ossl_provider_ctx(const OSSL_PROVIDER *prov);
42 /* Iterate over all loaded providers */
43 int ossl_provider_forall_loaded(OPENSSL_CTX *,
44 int (*cb)(OSSL_PROVIDER *provider,
48 /* Getters for other library functions */
49 const char *ossl_provider_name(OSSL_PROVIDER *prov);
50 const DSO *ossl_provider_dso(OSSL_PROVIDER *prov);
51 const char *ossl_provider_module_name(OSSL_PROVIDER *prov);
52 const char *ossl_provider_module_path(OSSL_PROVIDER *prov);
54 /* Thin wrappers around calls to the provider */
55 void ossl_provider_teardown(const OSSL_PROVIDER *prov);
56 const OSSL_PARAM *ossl_provider_get_param_types(const OSSL_PROVIDER *prov);
57 int ossl_provider_get_params(const OSSL_PROVIDER *prov, OSSL_PARAM params[]);
58 const OSSL_ALGORITHM *ossl_provider_query_operation(const OSSL_PROVIDER *prov,
64 I<OSSL_PROVIDER> is a type that holds all the necessary information
65 to handle a provider, regardless of if it's built in to the
66 application or the OpenSSL libraries, or if it's a loadable provider
68 Instances of this type are commonly referred to as "provider objects".
70 A provider object is always stored in a set of provider objects
71 in the library context.
73 Provider objects are reference counted.
75 Provider objects are initially inactive, i.e. they are only recorded
76 in the store, but are not used.
77 They are activated with the first call to ossl_provider_activate(),
78 and are inactivated when ossl_provider_free() has been called as many
79 times as ossl_provider_activate() has.
83 ossl_provider_find() finds an existing provider object in the provider
84 object store by I<name>.
85 The provider object it finds has its reference count incremented.
87 ossl_provider_new() creates a new provider object named I<name> and
88 stores it in the provider object store, unless there already is one
89 there with the same name.
90 If there already is one with the same name, it's returned with its
91 reference count incremented.
92 The reference count of a newly created provider object will always
93 be 2; one for being added to the store, and one for the returned
95 If I<init_function> is NULL, the provider is assumed to be a
96 dynamically loadable module, with the symbol B<OSSL_provider_init> as
97 its initialisation function.
98 If I<init_function> isn't NULL, the provider is assumed to be built
99 in, with I<init_function> being the pointer to its initialisation
101 For further description of the initialisation function, see the
102 description of ossl_provider_activate() below.
104 ossl_provider_up_ref() increments the provider object I<prov>'s
107 ossl_provider_free() decrements the provider object I<prov>'s
108 reference count; if it drops below 2, the provider object is assumed
109 to have fallen out of use and will be deactivated (its I<teardown>
110 function is called); if it drops down to zero, I<prov> is assumed to
111 have been taken out of the store, and the associated module will be
112 unloaded if one was loaded, and I<prov> itself will be freed.
114 ossl_provider_set_fallback() marks an available provider I<prov> as
116 Note that after this call, the provider object pointer that was
117 used can simply be dropped, but not freed.
119 ossl_provider_set_module_path() sets the module path to load the
120 provider module given the provider object I<prov>.
121 This will be used in preference to automatically trying to figure out
122 the path from the provider name and the default module directory (more
123 on this in L</NOTES>).
125 ossl_provider_add_parameter() adds a global parameter for the provider
126 to retrieve as it sees fit.
127 The parameters are a combination of I<name> and I<value>, and the
128 provider will use the name to find the value it wants.
129 Only text parameters can be given, and it's up to the provider to
132 ossl_provider_activate() "activates" the provider for the given
133 provider object I<prov>.
134 What "activates" means depends on what type of provider object it
141 If an initialization function was given with ossl_provider_new(), that
142 function will get called.
146 If no initialization function was given with ossl_provider_new(), a
147 loadable module with the I<name> that was given to ossl_provider_new()
148 will be located and loaded, then the symbol B<OSSL_provider_init> will
149 be located in that module, and called.
153 ossl_provider_available() activates all fallbacks if no provider is
154 activated yet, then checks if given provider object I<prov> is
157 ossl_provider_ctx() returns a context created by the provider.
158 Outside of the provider, it's completely opaque, but it needs to be
159 passed back to some of the provider functions.
161 ossl_provider_forall_loaded() iterates over all the currently
162 "activated" providers, and calls I<cb> for each of them.
163 If no providers have been "activated" yet, it tries to activate all
164 available fallback providers and tries another iteration.
166 ossl_provider_name() returns the name that was given with
169 ossl_provider_dso() returns a reference to the module, for providers
170 that come in the form of loadable modules.
172 ossl_provider_module_name() returns the file name of the module, for
173 providers that come in the form of loadable modules.
175 ossl_provider_module_path() returns the full path of the module file,
176 for providers that come in the form of loadable modules.
178 ossl_provider_teardown() calls the provider's I<teardown> function, if
179 the provider has one.
181 ossl_provider_get_param_types() calls the provider's I<get_param_types>
182 function, if the provider has one.
183 It should return an array of I<OSSL_PARAM> to describe all the
184 parameters that the provider has for the provider object.
186 ossl_provider_get_params() calls the provider's parameter request
188 It should treat the given I<OSSL_PARAM> array as described in
191 ossl_provider_query_operation() calls the provider's
192 I<query_operation> function, if the provider has one.
193 It should return an array of I<OSSL_ALGORITHM> for the given
198 Locating a provider module happens as follows:
204 If a path was given with ossl_provider_set_module_path(), use that as
206 Otherwise, use the provider object's name as module path, with
207 platform specific standard extensions added.
211 If the environment variable B<OPENSSL_MODULES> is defined, assume its
212 value is a directory specification and merge it with the module path.
213 Otherwise, merge the value of the OpenSSL built in macro B<MODULESDIR>
214 with the module path.
218 When this process is done, the result is used when trying to load the
221 The command C<openssl version -m> can be used to find out the value
222 of the built in macro B<MODULESDIR>.
226 ossl_provider_find() and ossl_provider_new() return a pointer to a
227 provider object (I<OSSL_PROVIDER>) on success, or NULL on error.
229 ossl_provider_up_ref() returns the value of the reference count after
230 it has been incremented.
232 ossl_provider_free() doesn't return any value.
234 ossl_provider_set_module_path(), ossl_provider_set_fallback() and
235 ossl_provider_activate() return 1 on success, or 0 on error.
237 ossl_provider_available() return 1 if the provider is available,
240 ossl_provider_name(), ossl_provider_dso(),
241 ossl_provider_module_name(), and ossl_provider_module_path() return a
242 pointer to their respective data if it's available, otherwise NULL
245 ossl_provider_teardown() doesnt't return any value.
247 ossl_provider_get_param_types() returns a pointer to a constant
248 I<OSSL_PARAM> array if this function is available in the provider,
251 ossl_provider_get_params() returns 1 on success, or 0 on error.
252 If this function isn't available in the provider, 0 is returned.
256 L<OSSL_PROVIDER(3)>, L<provider(7)>, L<openssl(1)>
260 The functions described here were all added in OpenSSL 3.0.
264 Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
266 Licensed under the Apache License 2.0 (the "License"). You may not use
267 this file except in compliance with the License. You can obtain a copy
268 in the file LICENSE in the source distribution or at
269 L<https://www.openssl.org/source/license.html>.