]> git.ipfire.org Git - thirdparty/openssl.git/blame - doc/man7/provider.pod
Introduce the provider property
[thirdparty/openssl.git] / doc / man7 / provider.pod
CommitLineData
e4c0ec62
RL
1=pod
2
3=head1 NAME
4
5provider - OpenSSL operation implementation providers
6
7=head1 SYNOPSIS
8
bb82531f 9=for openssl generic
e4c0ec62
RL
10
11#include <openssl/provider.h>
12
13=head1 DESCRIPTION
14
15=head2 General
16
17A I<provider>, in OpenSSL terms, is a unit of code that provides one
18or more implementations for various operations for diverse algorithms
19that one might want to perform.
20
21An I<operation> is something one wants to do, such as encryption and
22decryption, key derivation, MAC calculation, signing and verification,
23etc.
24
25An I<algorithm> is a named method to perform an operation.
26Very often, the algorithms revolve around cryptographic operations,
27but may also revolve around other types of operation, such as managing
28certain types of objects.
29
30=head2 Provider
31
32I<NOTE: This section is mostly interesting for provider authors.>
33
34A I<provider> offers an initialization function, as a set of base
35functions in the form of an B<OSSL_DISPATCH> array, and by extension,
36a set of B<OSSL_ALGORITHM>s (see L<openssl-core.h(7)>).
37It may be a dynamically loadable module, or may be built-in, in
38OpenSSL libraries or in the application.
39If it's a dynamically loadable module, the initialization function
40must be named C<OSSL_provider_init> and must be exported.
41If it's built-in, the initialization function may have any name.
42
43The initialization function must have the following signature:
44
45 int NAME(const OSSL_PROVIDER *provider,
46 const OSSL_DISPATCH *in, const OSSL_DISPATCH **out,
47 void **provctx);
48
49I<provider> is the OpenSSL library object for the provider, and works
50as a handle for everything the OpenSSL libraries need to know about
51the provider.
52For the provider itself, it may hold some interesting information,
53and is also passed to some of the functions given in the dispatch
54array I<in>.
55
56I<in> is a dispatch array of base functions offered by the OpenSSL
57libraries, and the available functions are further described in
58L<provider-base(7)>.
59
60I<*out> must be assigned a dispatch array of base functions that the
61provider offers to the OpenSSL libraries.
62The functions that may be offered are further described in
63L<provider-base(7)>, and they are the central means of communication
64between the OpenSSL libraries and the provider.
65
66I<*provctx> should be assigned a provider specific context to allow
67the provider multiple simultaneous uses.
68This pointer will be passed to various operation functions offered by
69the provider.
70
71One of the functions the provider offers to the OpenSSL libraries is
72the central mechanism for the OpenSSL libraries to get access to
73operation implementations for diverse algorithms.
74Its referred to with the number B<OSSL_FUNC_PROVIDER_QUERY_OPERATION>
75and has the following signature:
76
77 const OSSL_ALGORITHM *provider_query_operation(void *provctx,
78 int operation_id,
79 const int *no_store);
80
81I<provctx> is the provider specific context that was passed back by
82the initialization function.
83
84I<operation_id> is an operation identity (see L</Operations> below).
85
86I<no_store> is a flag back to the OpenSSL libraries which, when
9c0586d5 87nonzero, signifies that the OpenSSL libraries will not store a
e4c0ec62
RL
88reference to the returned data in their internal store of
89implementations.
90
91The returned B<OSSL_ALGORITHM> is the foundation of any OpenSSL
92library API that uses providers for their implementation, most
93commonly in the I<fetching> type of functions
94(see L</Fetching algorithms> below).
95
96=head2 Operations
97
98I<NOTE: This section is mostly interesting for provider authors.>
99
100Operations are referred to with numbers, via macros with names
101starting with C<OSSL_OP_>.
102
103With each operation comes a set of defined function types that a
104provider may or may not offer, depending on its needs.
105
106Currently available operations are:
107
108=over 4
109
110=item Digests
111
112In the OpenSSL libraries, the corresponding method object is
113B<EVP_MD>.
114The number for this operation is B<OSSL_OP_DIGEST>.
115The functions the provider can offer are described in
116L<provider-digest(7)>
117
118=item Symmetric ciphers
119
120In the OpenSSL libraries, the corresponding method object is
121B<EVP_CIPHER>.
122The number for this operation is B<OSSL_OP_CIPHER>.
123The functions the provider can offer are described in
124L<provider-cipher(7)>
125
e4c0ec62
RL
126=item Message Authentication Code (MAC)
127
128In the OpenSSL libraries, the corresponding method object is
129B<EVP_MAC>.
130The number for this operation is B<OSSL_OP_MAC>.
131The functions the provider can offer are described in
132L<provider-mac(7)>
133
e4c0ec62
RL
134=item Key Derivation Function (KDF)
135
136In the OpenSSL libraries, the corresponding method object is
137B<EVP_KDF>.
138The number for this operation is B<OSSL_OP_KDF>.
139The functions the provider can offer are described in
140L<provider-kdf(7)>
141
e4c0ec62
RL
142=item Key Exchange
143
144In the OpenSSL libraries, the corresponding method object is
dfabee82 145B<EVP_KEYEXCH>.
e4c0ec62
RL
146The number for this operation is B<OSSL_OP_KEYEXCH>.
147The functions the provider can offer are described in
148L<provider-keyexch(7)>
149
0d003c52
RL
150=item Serialization
151
152In the OpenSSL libraries, the corresponding method object is
153B<OSSL_SERIALIZER>.
154The number for this operation is B<OSSL_OP_SERIALIZER>.
155The functions the provider can offer are described in
156L<provider-serializer(7)>
157
e4c0ec62
RL
158=back
159
160=head2 Fetching algorithms
161
162=head3 Explicit fetch
163
164I<NOTE: This section is mostly interesting to OpenSSL users.>
165
166Users of the OpenSSL libraries never query the provider directly for
167its diverse implementations and dispatch tables.
168Instead, the diverse OpenSSL APIs often have fetching functions that
169do the work, and they return an appropriate method object back to the
170user.
171These functions usually have the name C<APINAME_fetch>, where
172C<APINAME> is the name of the API, for example L<EVP_MD_fetch(3)>.
173
174These fetching functions follow a fairly common pattern, where three
175arguments are passed:
176
177=over 4
178
179=item The library context
180
181See L<OPENSSL_CTX(3)> for a more detailed description.
182This may be NULL to signify the default (global) library context, or a
183context created by the user.
184Only providers loaded in this library context (see
185L<OSSL_PROVIDER_load(3)>) will be considered by the fetching
186function.
187
188=item An identifier
189
190This is most commonly an algorithm name (this is the case for all EVP
191methods), but may also be called something else.
192
193=for comment For example, an OSSL_STORE implementation would use the
194URI scheme as an identifier.
195
196=item A property query string
197
198See L<property(7)> for a more detailed description.
199This is used to select more exactly which providers will get to offer
200an implementation.
201
202=back
203
204The method object that is fetched can then be used with diverse other
205functions that use them, for example L<EVP_DigestInit_ex(3)>.
206
485d3361 207=head3 Implicit fetch
e4c0ec62
RL
208
209I<NOTE: This section is mostly interesting to OpenSSL users.>
210
211OpenSSL has a number of functions that return a method object with no
212associated implementation, such as L<EVP_sha256(3)>,
213L<EVP_blake2b512(3)> or L<EVP_aes_128_cbc(3)>, which are present for
214compatibility with OpenSSL before version 3.0.
215
216When they are used with functions like L<EVP_DigestInit_ex(3)> or
217L<EVP_CipherInit_ex(3)>, the actual implementation to be used is
218fetched implicitly using default search criteria.
219
fadb57e5 220Implicit fetching can also occur when a NULL algorithm parameter is
e4c0ec62
RL
221supplied.
222In this case an algorithm implementation is implicitly fetched using
223default search criteria and an algorithm name that is consistent with
224the type of EVP_PKEY being used.
225
e44192d1 226=head3 Algorithm naming
e4c0ec62 227
e44192d1
MC
228Algorithm names are case insensitive. Any particular algorithm can have multiple
229aliases associated with it. The canonical OpenSSL naming scheme follows this
230format:
e4c0ec62 231
e44192d1 232ALGNAME[VERSION?][-SUBNAME[VERSION?]?][-SIZE?][-MODE?]
e4c0ec62 233
e44192d1
MC
234VERSION is only present if there are multiple versions of an algorithm (e.g.
235MD2, MD4, MD5). It may be omitted if there is only one version.
e4c0ec62 236
e44192d1
MC
237SUBNAME may be present where multiple algorithms are combined together,
238e.g. MD5-SHA1.
e4c0ec62 239
e44192d1
MC
240SIZE is only present if multiple versions of an algorithm exist with different
241sizes (e.g. AES-128-CBC, AES-256-CBC)
e4c0ec62 242
e44192d1 243MODE is only present where applicable.
e4c0ec62 244
e44192d1
MC
245Other aliases may exist for example where standards bodies or common practice
246use alternative names or names that OpenSSL has used historically.
e4c0ec62 247
e44192d1 248=head1 OPENSSL PROVIDERS
e4c0ec62 249
e44192d1 250OpenSSL comes with a set of providers.
e4c0ec62 251
e44192d1
MC
252The algorithms available in each of these providers may vary due to build time
253configuration options. The L<openssl-list(1)> command can be used to list the
254currently available algorithms.
e4c0ec62 255
e44192d1
MC
256The names of the algorithms shown from L<openssl-list(1)> can be used as an
257algorithm identifier to the appropriate fetching function.
e4c0ec62 258
e44192d1
MC
259=head2 Default provider
260
261The default provider is built in as part of the F<libcrypto> library.
262Should it be needed (if other providers are loaded and offer
745fc918
MC
263implementations of the same algorithms), the property "provider=default"
264can be used as a search criterion for these implementations. Some
265non-cryptographic algorithms (such as serializers for loading keys and
266parameters from files) are not FIPS algorithm implementations in themselves but
267support algorithms from the FIPS provider and are allowed for use in "FIPS
268mode". The property "fips=yes" can be used to select such algorithms.
e4c0ec62
RL
269
270=head2 FIPS provider
271
272The FIPS provider is a dynamically loadable module, and must therefore
273be loaded explicitly, either in code or through OpenSSL configuration
274(see L<config(5)>).
275Should it be needed (if other providers are loaded and offer
745fc918
MC
276implementations of the same algorithms), the property "provider=fips" can
277be used as a search criterion for these implementations. All algorithm
278implementations in the FIPS provider can also be selected with the property
279"fips=yes".
e4c0ec62 280
e4c0ec62
RL
281=head2 Legacy provider
282
283The legacy provider is a dynamically loadable module, and must therefore
284be loaded explicitly, either in code or through OpenSSL configuration
285(see L<config(5)>).
286Should it be needed (if other providers are loaded and offer
745fc918 287implementations of the same algorithms), the property "provider=legacy" can be
e4c0ec62
RL
288used as a search criterion for these implementations.
289
e4c0ec62
RL
290=head1 EXAMPLES
291
292=head2 Fetching
293
e44192d1 294Fetch any available implementation of SHA2-256 in the default context:
e4c0ec62 295
e44192d1 296 EVP_MD *md = EVP_MD_fetch(NULL, "SHA2-256", NULL);
e4c0ec62
RL
297 ...
298 EVP_MD_meth_free(md);
299
300Fetch any available implementation of AES-128-CBC in the default context:
301
302 EVP_CIPHER *cipher = EVP_CIPHER_fetch(NULL, "AES-128-CBC", NULL);
303 ...
304 EVP_CIPHER_meth_free(cipher);
305
e44192d1 306Fetch an implementation of SHA2-256 from the default provider in the default
e4c0ec62
RL
307context:
308
745fc918 309 EVP_MD *md = EVP_MD_fetch(NULL, "SHA2-256", "provider=default");
e4c0ec62
RL
310 ...
311 EVP_MD_meth_free(md);
312
e44192d1 313Fetch an implementation of SHA2-256 that is not from the default provider in the
e4c0ec62
RL
314default context:
315
745fc918 316 EVP_MD *md = EVP_MD_fetch(NULL, "SHA2-256", "provider!=default");
e4c0ec62
RL
317 ...
318 EVP_MD_meth_free(md);
319
e44192d1 320Fetch an implementation of SHA2-256 from the default provider in the specified
e4c0ec62
RL
321context:
322
745fc918 323 EVP_MD *md = EVP_MD_fetch(ctx, "SHA2-256", "provider=default");
e4c0ec62
RL
324 ...
325 EVP_MD_meth_free(md);
326
327Load the legacy provider into the default context and then fetch an
e44192d1 328implementation of WHIRLPOOL from it:
e4c0ec62
RL
329
330 /* This only needs to be done once - usually at application start up */
331 OSSL_PROVIDER *legacy = OSSL_PROVIDER_load(NULL, "legacy");
332
745fc918 333 EVP_MD *md = EVP_MD_fetch(NULL, "WHIRLPOOL", "provider=legacy");
e4c0ec62
RL
334 ...
335 EVP_MD_meth_free(md);
336
745fc918 337Note that in the above example the property string "provider=legacy" is optional
e4c0ec62
RL
338since, assuming no other providers have been loaded, the only implementation of
339the "whirlpool" algorithm is in the "legacy" provider. Also note that the
340default provider should be explicitly loaded if it is required in addition to
341other providers:
342
343 /* This only needs to be done once - usually at application start up */
344 OSSL_PROVIDER *legacy = OSSL_PROVIDER_load(NULL, "legacy");
345 OSSL_PROVIDER *default = OSSL_PROVIDER_load(NULL, "default");
346
347 EVP_MD *md_whirlpool = EVP_MD_fetch(NULL, "whirlpool", NULL);
e44192d1 348 EVP_MD *md_sha256 = EVP_MD_fetch(NULL, "SHA2-256", NULL);
e4c0ec62
RL
349 ...
350 EVP_MD_meth_free(md_whirlpool);
351 EVP_MD_meth_free(md_sha256);
352
353
354=head1 SEE ALSO
355
356L<EVP_DigestInit_ex(3)>, L<EVP_EncryptInit_ex(3)>,
e4c0ec62
RL
357L<OPENSSL_CTX(3)>,
358L<EVP_set_default_properties(3)>,
359L<EVP_MD_fetch(3)>,
360L<EVP_CIPHER_fetch(3)>,
361L<EVP_KEYMGMT_fetch(3)>,
362L<openssl-core.h(7)>,
363L<provider-base(7)>,
364L<provider-digest(7)>,
365L<provider-cipher(7)>,
366L<provider-keyexch(7)>
367
368=head1 HISTORY
369
370The concept of providers and everything surrounding them was
371introduced in OpenSSL 3.0.
372
373=head1 COPYRIGHT
374
375Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
376
377Licensed under the Apache License 2.0 (the "License"). You may not use
378this file except in compliance with the License. You can obtain a copy
379in the file LICENSE in the source distribution or at
380L<https://www.openssl.org/source/license.html>.
381
382=cut