]> git.ipfire.org Git - thirdparty/openssl.git/blame - doc/internal/man3/ossl_provider_new.pod
crypto/engine/eng_openssl.c: define TEST_ENG_OPENSSL_RC4_P_INIT conditionally
[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,
36f5ec55 9ossl_provider_activate, ossl_provider_available,
3bbec1af
RL
10ossl_provider_ctx,
11ossl_provider_forall_loaded,
85e2417c 12ossl_provider_name, ossl_provider_dso,
c4532834
RL
13ossl_provider_module_name, ossl_provider_module_path,
14ossl_provider_teardown, ossl_provider_get_param_types,
099bd339
RL
15ossl_provider_get_params, ossl_provider_query_operation
16- internal provider routines
c4532834
RL
17
18=head1 SYNOPSIS
19
20 #include "internal/provider.h"
21
29dc6e00
MC
22 OSSL_PROVIDER *ossl_provider_find(OPENSSL_CTX *libctx, const char *name,
23 int noconfig);
c4532834 24 OSSL_PROVIDER *ossl_provider_new(OPENSSL_CTX *libctx, const char *name,
29dc6e00
MC
25 ossl_provider_init_fn *init_function
26 int noconfig);
7c95390e 27 int ossl_provider_up_ref(OSSL_PROVIDER *prov);
c4532834
RL
28 void ossl_provider_free(OSSL_PROVIDER *prov);
29
30 /* Setters */
e55008a9 31 int ossl_provider_set_fallback(OSSL_PROVIDER *prov);
3bbec1af
RL
32 int ossl_provider_set_module_path(OSSL_PROVIDER *prov, const char *path);
33 int ossl_provider_add_parameter(OSSL_PROVIDER *prov, const char *name,
34 const char *value);
c4532834
RL
35
36 /* Load and initialize the Provider */
37 int ossl_provider_activate(OSSL_PROVIDER *prov);
36f5ec55
RL
38 /* Check if provider is available */
39 int ossl_provider_available(OSSL_PROVIDER *prov);
c4532834 40
a39eb840
RL
41 /* Return pointer to the provider's context */
42 void *ossl_provider_ctx(const OSSL_PROVIDER *prov);
43
85e2417c
RL
44 /* Iterate over all loaded providers */
45 int ossl_provider_forall_loaded(OPENSSL_CTX *,
46 int (*cb)(OSSL_PROVIDER *provider,
47 void *cbdata),
48 void *cbdata);
49
c4532834
RL
50 /* Getters for other library functions */
51 const char *ossl_provider_name(OSSL_PROVIDER *prov);
52 const DSO *ossl_provider_dso(OSSL_PROVIDER *prov);
53 const char *ossl_provider_module_name(OSSL_PROVIDER *prov);
54 const char *ossl_provider_module_path(OSSL_PROVIDER *prov);
55
56 /* Thin wrappers around calls to the provider */
57 void ossl_provider_teardown(const OSSL_PROVIDER *prov);
26175013 58 const OSSL_PARAM *ossl_provider_get_param_types(const OSSL_PROVIDER *prov);
4e7991b4 59 int ossl_provider_get_params(const OSSL_PROVIDER *prov, OSSL_PARAM params[]);
099bd339
RL
60 const OSSL_ALGORITHM *ossl_provider_query_operation(const OSSL_PROVIDER *prov,
61 int operation_id,
62 int *no_cache);
c4532834
RL
63
64=head1 DESCRIPTION
65
3bbec1af 66I<OSSL_PROVIDER> is a type that holds all the necessary information
c4532834
RL
67to handle a provider, regardless of if it's built in to the
68application or the OpenSSL libraries, or if it's a loadable provider
69module.
3bbec1af 70Instances of this type are commonly referred to as "provider objects".
c4532834 71
3bbec1af 72A provider object is always stored in a set of provider objects
c4532834
RL
73in the library context.
74
3bbec1af 75Provider objects are reference counted.
c4532834 76
3bbec1af
RL
77Provider objects are initially inactive, i.e. they are only recorded
78in the store, but are not used.
c4532834
RL
79They are activated with the first call to ossl_provider_activate(),
80and are inactivated when ossl_provider_free() has been called as many
81times as ossl_provider_activate() has.
82
83=head2 Functions
84
3bbec1af 85ossl_provider_find() finds an existing provider object in the provider
29dc6e00
MC
86object store by I<name>.
87The config file will be automatically loaded unless I<noconfig> is set.
88Typically I<noconfig> should be 0.
89We set I<noconfig> to 1 only when calling these functions while processing a
90config file in order to avoid recursively attempting to load the file.
3bbec1af
RL
91The provider object it finds has its reference count incremented.
92
93ossl_provider_new() creates a new provider object named I<name> and
94stores it in the provider object store, unless there already is one
95there with the same name.
96If there already is one with the same name, it's returned with its
97reference count incremented.
29dc6e00
MC
98The config file will be automatically loaded unless I<noconfig> is set.
99Typically I<noconfig> should be 0.
100We set I<noconfig> to 1 only when calling these functions while processing a
101config file in order to avoid recursively attempting to load the file.
3bbec1af
RL
102The reference count of a newly created provider object will always
103be 2; one for being added to the store, and one for the returned
104reference.
105If I<init_function> is NULL, the provider is assumed to be a
106dynamically loadable module, with the symbol B<OSSL_provider_init> as
107its initialisation function.
108If I<init_function> isn't NULL, the provider is assumed to be built
109in, with I<init_function> being the pointer to its initialisation
110function.
111For further description of the initialisation function, see the
112description of ossl_provider_activate() below.
113
7c95390e 114ossl_provider_up_ref() increments the provider object I<prov>'s
3bbec1af
RL
115reference count.
116
117ossl_provider_free() decrements the provider object I<prov>'s
118reference count; if it drops below 2, the provider object is assumed
119to have fallen out of use and will be deactivated (its I<teardown>
120function is called); if it drops down to zero, I<prov> is assumed to
121have been taken out of the store, and the associated module will be
122unloaded if one was loaded, and I<prov> itself will be freed.
123
124ossl_provider_set_fallback() marks an available provider I<prov> as
125fallback.
126Note that after this call, the provider object pointer that was
e55008a9
RL
127used can simply be dropped, but not freed.
128
3bbec1af
RL
129ossl_provider_set_module_path() sets the module path to load the
130provider module given the provider object I<prov>.
131This will be used in preference to automatically trying to figure out
132the path from the provider name and the default module directory (more
133on this in L</NOTES>).
134
135ossl_provider_add_parameter() adds a global parameter for the provider
136to retrieve as it sees fit.
137The parameters are a combination of I<name> and I<value>, and the
138provider will use the name to find the value it wants.
139Only text parameters can be given, and it's up to the provider to
140interpret them.
141
c4532834 142ossl_provider_activate() "activates" the provider for the given
3bbec1af
RL
143provider object I<prov>.
144What "activates" means depends on what type of provider object it
c4532834
RL
145is:
146
147=over 4
148
149=item *
150
151If an initialization function was given with ossl_provider_new(), that
152function will get called.
153
154=item *
155
c2969ff6 156If no initialization function was given with ossl_provider_new(), a
3bbec1af
RL
157loadable module with the I<name> that was given to ossl_provider_new()
158will be located and loaded, then the symbol B<OSSL_provider_init> will
c4532834
RL
159be located in that module, and called.
160
161=back
162
36f5ec55
RL
163ossl_provider_available() activates all fallbacks if no provider is
164activated yet, then checks if given provider object I<prov> is
165activated.
166
a39eb840
RL
167ossl_provider_ctx() returns a context created by the provider.
168Outside of the provider, it's completely opaque, but it needs to be
169passed back to some of the provider functions.
170
85e2417c 171ossl_provider_forall_loaded() iterates over all the currently
3bbec1af 172"activated" providers, and calls I<cb> for each of them.
e55008a9
RL
173If no providers have been "activated" yet, it tries to activate all
174available fallback providers and tries another iteration.
85e2417c 175
c4532834
RL
176ossl_provider_name() returns the name that was given with
177ossl_provider_new().
178
179ossl_provider_dso() returns a reference to the module, for providers
180that come in the form of loadable modules.
181
182ossl_provider_module_name() returns the file name of the module, for
183providers that come in the form of loadable modules.
184
185ossl_provider_module_path() returns the full path of the module file,
186for providers that come in the form of loadable modules.
187
3bbec1af 188ossl_provider_teardown() calls the provider's I<teardown> function, if
c4532834
RL
189the provider has one.
190
3bbec1af 191ossl_provider_get_param_types() calls the provider's I<get_param_types>
c4532834 192function, if the provider has one.
26175013 193It should return an array of I<OSSL_PARAM> to describe all the
3bbec1af 194parameters that the provider has for the provider object.
c4532834
RL
195
196ossl_provider_get_params() calls the provider's parameter request
197responder.
3bbec1af 198It should treat the given I<OSSL_PARAM> array as described in
c4532834
RL
199L<OSSL_PARAM(3)>.
200
099bd339 201ossl_provider_query_operation() calls the provider's
3bbec1af
RL
202I<query_operation> function, if the provider has one.
203It should return an array of I<OSSL_ALGORITHM> for the given
204I<operation_id>.
099bd339 205
c4532834
RL
206=head1 NOTES
207
208Locating a provider module happens as follows:
209
210=over 4
211
212=item 1.
213
3bbec1af
RL
214If a path was given with ossl_provider_set_module_path(), use that as
215module path.
216Otherwise, use the provider object's name as module path, with
217platform specific standard extensions added.
c4532834
RL
218
219=item 2.
220
3bbec1af
RL
221If the environment variable B<OPENSSL_MODULES> is defined, assume its
222value is a directory specification and merge it with the module path.
223Otherwise, merge the value of the OpenSSL built in macro B<MODULESDIR>
224with the module path.
c4532834 225
3bbec1af 226=back
c4532834 227
3bbec1af
RL
228When this process is done, the result is used when trying to load the
229provider module.
c4532834 230
3bbec1af
RL
231The command C<openssl version -m> can be used to find out the value
232of the built in macro B<MODULESDIR>.
c4532834
RL
233
234=head1 RETURN VALUES
235
236ossl_provider_find() and ossl_provider_new() return a pointer to a
3bbec1af 237provider object (I<OSSL_PROVIDER>) on success, or NULL on error.
c4532834 238
7c95390e 239ossl_provider_up_ref() returns the value of the reference count after
c4532834
RL
240it has been incremented.
241
242ossl_provider_free() doesn't return any value.
243
3bbec1af 244ossl_provider_set_module_path(), ossl_provider_set_fallback() and
e55008a9 245ossl_provider_activate() return 1 on success, or 0 on error.
c4532834 246
36f5ec55
RL
247ossl_provider_available() return 1 if the provider is available,
248otherwise 0.
249
c4532834
RL
250ossl_provider_name(), ossl_provider_dso(),
251ossl_provider_module_name(), and ossl_provider_module_path() return a
3bbec1af 252pointer to their respective data if it's available, otherwise NULL
c4532834
RL
253is returned.
254
255ossl_provider_teardown() doesnt't return any value.
256
26175013
RL
257ossl_provider_get_param_types() returns a pointer to a constant
258I<OSSL_PARAM> array if this function is available in the provider,
259otherwise NULL.
c4532834
RL
260
261ossl_provider_get_params() returns 1 on success, or 0 on error.
262If this function isn't available in the provider, 0 is returned.
263
264=head1 SEE ALSO
265
3bbec1af 266L<OSSL_PROVIDER(3)>, L<provider(7)>, L<openssl(1)>
c4532834
RL
267
268=head1 HISTORY
269
270The functions described here were all added in OpenSSL 3.0.
271
272=head1 COPYRIGHT
273
274Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
275
276Licensed under the Apache License 2.0 (the "License"). You may not use
277this file except in compliance with the License. You can obtain a copy
278in the file LICENSE in the source distribution or at
279L<https://www.openssl.org/source/license.html>.
280
281=cut