1e1051a39Sopenharmony_ciProviders
2e1051a39Sopenharmony_ci=========
3e1051a39Sopenharmony_ci
4e1051a39Sopenharmony_ci - [Standard Providers](#standard-providers)
5e1051a39Sopenharmony_ci    - [The Default Provider](#the-default-provider)
6e1051a39Sopenharmony_ci    - [The Legacy Provider](#the-legacy-provider)
7e1051a39Sopenharmony_ci    - [The FIPS Provider](#the-fips-provider)
8e1051a39Sopenharmony_ci    - [The Base Provider](#the-base-provider)
9e1051a39Sopenharmony_ci    - [The Null Provider](#the-null-provider)
10e1051a39Sopenharmony_ci - [Loading Providers](#loading-providers)
11e1051a39Sopenharmony_ci
12e1051a39Sopenharmony_ciStandard Providers
13e1051a39Sopenharmony_ci==================
14e1051a39Sopenharmony_ci
15e1051a39Sopenharmony_ciProviders are containers for algorithm implementations. Whenever a cryptographic
16e1051a39Sopenharmony_cialgorithm is used via the high level APIs a provider is selected. It is that
17e1051a39Sopenharmony_ciprovider implementation that actually does the required work. There are five
18e1051a39Sopenharmony_ciproviders distributed with OpenSSL. In the future we expect third parties to
19e1051a39Sopenharmony_cidistribute their own providers which can be added to OpenSSL dynamically.
20e1051a39Sopenharmony_ciDocumentation about writing providers is available on the [provider(7)]
21e1051a39Sopenharmony_cimanual page.
22e1051a39Sopenharmony_ci
23e1051a39Sopenharmony_ci [provider(7)]: https://www.openssl.org/docs/man3.0/man7/provider.html
24e1051a39Sopenharmony_ci
25e1051a39Sopenharmony_ciThe Default Provider
26e1051a39Sopenharmony_ci--------------------
27e1051a39Sopenharmony_ci
28e1051a39Sopenharmony_ciThe default provider collects together all of the standard built-in OpenSSL
29e1051a39Sopenharmony_cialgorithm implementations. If an application doesn't specify anything else
30e1051a39Sopenharmony_ciexplicitly (e.g. in the application or via config), then this is the provider
31e1051a39Sopenharmony_cithat will be used. It is loaded automatically the first time that we try to
32e1051a39Sopenharmony_ciget an algorithm from a provider if no other provider has been loaded yet.
33e1051a39Sopenharmony_ciIf another provider has already been loaded then it won't be loaded
34e1051a39Sopenharmony_ciautomatically. Therefore if you want to use it in conjunction with other
35e1051a39Sopenharmony_ciproviders then you must load it explicitly.
36e1051a39Sopenharmony_ci
37e1051a39Sopenharmony_ciThis is a "built-in" provider which means that it is compiled and linked
38e1051a39Sopenharmony_ciinto the libcrypto library and does not exist as a separate standalone module.
39e1051a39Sopenharmony_ci
40e1051a39Sopenharmony_ciThe Legacy Provider
41e1051a39Sopenharmony_ci-------------------
42e1051a39Sopenharmony_ci
43e1051a39Sopenharmony_ciThe legacy provider is a collection of legacy algorithms that are either no
44e1051a39Sopenharmony_cilonger in common use or considered insecure and strongly discouraged from use.
45e1051a39Sopenharmony_ciHowever, some applications may need to use these algorithms for backwards
46e1051a39Sopenharmony_cicompatibility reasons. This provider is **not** loaded by default.
47e1051a39Sopenharmony_ciThis may mean that some applications upgrading from earlier versions of OpenSSL
48e1051a39Sopenharmony_cimay find that some algorithms are no longer available unless they load the
49e1051a39Sopenharmony_cilegacy provider explicitly.
50e1051a39Sopenharmony_ci
51e1051a39Sopenharmony_ciAlgorithms in the legacy provider include MD2, MD4, MDC2, RMD160, CAST5,
52e1051a39Sopenharmony_ciBF (Blowfish), IDEA, SEED, RC2, RC4, RC5 and DES (but not 3DES).
53e1051a39Sopenharmony_ci
54e1051a39Sopenharmony_ciThe FIPS Provider
55e1051a39Sopenharmony_ci-----------------
56e1051a39Sopenharmony_ci
57e1051a39Sopenharmony_ciThe FIPS provider contains a sub-set of the algorithm implementations available
58e1051a39Sopenharmony_cifrom the default provider, consisting of algorithms conforming to FIPS standards.
59e1051a39Sopenharmony_ciIt is intended that this provider will be FIPS140-2 validated.
60e1051a39Sopenharmony_ci
61e1051a39Sopenharmony_ciIn some cases there may be minor behavioural differences between algorithm
62e1051a39Sopenharmony_ciimplementations in this provider compared to the equivalent algorithm in the
63e1051a39Sopenharmony_cidefault provider. This is typically in order to conform to FIPS standards.
64e1051a39Sopenharmony_ci
65e1051a39Sopenharmony_ciThe Base Provider
66e1051a39Sopenharmony_ci-----------------
67e1051a39Sopenharmony_ci
68e1051a39Sopenharmony_ciThe base provider contains a small sub-set of non-cryptographic algorithms
69e1051a39Sopenharmony_ciavailable in the default provider. For example, it contains algorithms to
70e1051a39Sopenharmony_ciserialize and deserialize keys to files. If you do not load the default
71e1051a39Sopenharmony_ciprovider then you should always load this one instead (in particular, if
72e1051a39Sopenharmony_ciyou are using the FIPS provider).
73e1051a39Sopenharmony_ci
74e1051a39Sopenharmony_ciThe Null Provider
75e1051a39Sopenharmony_ci-----------------
76e1051a39Sopenharmony_ci
77e1051a39Sopenharmony_ciThe null provider is "built-in" to libcrypto and contains no algorithm
78e1051a39Sopenharmony_ciimplementations. In order to guarantee that the default provider is not
79e1051a39Sopenharmony_ciautomatically loaded, the null provider can be loaded instead.
80e1051a39Sopenharmony_ci
81e1051a39Sopenharmony_ciThis can be useful if you are using non-default library contexts and want
82e1051a39Sopenharmony_cito ensure that the default library context is never used unintentionally.
83e1051a39Sopenharmony_ci
84e1051a39Sopenharmony_ciLoading Providers
85e1051a39Sopenharmony_ci=================
86e1051a39Sopenharmony_ci
87e1051a39Sopenharmony_ciProviders to be loaded can be specified in the OpenSSL config file.
88e1051a39Sopenharmony_ciSee the [config(5)] manual page for information about how to configure
89e1051a39Sopenharmony_ciproviders via the config file, and how to automatically activate them.
90e1051a39Sopenharmony_ci
91e1051a39Sopenharmony_ci [config(5)]: https://www.openssl.org/docs/man3.0/man5/config.html
92e1051a39Sopenharmony_ci
93e1051a39Sopenharmony_ciThe following is a minimal config file example to load and activate both
94e1051a39Sopenharmony_cithe legacy and the default provider in the default library context.
95e1051a39Sopenharmony_ci
96e1051a39Sopenharmony_ci    openssl_conf = openssl_init
97e1051a39Sopenharmony_ci
98e1051a39Sopenharmony_ci    [openssl_init]
99e1051a39Sopenharmony_ci    providers = provider_sect
100e1051a39Sopenharmony_ci
101e1051a39Sopenharmony_ci    [provider_sect]
102e1051a39Sopenharmony_ci    default = default_sect
103e1051a39Sopenharmony_ci    legacy = legacy_sect
104e1051a39Sopenharmony_ci
105e1051a39Sopenharmony_ci    [default_sect]
106e1051a39Sopenharmony_ci    activate = 1
107e1051a39Sopenharmony_ci
108e1051a39Sopenharmony_ci    [legacy_sect]
109e1051a39Sopenharmony_ci    activate = 1
110e1051a39Sopenharmony_ci
111e1051a39Sopenharmony_ciIt is also possible to load providers programmatically. For example you can
112e1051a39Sopenharmony_ciload the legacy provider into the default library context as shown below.
113e1051a39Sopenharmony_ciNote that once you have explicitly loaded a provider into the library context
114e1051a39Sopenharmony_cithe default provider will no longer be automatically loaded. Therefore you will
115e1051a39Sopenharmony_cioften also want to explicitly load the default provider, as is done here:
116e1051a39Sopenharmony_ci
117e1051a39Sopenharmony_ci    #include <stdio.h>
118e1051a39Sopenharmony_ci    #include <stdlib.h>
119e1051a39Sopenharmony_ci
120e1051a39Sopenharmony_ci    #include <openssl/provider.h>
121e1051a39Sopenharmony_ci
122e1051a39Sopenharmony_ci    int main(void)
123e1051a39Sopenharmony_ci    {
124e1051a39Sopenharmony_ci        OSSL_PROVIDER *legacy;
125e1051a39Sopenharmony_ci        OSSL_PROVIDER *deflt;
126e1051a39Sopenharmony_ci
127e1051a39Sopenharmony_ci        /* Load Multiple providers into the default (NULL) library context */
128e1051a39Sopenharmony_ci        legacy = OSSL_PROVIDER_load(NULL, "legacy");
129e1051a39Sopenharmony_ci        if (legacy == NULL) {
130e1051a39Sopenharmony_ci            printf("Failed to load Legacy provider\n");
131e1051a39Sopenharmony_ci            exit(EXIT_FAILURE);
132e1051a39Sopenharmony_ci        }
133e1051a39Sopenharmony_ci        deflt = OSSL_PROVIDER_load(NULL, "default");
134e1051a39Sopenharmony_ci        if (deflt == NULL) {
135e1051a39Sopenharmony_ci            printf("Failed to load Default provider\n");
136e1051a39Sopenharmony_ci            OSSL_PROVIDER_unload(legacy);
137e1051a39Sopenharmony_ci            exit(EXIT_FAILURE);
138e1051a39Sopenharmony_ci        }
139e1051a39Sopenharmony_ci
140e1051a39Sopenharmony_ci        /* Rest of application */
141e1051a39Sopenharmony_ci
142e1051a39Sopenharmony_ci        OSSL_PROVIDER_unload(legacy);
143e1051a39Sopenharmony_ci        OSSL_PROVIDER_unload(deflt);
144e1051a39Sopenharmony_ci        exit(EXIT_SUCCESS);
145e1051a39Sopenharmony_ci    }
146