xref: /freebsd/crypto/openssl/doc/man3/OSSL_PROVIDER.pod (revision aa7957345732816fb0ba8308798d2f79f45597f9)
1b077aed3SPierre Pronchery=pod
2b077aed3SPierre Pronchery
3b077aed3SPierre Pronchery=head1 NAME
4b077aed3SPierre Pronchery
5b077aed3SPierre ProncheryOSSL_PROVIDER_set_default_search_path,
6b077aed3SPierre ProncheryOSSL_PROVIDER, OSSL_PROVIDER_load, OSSL_PROVIDER_try_load, OSSL_PROVIDER_unload,
7b077aed3SPierre ProncheryOSSL_PROVIDER_available, OSSL_PROVIDER_do_all,
8b077aed3SPierre ProncheryOSSL_PROVIDER_gettable_params, OSSL_PROVIDER_get_params,
9b077aed3SPierre ProncheryOSSL_PROVIDER_query_operation, OSSL_PROVIDER_unquery_operation,
10b077aed3SPierre ProncheryOSSL_PROVIDER_get0_provider_ctx, OSSL_PROVIDER_get0_dispatch,
11b077aed3SPierre ProncheryOSSL_PROVIDER_add_builtin, OSSL_PROVIDER_get0_name, OSSL_PROVIDER_get_capabilities,
12b077aed3SPierre ProncheryOSSL_PROVIDER_self_test
13b077aed3SPierre Pronchery- provider routines
14b077aed3SPierre Pronchery
15b077aed3SPierre Pronchery=head1 SYNOPSIS
16b077aed3SPierre Pronchery
17b077aed3SPierre Pronchery #include <openssl/provider.h>
18b077aed3SPierre Pronchery
19b077aed3SPierre Pronchery typedef struct ossl_provider_st OSSL_PROVIDER;
20b077aed3SPierre Pronchery
21b077aed3SPierre Pronchery int OSSL_PROVIDER_set_default_search_path(OSSL_LIB_CTX *libctx,
22b077aed3SPierre Pronchery                                           const char *path);
23b077aed3SPierre Pronchery
24b077aed3SPierre Pronchery OSSL_PROVIDER *OSSL_PROVIDER_load(OSSL_LIB_CTX *libctx, const char *name);
25b077aed3SPierre Pronchery OSSL_PROVIDER *OSSL_PROVIDER_try_load(OSSL_LIB_CTX *libctx, const char *name,
26b077aed3SPierre Pronchery                                       int retain_fallbacks);
27b077aed3SPierre Pronchery int OSSL_PROVIDER_unload(OSSL_PROVIDER *prov);
28b077aed3SPierre Pronchery int OSSL_PROVIDER_available(OSSL_LIB_CTX *libctx, const char *name);
29b077aed3SPierre Pronchery int OSSL_PROVIDER_do_all(OSSL_LIB_CTX *ctx,
30b077aed3SPierre Pronchery                          int (*cb)(OSSL_PROVIDER *provider, void *cbdata),
31b077aed3SPierre Pronchery                          void *cbdata);
32b077aed3SPierre Pronchery
33b077aed3SPierre Pronchery const OSSL_PARAM *OSSL_PROVIDER_gettable_params(OSSL_PROVIDER *prov);
34b077aed3SPierre Pronchery int OSSL_PROVIDER_get_params(OSSL_PROVIDER *prov, OSSL_PARAM params[]);
35b077aed3SPierre Pronchery
36b077aed3SPierre Pronchery const OSSL_ALGORITHM *OSSL_PROVIDER_query_operation(const OSSL_PROVIDER *prov,
37b077aed3SPierre Pronchery                                                     int operation_id,
38b077aed3SPierre Pronchery                                                     int *no_cache);
39b077aed3SPierre Pronchery void OSSL_PROVIDER_unquery_operation(const OSSL_PROVIDER *prov,
40b077aed3SPierre Pronchery                                      int operation_id,
41b077aed3SPierre Pronchery                                      const OSSL_ALGORITHM *algs);
42b077aed3SPierre Pronchery void *OSSL_PROVIDER_get0_provider_ctx(const OSSL_PROVIDER *prov);
43b077aed3SPierre Pronchery const OSSL_DISPATCH *OSSL_PROVIDER_get0_dispatch(const OSSL_PROVIDER *prov);
44b077aed3SPierre Pronchery
45b077aed3SPierre Pronchery int OSSL_PROVIDER_add_builtin(OSSL_LIB_CTX *libctx, const char *name,
46b077aed3SPierre Pronchery                               ossl_provider_init_fn *init_fn);
47b077aed3SPierre Pronchery
48b077aed3SPierre Pronchery const char *OSSL_PROVIDER_get0_name(const OSSL_PROVIDER *prov);
49b077aed3SPierre Pronchery
50b077aed3SPierre Pronchery int OSSL_PROVIDER_get_capabilities(const OSSL_PROVIDER *prov,
51b077aed3SPierre Pronchery                                    const char *capability,
52b077aed3SPierre Pronchery                                    OSSL_CALLBACK *cb,
53b077aed3SPierre Pronchery                                    void *arg);
54b077aed3SPierre Pronchery int OSSL_PROVIDER_self_test(const OSSL_PROVIDER *prov);
55b077aed3SPierre Pronchery
56b077aed3SPierre Pronchery=head1 DESCRIPTION
57b077aed3SPierre Pronchery
58b077aed3SPierre ProncheryB<OSSL_PROVIDER> is a type that holds internal information about
59b077aed3SPierre Proncheryimplementation providers (see L<provider(7)> for information on what a
60b077aed3SPierre Proncheryprovider is).
61b077aed3SPierre ProncheryA provider can be built in to the application or the OpenSSL
62b077aed3SPierre Proncherylibraries, or can be a loadable module.
63b077aed3SPierre ProncheryThe functions described here handle both forms.
64b077aed3SPierre Pronchery
65b077aed3SPierre ProncherySome of these functions operate within a library context, please see
66b077aed3SPierre ProncheryL<OSSL_LIB_CTX(3)> for further details.
67b077aed3SPierre Pronchery
68b077aed3SPierre Pronchery=head2 Functions
69b077aed3SPierre Pronchery
70b077aed3SPierre ProncheryOSSL_PROVIDER_set_default_search_path() specifies the default search I<path>
71b077aed3SPierre Proncherythat is to be used for looking for providers in the specified I<libctx>.
72b077aed3SPierre ProncheryIf left unspecified, an environment variable and a fall back default value will
73b077aed3SPierre Proncherybe used instead.
74b077aed3SPierre Pronchery
75b077aed3SPierre ProncheryOSSL_PROVIDER_add_builtin() is used to add a built in provider to
76b077aed3SPierre ProncheryB<OSSL_PROVIDER> store in the given library context, by associating a
77b077aed3SPierre Proncheryprovider name with a provider initialization function.
78b077aed3SPierre ProncheryThis name can then be used with OSSL_PROVIDER_load().
79b077aed3SPierre Pronchery
80b077aed3SPierre ProncheryOSSL_PROVIDER_load() loads and initializes a provider.
81b077aed3SPierre ProncheryThis may simply initialize a provider that was previously added with
82b077aed3SPierre ProncheryOSSL_PROVIDER_add_builtin() and run its given initialization function,
83b077aed3SPierre Proncheryor load a provider module with the given name and run its provider
84b077aed3SPierre Proncheryentry point, C<OSSL_provider_init>. The I<name> can be a path
85b077aed3SPierre Proncheryto a provider module, in that case the provider name as returned
86b077aed3SPierre Proncheryby OSSL_PROVIDER_get0_name() will be the path. Interpretation
87b077aed3SPierre Proncheryof relative paths is platform dependent and they are relative
88b077aed3SPierre Proncheryto the configured "MODULESDIR" directory or the path set in
89b077aed3SPierre Proncherythe environment variable OPENSSL_MODULES if set.
90b077aed3SPierre Pronchery
91b077aed3SPierre ProncheryOSSL_PROVIDER_try_load() functions like OSSL_PROVIDER_load(), except that
92b077aed3SPierre Proncheryit does not disable the fallback providers if the provider cannot be
93*aa795734SPierre Proncheryloaded and initialized or if I<retain_fallbacks> is nonzero.
94*aa795734SPierre ProncheryIf the provider loads successfully and I<retain_fallbacks> is zero, the
95b077aed3SPierre Proncheryfallback providers are disabled.
96b077aed3SPierre Pronchery
97b077aed3SPierre ProncheryOSSL_PROVIDER_unload() unloads the given provider.
98b077aed3SPierre ProncheryFor a provider added with OSSL_PROVIDER_add_builtin(), this simply
99b077aed3SPierre Proncheryruns its teardown function.
100b077aed3SPierre Pronchery
101b077aed3SPierre ProncheryOSSL_PROVIDER_available() checks if a named provider is available
102b077aed3SPierre Proncheryfor use.
103b077aed3SPierre Pronchery
104b077aed3SPierre ProncheryOSSL_PROVIDER_do_all() iterates over all loaded providers, calling
105b077aed3SPierre ProncheryI<cb> for each one, with the current provider in I<provider> and the
106b077aed3SPierre ProncheryI<cbdata> that comes from the caller. If no other provider has been loaded
107b077aed3SPierre Proncherybefore calling this function, the default provider is still available as
108b077aed3SPierre Proncheryfallback.
109b077aed3SPierre ProncherySee L<OSSL_PROVIDER-default(7)> for more information on this fallback
110b077aed3SPierre Proncherybehaviour.
111b077aed3SPierre Pronchery
112b077aed3SPierre ProncheryOSSL_PROVIDER_gettable_params() is used to get a provider parameter
113b077aed3SPierre Proncherydescriptor set as a constant L<OSSL_PARAM(3)> array.
114b077aed3SPierre Pronchery
115b077aed3SPierre ProncheryOSSL_PROVIDER_get_params() is used to get provider parameter values.
116b077aed3SPierre ProncheryThe caller must prepare the L<OSSL_PARAM(3)> array before calling this
117b077aed3SPierre Proncheryfunction, and the variables acting as buffers for this parameter array
118b077aed3SPierre Proncheryshould be filled with data when it returns successfully.
119b077aed3SPierre Pronchery
120b077aed3SPierre ProncheryOSSL_PROVIDER_self_test() is used to run a provider's self tests on demand.
121b077aed3SPierre ProncheryIf the self tests fail then the provider will fail to provide any further
122b077aed3SPierre Proncheryservices and algorithms. L<OSSL_SELF_TEST_set_callback(3)> may be called
123b077aed3SPierre Proncherybeforehand in order to display diagnostics for the running self tests.
124b077aed3SPierre Pronchery
125b077aed3SPierre ProncheryOSSL_PROVIDER_query_operation() calls the provider's I<query_operation>
126b077aed3SPierre Proncheryfunction (see L<provider(7)>), if the provider has one. It returns an
127b077aed3SPierre Proncheryarray of I<OSSL_ALGORITHM> for the given I<operation_id> terminated by an all
128b077aed3SPierre ProncheryNULL OSSL_ALGORITHM entry. This is considered a low-level function that most
129b077aed3SPierre Proncheryapplications should not need to call.
130b077aed3SPierre Pronchery
131b077aed3SPierre ProncheryOSSL_PROVIDER_unquery_operation() calls the provider's I<unquery_operation>
132b077aed3SPierre Proncheryfunction (see L<provider(7)>), if the provider has one.  This is considered a
133b077aed3SPierre Proncherylow-level function that most applications should not need to call.
134b077aed3SPierre Pronchery
135b077aed3SPierre ProncheryOSSL_PROVIDER_get0_provider_ctx() returns the provider context for the given
136b077aed3SPierre Proncheryprovider. The provider context is an opaque handle set by the provider itself
137b077aed3SPierre Proncheryand is passed back to the provider by libcrypto in various function calls.
138b077aed3SPierre Pronchery
139b077aed3SPierre ProncheryOSSL_PROVIDER_get0_dispatch() returns the provider's dispatch table as it was
140b077aed3SPierre Proncheryreturned in the I<out> parameter from the provider's init function. See
141b077aed3SPierre ProncheryL<provider-base(7)>.
142b077aed3SPierre Pronchery
143b077aed3SPierre ProncheryIf it is permissible to cache references to this array then I<*no_store> is set
144b077aed3SPierre Proncheryto 0 or 1 otherwise. If the array is not cacheable then it is assumed to
145b077aed3SPierre Proncheryhave a short lifetime.
146b077aed3SPierre Pronchery
147b077aed3SPierre ProncheryOSSL_PROVIDER_get0_name() returns the name of the given provider.
148b077aed3SPierre Pronchery
149b077aed3SPierre ProncheryOSSL_PROVIDER_get_capabilities() provides information about the capabilities
150b077aed3SPierre Proncherysupported by the provider specified in I<prov> with the capability name
151b077aed3SPierre ProncheryI<capability>. For each capability of that name supported by the provider it
152b077aed3SPierre Proncherywill call the callback I<cb> and supply a set of L<OSSL_PARAM(3)>s describing the
153b077aed3SPierre Proncherycapability. It will also pass back the argument I<arg>. For more details about
154b077aed3SPierre Proncherycapabilities and what they can be used for please see
155b077aed3SPierre ProncheryL<provider-base(7)/CAPABILTIIES>.
156b077aed3SPierre Pronchery
157b077aed3SPierre Pronchery=head1 RETURN VALUES
158b077aed3SPierre Pronchery
159b077aed3SPierre ProncheryOSSL_PROVIDER_set_default_search_path(), OSSL_PROVIDER_add(),
160b077aed3SPierre ProncheryOSSL_PROVIDER_unload(), OSSL_PROVIDER_get_params() and
161b077aed3SPierre ProncheryOSSL_PROVIDER_get_capabilities() return 1 on success, or 0 on error.
162b077aed3SPierre Pronchery
163b077aed3SPierre ProncheryOSSL_PROVIDER_load() and OSSL_PROVIDER_try_load() return a pointer to a
164b077aed3SPierre Proncheryprovider object on success, or NULL on error.
165b077aed3SPierre Pronchery
166b077aed3SPierre ProncheryOSSL_PROVIDER_do_all() returns 1 if the callback I<cb> returns 1 for every
167b077aed3SPierre Proncheryprovider it is called with, or 0 if any provider callback invocation returns 0;
168b077aed3SPierre Proncherycallback processing stops at the first callback invocation on a provider
169b077aed3SPierre Proncherythat returns 0.
170b077aed3SPierre Pronchery
171b077aed3SPierre ProncheryOSSL_PROVIDER_available() returns 1 if the named provider is available,
172b077aed3SPierre Proncheryotherwise 0.
173b077aed3SPierre Pronchery
174b077aed3SPierre ProncheryOSSL_PROVIDER_gettable_params() returns a pointer to an array
175b077aed3SPierre Proncheryof constant L<OSSL_PARAM(3)>, or NULL if none is provided.
176b077aed3SPierre Pronchery
177b077aed3SPierre ProncheryOSSL_PROVIDER_get_params() and returns 1 on success, or 0 on error.
178b077aed3SPierre Pronchery
179b077aed3SPierre ProncheryOSSL_PROVIDER_query_operation() returns an array of OSSL_ALGORITHM or NULL on
180b077aed3SPierre Proncheryerror.
181b077aed3SPierre Pronchery
182b077aed3SPierre ProncheryOSSL_PROVIDER_self_test() returns 1 if the self tests pass, or 0 on error.
183b077aed3SPierre Pronchery
184b077aed3SPierre Pronchery=head1 EXAMPLES
185b077aed3SPierre Pronchery
186b077aed3SPierre ProncheryThis demonstrates how to load the provider module "foo" and ask for
187b077aed3SPierre Proncheryits build information.
188b077aed3SPierre Pronchery
189b077aed3SPierre Pronchery #include <openssl/params.h>
190b077aed3SPierre Pronchery #include <openssl/provider.h>
191b077aed3SPierre Pronchery #include <openssl/err.h>
192b077aed3SPierre Pronchery
193b077aed3SPierre Pronchery OSSL_PROVIDER *prov = NULL;
194b077aed3SPierre Pronchery const char *build = NULL;
195b077aed3SPierre Pronchery OSSL_PARAM request[] = {
196b077aed3SPierre Pronchery     { "buildinfo", OSSL_PARAM_UTF8_PTR, &build, 0, 0 },
197b077aed3SPierre Pronchery     { NULL, 0, NULL, 0, 0 }
198b077aed3SPierre Pronchery };
199b077aed3SPierre Pronchery
200b077aed3SPierre Pronchery if ((prov = OSSL_PROVIDER_load(NULL, "foo")) != NULL
201b077aed3SPierre Pronchery     && OSSL_PROVIDER_get_params(prov, request))
202b077aed3SPierre Pronchery     printf("Provider 'foo' buildinfo: %s\n", build);
203b077aed3SPierre Pronchery else
204b077aed3SPierre Pronchery     ERR_print_errors_fp(stderr);
205b077aed3SPierre Pronchery
206b077aed3SPierre Pronchery=head1 SEE ALSO
207b077aed3SPierre Pronchery
208b077aed3SPierre ProncheryL<openssl-core.h(7)>, L<OSSL_LIB_CTX(3)>, L<provider(7)>
209b077aed3SPierre Pronchery
210b077aed3SPierre Pronchery=head1 HISTORY
211b077aed3SPierre Pronchery
212b077aed3SPierre ProncheryThe type and functions described here were added in OpenSSL 3.0.
213b077aed3SPierre Pronchery
214b077aed3SPierre Pronchery=head1 COPYRIGHT
215b077aed3SPierre Pronchery
216*aa795734SPierre ProncheryCopyright 2019-2023 The OpenSSL Project Authors. All Rights Reserved.
217b077aed3SPierre Pronchery
218b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License").  You may not use
219b077aed3SPierre Proncherythis file except in compliance with the License.  You can obtain a copy
220b077aed3SPierre Proncheryin the file LICENSE in the source distribution or at
221b077aed3SPierre ProncheryL<https://www.openssl.org/source/license.html>.
222b077aed3SPierre Pronchery
223b077aed3SPierre Pronchery=cut
224