5 provider - OpenSSL operation implementation providers
11 #include <openssl/provider.h>
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.
21 An I<operation> is something one wants to do, such as encryption and
22 decryption, key derivation, MAC calculation, signing and verification,
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.
32 I<NOTE: This section is mostly interesting for provider authors.>
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.
43 The initialization function must have the following signature:
45 int NAME(const OSSL_CORE_HANDLE *handle,
46 const OSSL_DISPATCH *in, const OSSL_DISPATCH **out,
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
52 For the provider itself, it is passed to some of the functions given in the
55 I<in> is a dispatch array of base functions offered by the OpenSSL
56 libraries, and the available functions are further described in
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.
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
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:
76 const OSSL_ALGORITHM *provider_query_operation(void *provctx,
80 I<provctx> is the provider specific context that was passed back by
81 the initialization function.
83 I<operation_id> is an operation identity (see L</Operations> below).
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
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).
97 I<NOTE: This section is mostly interesting for provider authors.>
99 Operations are referred to with numbers, via macros with names
100 starting with C<OSSL_OP_>.
102 With each operation comes a set of defined function types that a
103 provider may or may not offer, depending on its needs.
105 Currently available operations are:
111 In the OpenSSL libraries, the corresponding method object is
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)>
117 =item Symmetric ciphers
119 In the OpenSSL libraries, the corresponding method object is
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)>
125 =item Message Authentication Code (MAC)
127 In the OpenSSL libraries, the corresponding method object is
129 The number for this operation is B<OSSL_OP_MAC>.
130 The functions the provider can offer are described in
133 =item Key Derivation Function (KDF)
135 In the OpenSSL libraries, the corresponding method object is
137 The number for this operation is B<OSSL_OP_KDF>.
138 The functions the provider can offer are described in
143 In the OpenSSL libraries, the corresponding method object is
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)>
149 =item Asymmetric Ciphers
151 In the OpenSSL libraries, the corresponding method object is
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)>
159 In the OpenSSL libraries, the corresponding method object is
161 The number for this operation is B<OSSL_OP_SERIALIZER>.
162 The functions the provider can offer are described in
163 L<provider-serializer(7)>
167 =head2 Fetching algorithms
169 =head3 Explicit fetch
171 I<NOTE: This section is mostly interesting to OpenSSL users.>
173 Users of the OpenSSL libraries never query the provider directly for
174 its diverse implementations and dispatch tables.
175 Instead, the diverse OpenSSL APIs often have fetching functions that
176 do the work, and they return an appropriate method object back to the
178 These functions usually have the name C<APINAME_fetch>, where
179 C<APINAME> is the name of the API, for example L<EVP_MD_fetch(3)>.
181 These fetching functions follow a fairly common pattern, where three
182 arguments are passed:
186 =item The library context
188 See L<OPENSSL_CTX(3)> for a more detailed description.
189 This may be NULL to signify the default (global) library context, or a
190 context created by the user.
191 Only providers loaded in this library context (see
192 L<OSSL_PROVIDER_load(3)>) will be considered by the fetching
197 This is most commonly an algorithm name (this is the case for all EVP
198 methods), but may also be called something else.
200 =for comment For example, an OSSL_STORE implementation would use the
201 URI scheme as an identifier.
203 =item A property query string
205 See L<property(7)> for a more detailed description.
206 This is used to select more exactly which providers will get to offer
211 The method object that is fetched can then be used with diverse other
212 functions that use them, for example L<EVP_DigestInit_ex(3)>.
214 =head3 Implicit fetch
216 I<NOTE: This section is mostly interesting to OpenSSL users.>
218 OpenSSL has a number of functions that return a method object with no
219 associated implementation, such as L<EVP_sha256(3)>,
220 L<EVP_blake2b512(3)> or L<EVP_aes_128_cbc(3)>, which are present for
221 compatibility with OpenSSL before version 3.0.
223 When they are used with functions like L<EVP_DigestInit_ex(3)> or
224 L<EVP_CipherInit_ex(3)>, the actual implementation to be used is
225 fetched implicitly using default search criteria.
227 Implicit fetching can also occur when a NULL algorithm parameter is
229 In this case an algorithm implementation is implicitly fetched using
230 default search criteria and an algorithm name that is consistent with
231 the type of EVP_PKEY being used.
233 =head3 Algorithm naming
235 Algorithm names are case insensitive. Any particular algorithm can have multiple
236 aliases associated with it. The canonical OpenSSL naming scheme follows this
239 ALGNAME[VERSION?][-SUBNAME[VERSION?]?][-SIZE?][-MODE?]
241 VERSION is only present if there are multiple versions of an algorithm (e.g.
242 MD2, MD4, MD5). It may be omitted if there is only one version.
244 SUBNAME may be present where multiple algorithms are combined together,
247 SIZE is only present if multiple versions of an algorithm exist with different
248 sizes (e.g. AES-128-CBC, AES-256-CBC)
250 MODE is only present where applicable.
252 Other aliases may exist for example where standards bodies or common practice
253 use alternative names or names that OpenSSL has used historically.
255 =head1 OPENSSL PROVIDERS
257 OpenSSL comes with a set of providers.
259 The algorithms available in each of these providers may vary due to build time
260 configuration options. The L<openssl-list(1)> command can be used to list the
261 currently available algorithms.
263 The names of the algorithms shown from L<openssl-list(1)> can be used as an
264 algorithm identifier to the appropriate fetching function.
266 =head2 Default provider
268 The default provider is built in as part of the F<libcrypto> library.
269 Should it be needed (if other providers are loaded and offer
270 implementations of the same algorithms), the property "provider=default"
271 can be used as a search criterion for these implementations. Some
272 non-cryptographic algorithms (such as serializers for loading keys and
273 parameters from files) are not FIPS algorithm implementations in themselves but
274 support algorithms from the FIPS provider and are allowed for use in "FIPS
275 mode". The property "fips=yes" can be used to select such algorithms.
279 The FIPS provider is a dynamically loadable module, and must therefore
280 be loaded explicitly, either in code or through OpenSSL configuration
282 Should it be needed (if other providers are loaded and offer
283 implementations of the same algorithms), the property "provider=fips" can
284 be used as a search criterion for these implementations. All approved algorithm
285 implementations in the FIPS provider can also be selected with the property
286 "fips=yes". The FIPS provider also contains a number of non-approved algorithm
287 implementations and these can be selected with the property "fips=no".
289 =head2 Legacy provider
291 The legacy provider is a dynamically loadable module, and must therefore
292 be loaded explicitly, either in code or through OpenSSL configuration
294 Should it be needed (if other providers are loaded and offer
295 implementations of the same algorithms), the property "provider=legacy" can be
296 used as a search criterion for these implementations.
300 The null provider is built in as part of the F<libcrypto> library. It contains
301 no algorithms in it at all. When fetching algorithms the default provider will
302 be automatically loaded if no other provider has been explicitly loaded. To
303 prevent that from happening you can explicitly load the null provider.
309 Fetch any available implementation of SHA2-256 in the default context:
311 EVP_MD *md = EVP_MD_fetch(NULL, "SHA2-256", NULL);
313 EVP_MD_meth_free(md);
315 Fetch any available implementation of AES-128-CBC in the default context:
317 EVP_CIPHER *cipher = EVP_CIPHER_fetch(NULL, "AES-128-CBC", NULL);
319 EVP_CIPHER_meth_free(cipher);
321 Fetch an implementation of SHA2-256 from the default provider in the default
324 EVP_MD *md = EVP_MD_fetch(NULL, "SHA2-256", "provider=default");
326 EVP_MD_meth_free(md);
328 Fetch an implementation of SHA2-256 that is not from the default provider in the
331 EVP_MD *md = EVP_MD_fetch(NULL, "SHA2-256", "provider!=default");
333 EVP_MD_meth_free(md);
335 Fetch an implementation of SHA2-256 from the default provider in the specified
338 EVP_MD *md = EVP_MD_fetch(ctx, "SHA2-256", "provider=default");
340 EVP_MD_meth_free(md);
342 Load the legacy provider into the default context and then fetch an
343 implementation of WHIRLPOOL from it:
345 /* This only needs to be done once - usually at application start up */
346 OSSL_PROVIDER *legacy = OSSL_PROVIDER_load(NULL, "legacy");
348 EVP_MD *md = EVP_MD_fetch(NULL, "WHIRLPOOL", "provider=legacy");
350 EVP_MD_meth_free(md);
352 Note that in the above example the property string "provider=legacy" is optional
353 since, assuming no other providers have been loaded, the only implementation of
354 the "whirlpool" algorithm is in the "legacy" provider. Also note that the
355 default provider should be explicitly loaded if it is required in addition to
358 /* This only needs to be done once - usually at application start up */
359 OSSL_PROVIDER *legacy = OSSL_PROVIDER_load(NULL, "legacy");
360 OSSL_PROVIDER *default = OSSL_PROVIDER_load(NULL, "default");
362 EVP_MD *md_whirlpool = EVP_MD_fetch(NULL, "whirlpool", NULL);
363 EVP_MD *md_sha256 = EVP_MD_fetch(NULL, "SHA2-256", NULL);
365 EVP_MD_meth_free(md_whirlpool);
366 EVP_MD_meth_free(md_sha256);
371 L<EVP_DigestInit_ex(3)>, L<EVP_EncryptInit_ex(3)>,
373 L<EVP_set_default_properties(3)>,
375 L<EVP_CIPHER_fetch(3)>,
376 L<EVP_KEYMGMT_fetch(3)>,
377 L<openssl-core.h(7)>,
379 L<provider-digest(7)>,
380 L<provider-cipher(7)>,
381 L<provider-keyexch(7)>
385 The concept of providers and everything surrounding them was
386 introduced in OpenSSL 3.0.
390 Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
392 Licensed under the Apache License 2.0 (the "License"). You may not use
393 this file except in compliance with the License. You can obtain a copy
394 in the file LICENSE in the source distribution or at
395 L<https://www.openssl.org/source/license.html>.