]> git.ipfire.org Git - thirdparty/openssl.git/blame - doc/internal/man3/ossl_provider_new.pod
Update documentation following addition of OSSL_LIB_CTX_new_child()
[thirdparty/openssl.git] / doc / internal / man3 / ossl_provider_new.pod
CommitLineData
c4532834
RL
1=pod
2
3=head1 NAME
4
7c95390e 5ossl_provider_find, ossl_provider_new, ossl_provider_up_ref,
3bbec1af
RL
6ossl_provider_free,
7ossl_provider_set_fallback, ossl_provider_set_module_path,
878be71c
MC
8ossl_provider_add_parameter, ossl_provider_set_child, ossl_provider_get_parent,
9ossl_provider_up_ref_parent, ossl_provider_free_parent,
10ossl_provider_get0_dispatch, ossl_provider_init_child_providers,
11ossl_provider_init_as_child,
390f9bad 12ossl_provider_activate, ossl_provider_deactivate, ossl_provider_available,
3bbec1af 13ossl_provider_ctx,
8f089576 14ossl_provider_doall_activated,
85e2417c 15ossl_provider_name, ossl_provider_dso,
c4532834 16ossl_provider_module_name, ossl_provider_module_path,
a829b735 17ossl_provider_libctx,
dca97d00 18ossl_provider_teardown, ossl_provider_gettable_params,
2876528d 19ossl_provider_get_params, ossl_provider_clear_all_operation_bits,
b0001d0c 20ossl_provider_query_operation, ossl_provider_unquery_operation,
82ec09ec
MC
21ossl_provider_set_operation_bit, ossl_provider_test_operation_bit,
22ossl_provider_get_capabilities
099bd339 23- internal provider routines
c4532834
RL
24
25=head1 SYNOPSIS
26
27 #include "internal/provider.h"
28
b4250010 29 OSSL_PROVIDER *ossl_provider_find(OSSL_LIB_CTX *libctx, const char *name,
29dc6e00 30 int noconfig);
b4250010 31 OSSL_PROVIDER *ossl_provider_new(OSSL_LIB_CTX *libctx, const char *name,
29dc6e00
MC
32 ossl_provider_init_fn *init_function
33 int noconfig);
7c95390e 34 int ossl_provider_up_ref(OSSL_PROVIDER *prov);
c4532834
RL
35 void ossl_provider_free(OSSL_PROVIDER *prov);
36
37 /* Setters */
e55008a9 38 int ossl_provider_set_fallback(OSSL_PROVIDER *prov);
3bbec1af
RL
39 int ossl_provider_set_module_path(OSSL_PROVIDER *prov, const char *path);
40 int ossl_provider_add_parameter(OSSL_PROVIDER *prov, const char *name,
41 const char *value);
c4532834 42
878be71c
MC
43 /* Child Providers */
44 int ossl_provider_set_child(OSSL_PROVIDER *prov,
45 const OSSL_CORE_HANDLE *handle);
46 const OSSL_CORE_HANDLE *ossl_provider_get_parent(OSSL_PROVIDER *prov);
47 int ossl_provider_up_ref_parent(OSSL_PROVIDER *prov, int activate);
48 int ossl_provider_free_parent(OSSL_PROVIDER *prov, int deactivate);
49
390f9bad
RL
50 /*
51 * Activate the Provider
52 * If the Provider is a module, the module will be loaded
53 */
878be71c
MC
54 int ossl_provider_activate(OSSL_PROVIDER *prov, int retain_fallbacks,
55 int upcalls);
390f9bad
RL
56 int ossl_provider_deactivate(OSSL_PROVIDER *prov);
57 /* Check if provider is available (activated) */
36f5ec55 58 int ossl_provider_available(OSSL_PROVIDER *prov);
c4532834 59
a39eb840
RL
60 /* Return pointer to the provider's context */
61 void *ossl_provider_ctx(const OSSL_PROVIDER *prov);
62
878be71c
MC
63 const OSSL_DISPATCH *ossl_provider_get0_dispatch(const OSSL_PROVIDER *prov);
64
85e2417c 65 /* Iterate over all loaded providers */
8f089576
P
66 int ossl_provider_doall_activated(OSSL_LIB_CTX *,
67 int (*cb)(OSSL_PROVIDER *provider,
68 void *cbdata),
69 void *cbdata);
85e2417c 70
c4532834
RL
71 /* Getters for other library functions */
72 const char *ossl_provider_name(OSSL_PROVIDER *prov);
73 const DSO *ossl_provider_dso(OSSL_PROVIDER *prov);
74 const char *ossl_provider_module_name(OSSL_PROVIDER *prov);
75 const char *ossl_provider_module_path(OSSL_PROVIDER *prov);
a829b735 76 OSSL_LIB_CTX *ossl_provider_libctx(const OSSL_PROVIDER *prov);
c4532834
RL
77
78 /* Thin wrappers around calls to the provider */
79 void ossl_provider_teardown(const OSSL_PROVIDER *prov);
dca97d00 80 const OSSL_PARAM *ossl_provider_gettable_params(const OSSL_PROVIDER *prov);
4e7991b4 81 int ossl_provider_get_params(const OSSL_PROVIDER *prov, OSSL_PARAM params[]);
82ec09ec
MC
82 int ossl_provider_get_capabilities(const OSSL_PROVIDER *prov,
83 const char *capability,
84 OSSL_CALLBACK *cb,
85 void *arg);
099bd339
RL
86 const OSSL_ALGORITHM *ossl_provider_query_operation(const OSSL_PROVIDER *prov,
87 int operation_id,
88 int *no_cache);
b0001d0c
P
89 void ossl_provider_unquery_operation(const OSSL_PROVIDER *prov,
90 int operation_id,
91 const OSSL_ALGORITHM *algs);
c4532834 92
5a29b628
RL
93 int ossl_provider_set_operation_bit(OSSL_PROVIDER *provider, size_t bitnum);
94 int ossl_provider_test_operation_bit(OSSL_PROVIDER *provider, size_t bitnum,
95 int *result);
2876528d 96 int ossl_provider_clear_all_operation_bits(OSSL_LIB_CTX *libctx);
5a29b628 97
878be71c
MC
98 int ossl_provider_init_child_providers(OSSL_LIB_CTX *ctx);
99 int ossl_provider_init_as_child(OSSL_LIB_CTX *ctx,
100 const OSSL_CORE_HANDLE *handle,
101 const OSSL_DISPATCH *in);
102
103
c4532834
RL
104=head1 DESCRIPTION
105
3bbec1af 106I<OSSL_PROVIDER> is a type that holds all the necessary information
c4532834
RL
107to handle a provider, regardless of if it's built in to the
108application or the OpenSSL libraries, or if it's a loadable provider
109module.
3bbec1af 110Instances of this type are commonly referred to as "provider objects".
c4532834 111
3bbec1af 112A provider object is always stored in a set of provider objects
c4532834
RL
113in the library context.
114
3bbec1af 115Provider objects are reference counted.
c4532834 116
3bbec1af
RL
117Provider objects are initially inactive, i.e. they are only recorded
118in the store, but are not used.
c4532834 119They are activated with the first call to ossl_provider_activate(),
390f9bad
RL
120and are deactivated with the last call to ossl_provider_deactivate().
121Activation affects a separate counter.
c4532834
RL
122
123=head2 Functions
124
3bbec1af 125ossl_provider_find() finds an existing provider object in the provider
29dc6e00
MC
126object store by I<name>.
127The config file will be automatically loaded unless I<noconfig> is set.
128Typically I<noconfig> should be 0.
129We set I<noconfig> to 1 only when calling these functions while processing a
130config file in order to avoid recursively attempting to load the file.
3bbec1af
RL
131The provider object it finds has its reference count incremented.
132
133ossl_provider_new() creates a new provider object named I<name> and
134stores it in the provider object store, unless there already is one
135there with the same name.
136If there already is one with the same name, it's returned with its
137reference count incremented.
29dc6e00
MC
138The config file will be automatically loaded unless I<noconfig> is set.
139Typically I<noconfig> should be 0.
140We set I<noconfig> to 1 only when calling these functions while processing a
141config file in order to avoid recursively attempting to load the file.
3bbec1af
RL
142The reference count of a newly created provider object will always
143be 2; one for being added to the store, and one for the returned
144reference.
145If I<init_function> is NULL, the provider is assumed to be a
146dynamically loadable module, with the symbol B<OSSL_provider_init> as
147its initialisation function.
148If I<init_function> isn't NULL, the provider is assumed to be built
149in, with I<init_function> being the pointer to its initialisation
150function.
151For further description of the initialisation function, see the
152description of ossl_provider_activate() below.
153
7c95390e 154ossl_provider_up_ref() increments the provider object I<prov>'s
3bbec1af
RL
155reference count.
156
157ossl_provider_free() decrements the provider object I<prov>'s
390f9bad
RL
158reference count; when it drops to zero, the provider object is assumed
159to have fallen out of use and will be deinitialized (its I<teardown>
160function is called), and the associated module will be unloaded if one
161was loaded, and I<prov> itself will be freed.
3bbec1af
RL
162
163ossl_provider_set_fallback() marks an available provider I<prov> as
164fallback.
165Note that after this call, the provider object pointer that was
e55008a9
RL
166used can simply be dropped, but not freed.
167
3bbec1af
RL
168ossl_provider_set_module_path() sets the module path to load the
169provider module given the provider object I<prov>.
170This will be used in preference to automatically trying to figure out
171the path from the provider name and the default module directory (more
172on this in L</NOTES>).
173
a829b735 174ossl_provider_libctx() returns the library context the given
e74bd290
RL
175provider I<prov> is registered in.
176
3bbec1af
RL
177ossl_provider_add_parameter() adds a global parameter for the provider
178to retrieve as it sees fit.
179The parameters are a combination of I<name> and I<value>, and the
180provider will use the name to find the value it wants.
181Only text parameters can be given, and it's up to the provider to
182interpret them.
183
878be71c
MC
184ossl_provider_set_child() marks this provider as a child of a provider in the
185parent library context. I<handle> is the B<OSSL_CORE_HANDLE> object passed to
186the provider's B<OSSL_provider_init> function.
187
188ossl_provider_get_parent() obtains the handle on the parent provider.
189
190ossl_provider_up_ref_parent() increases the reference count on the parent
191provider. If I<activate> is nonzero then the parent provider is also activated.
192
193ossl_provider_free_parent() decreases the reference count on the parent
194provider. If I<deactivate> is nonzero then the parent provider is also
195deactivated.
196
c4532834 197ossl_provider_activate() "activates" the provider for the given
390f9bad
RL
198provider object I<prov> by incrementing its activation count, flagging
199it as activated, and initializing it if it isn't already initialized.
200Initializing means one of the following:
c4532834
RL
201
202=over 4
203
204=item *
205
206If an initialization function was given with ossl_provider_new(), that
207function will get called.
208
209=item *
210
c2969ff6 211If no initialization function was given with ossl_provider_new(), a
3bbec1af
RL
212loadable module with the I<name> that was given to ossl_provider_new()
213will be located and loaded, then the symbol B<OSSL_provider_init> will
c4532834
RL
214be located in that module, and called.
215
216=back
217
299f5ff3 218If I<retain_fallbacks> is zero, fallbacks are disabled. If it is nonzero,
878be71c
MC
219fallbacks are left unchanged. If I<upcalls> is nonzero then, if this is a child
220provider, upcalls to the parent libctx will be made to inform it of an
221up-ref.
299f5ff3 222
390f9bad
RL
223ossl_provider_deactivate() "deactivates" the provider for the given
224provider object I<prov> by decrementing its activation count. When
225that count reaches zero, the activation flag is cleared.
226
36f5ec55
RL
227ossl_provider_available() activates all fallbacks if no provider is
228activated yet, then checks if given provider object I<prov> is
229activated.
230
a39eb840
RL
231ossl_provider_ctx() returns a context created by the provider.
232Outside of the provider, it's completely opaque, but it needs to be
233passed back to some of the provider functions.
234
878be71c
MC
235ossl_provider_get0_dispatch() returns the dispatch table that the provider
236initially returned in the I<out> parameter of its B<OSSL_provider_init>
237function.
238
8f089576 239ossl_provider_doall_activated() iterates over all the currently
3bbec1af 240"activated" providers, and calls I<cb> for each of them.
e55008a9 241If no providers have been "activated" yet, it tries to activate all
3c5ce1ce 242available fallback providers before iterating over them.
85e2417c 243
c4532834
RL
244ossl_provider_name() returns the name that was given with
245ossl_provider_new().
246
247ossl_provider_dso() returns a reference to the module, for providers
248that come in the form of loadable modules.
249
9c0586d5 250ossl_provider_module_name() returns the filename of the module, for
c4532834
RL
251providers that come in the form of loadable modules.
252
253ossl_provider_module_path() returns the full path of the module file,
254for providers that come in the form of loadable modules.
255
3bbec1af 256ossl_provider_teardown() calls the provider's I<teardown> function, if
c4532834
RL
257the provider has one.
258
dca97d00 259ossl_provider_gettable_params() calls the provider's I<gettable_params>
c4532834 260function, if the provider has one.
26175013 261It should return an array of I<OSSL_PARAM> to describe all the
3bbec1af 262parameters that the provider has for the provider object.
c4532834
RL
263
264ossl_provider_get_params() calls the provider's parameter request
265responder.
3bbec1af 266It should treat the given I<OSSL_PARAM> array as described in
c4532834
RL
267L<OSSL_PARAM(3)>.
268
82ec09ec
MC
269ossl_provider_get_capabilities() calls the provider's I<get_capabilities> function,
270if the provider has one. It provides the name of the I<capability> and a
271callback I<cb> parameter to call for each capability that has a matching name in
272the provider. The callback gets passed OSSL_PARAM details about the capability as
273well as the caller supplied argument I<arg>.
274
099bd339 275ossl_provider_query_operation() calls the provider's
3bbec1af
RL
276I<query_operation> function, if the provider has one.
277It should return an array of I<OSSL_ALGORITHM> for the given
278I<operation_id>.
b0001d0c
P
279
280ossl_provider_unquery_operation() informs the provider that the result of
281ossl_provider_query_operation() is no longer going to be directly accessed and
282that all relevant information has been copied.
099bd339 283
5a29b628
RL
284ossl_provider_set_operation_bit() registers a 1 for operation I<bitnum>
285in a bitstring that's internal to I<provider>.
286
2876528d 287ossl_provider_test_operation_bit() checks if the bit operation I<bitnum>
5a29b628
RL
288is set (1) or not (0) in the internal I<provider> bitstring, and sets
289I<*result> to 1 or 0 accorddingly.
290
2876528d
P
291ossl_provider_clear_all_operation_bits() clears all of the operation bits
292to (0) for all providers in the library context I<libctx>.
293
878be71c
MC
294ossl_provider_init_child_providers() registers the callbacks required to
295receive notifications about loading and unloading of providers in the parent
296library context.
297
298ossl_provider_init_as_child() stores in the library context I<ctx> references to
299the necessary upcalls for managing child providers. The I<handle> and I<in>
300parameters are the B<OSSL_CORE_HANDLE> and B<OSSL_DISPATCH> pointers that were
301passed to the provider's B<OSSL_provider_init> function.
302
c4532834
RL
303=head1 NOTES
304
305Locating a provider module happens as follows:
306
307=over 4
308
309=item 1.
310
3bbec1af
RL
311If a path was given with ossl_provider_set_module_path(), use that as
312module path.
313Otherwise, use the provider object's name as module path, with
314platform specific standard extensions added.
c4532834
RL
315
316=item 2.
317
3bbec1af
RL
318If the environment variable B<OPENSSL_MODULES> is defined, assume its
319value is a directory specification and merge it with the module path.
320Otherwise, merge the value of the OpenSSL built in macro B<MODULESDIR>
321with the module path.
c4532834 322
3bbec1af 323=back
c4532834 324
3bbec1af
RL
325When this process is done, the result is used when trying to load the
326provider module.
c4532834 327
3bbec1af
RL
328The command C<openssl version -m> can be used to find out the value
329of the built in macro B<MODULESDIR>.
c4532834
RL
330
331=head1 RETURN VALUES
332
333ossl_provider_find() and ossl_provider_new() return a pointer to a
3bbec1af 334provider object (I<OSSL_PROVIDER>) on success, or NULL on error.
c4532834 335
7c95390e 336ossl_provider_up_ref() returns the value of the reference count after
c4532834
RL
337it has been incremented.
338
339ossl_provider_free() doesn't return any value.
340
8f089576 341ossl_provider_doall_activated() returns 1 if the callback was called for all
3c5ce1ce
P
342activated providers. A return value of 0 means that the callback was not
343called for any activated providers.
344
390f9bad 345ossl_provider_set_module_path(), ossl_provider_set_fallback(),
299f5ff3
P
346ossl_provider_activate(), ossl_provider_activate_leave_fallbacks() and
347ossl_provider_deactivate() return 1 on success, or 0 on error.
c4532834 348
36f5ec55
RL
349ossl_provider_available() return 1 if the provider is available,
350otherwise 0.
351
c4532834
RL
352ossl_provider_name(), ossl_provider_dso(),
353ossl_provider_module_name(), and ossl_provider_module_path() return a
3bbec1af 354pointer to their respective data if it's available, otherwise NULL
c4532834
RL
355is returned.
356
a829b735 357ossl_provider_libctx() return a pointer to the library context.
e74bd290
RL
358This may be NULL, and is perfectly valid, as it denotes the default
359global library context.
360
79c44b4e 361ossl_provider_teardown() doesn't return any value.
c4532834 362
dca97d00 363ossl_provider_gettable_params() returns a pointer to a constant
26175013
RL
364I<OSSL_PARAM> array if this function is available in the provider,
365otherwise NULL.
c4532834
RL
366
367ossl_provider_get_params() returns 1 on success, or 0 on error.
368If this function isn't available in the provider, 0 is returned.
369
5a29b628
RL
370ossl_provider_set_operation_bit() and ossl_provider_test_operation_bit()
371return 1 on success, or 0 on error.
372
2876528d
P
373ossl_provider_clear_all_operation_bits() returns 1 on success, or 0 on error.
374
82ec09ec
MC
375ossl_provider_get_capabilities() returns 1 on success, or 0 on error.
376If this function isn't available in the provider or the provider does not
377support the requested capability then 0 is returned.
378
c4532834
RL
379=head1 SEE ALSO
380
3bbec1af 381L<OSSL_PROVIDER(3)>, L<provider(7)>, L<openssl(1)>
c4532834
RL
382
383=head1 HISTORY
384
385The functions described here were all added in OpenSSL 3.0.
386
387=head1 COPYRIGHT
388
8020d79b 389Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
c4532834
RL
390
391Licensed under the Apache License 2.0 (the "License"). You may not use
392this file except in compliance with the License. You can obtain a copy
393in the file LICENSE in the source distribution or at
394L<https://www.openssl.org/source/license.html>.
395
396=cut