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