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