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