]> git.ipfire.org Git - thirdparty/openssl.git/blame - doc/man3/EVP_MD_fetch.pod
Fix Typos
[thirdparty/openssl.git] / doc / man3 / EVP_MD_fetch.pod
CommitLineData
fdf6c0b6
MC
1=pod
2
3=head1 NAME
4
42738cde 5EVP_MD_fetch, EVP_CIPHER_fetch
fdf6c0b6
MC
6- Functions to explicitly fetch algorithm implementations
7
8=head1 SYNOPSIS
9
10 #include <openssl/evp.h>
11
12 EVP_MD *EVP_MD_fetch(OPENSSL_CTX *ctx, const char *algorithm,
13 const char *properties);
42738cde
MC
14 EVP_CIPHER *EVP_CIPHER_fetch(OPENSSL_CTX *ctx, const char *algorithm,
15 const char *properties);
fdf6c0b6
MC
16
17=head1 DESCRIPTION
18
42738cde
MC
19Cryptographic algorithms are represented by different OpenSSL objects depending
20on what type of algorithm it is. The following cryptographic algorithm types are
21supported.
fdf6c0b6 22
42738cde
MC
23=over 4
24
25=item B<EVP_MD>
26
27Represents a digest algorithm.
28
29=item B<EVP_CIPHER>
30
31Represents a symmetric cipher algorithm.
32
33=item B<EVP_MAC>
34
35Represents a Message Authentication Code algorithm.
36
37=item B<EVP_KDF>
38
39Represents a Key Derivation Function algorithm.
40
41=back
fdf6c0b6 42
42738cde
MC
43The algorithm objects may or may not have an associated algorithm
44implementation.
45Cryptographic algorithms are implemented by providers.
46Any algorithm may be supported by zero or more providers.
47In order to use an algorithm an implementation must first be obtained.
48This can happen in one of three ways, i.e. implicit fetch, explicit fetch or
49user defined.
fdf6c0b6
MC
50
51=over 4
52
b7c913c8 53=item Implicit Fetch
fdf6c0b6 54
b7c913c8 55With implicit fetch an application can use functions such as L<EVP_sha256(3)>,
42738cde
MC
56L<EVP_blake2b512(3)> or L<EVP_aes_128_cbc(3)> to obtain an algorithm object with
57no associated implementation.
58When used in a function like L<EVP_DigestInit_ex(3)> or L<EVP_CipherInit_ex(3)>
59the actual implementation to be used will be fetched implicitly using default
60search criteria.
61Typically, this will return an implementation of the appropriate algorithm from
62the default provider unless the default search criteria have been changed and/or
63different providers have been loaded.
fdf6c0b6 64
b7c913c8 65=item Explicit Fetch
fdf6c0b6 66
42738cde
MC
67With explicit fetch an application uses one of the "fetch" functions to obtain
68an algorithm object with an associated implementation.
69An implementation with the given name that satisfies the search criteria
70specified in the B<properties> parameter combined with the default search
71criteria will be looked for within the available providers and returned.
cb929645
RL
72See L<EVP_set_default_properties(3)> for information on default search criteria
73and L<OSSL_PROVIDER(3)> for information about providers.
fdf6c0b6
MC
74
75=item User defined
76
42738cde
MC
77Using the user defined approach an application constructs its own algorithm
78object.
79See L<EVP_MD_meth_new(3)> and L<EVP_CIPHER_meth_new(3)> for details.
fdf6c0b6
MC
80
81=back
82
42738cde
MC
83Having obtained an algorithm implementation as an algorithm object it can then
84be used to perform cryptographic operations.
85For example to calculate the digest of input data with an B<EVP_MD> algorithm
86object you can use functions such as L<EVP_DigestInit_ex(3)>,
87L<EVP_DigestUpdate(3)> and L<EVP_DigestFinal_ex(3)>.
88
89The fetch functions will look for an algorithm within the providers that
90have been loaded into the B<OPENSSL_CTX> given in the B<ctx> parameter.
91This parameter may be NULL in which case the default B<OPENSSL_CTX> will be
92used.
93See L<OPENSSL_CTX_new(3)> and L<OSSL_PROVIDER_load(3)> for further details.
fdf6c0b6
MC
94
95The B<algorithm> parameter gives the name of the algorithm to be looked up.
42738cde
MC
96Different algorithms can be made available by loading different providers.
97
98The built-in default provider digest algorithm implementation names are: SHA1,
99SHA224, SHA256, SHA384, SHA512, SHA512-224, SHA512-256, SHA3-224, SHA3-256,
100SHA3-384, SHA3-512, SHAKE128, SHAKE256, SM3, BLAKE2b512, BLAKE2s256 and
101MD5-SHA1.
102
103The built-in default provider cipher algorithm implementation names are:
104AES-256-ECB, AES-192-ECB, AES-128-ECB, AES-256-CBC, AES-192-CBC, AES-128-CBC,
105AES-256-OFB, AES-192-OFB, AES-128-OFB, AES-256-CFB, AES-192-CFB, AES-128-CFB,
106AES-256-CFB1, AES-192-CFB1, AES-128-CFB1, AES-256-CFB8, AES-192-CFB8,
107AES-128-CFB8, AES-256-CTR, AES-192-CTR, AES-128-CTR, id-aes256-GCM,
108id-aes192-GCM and id-aes128-GCM.
fdf6c0b6
MC
109
110Additional algorithm implementations may be obtained by loading the "legacy"
42738cde
MC
111provider.
112
113The legacy provider digest algorithms are: RIPEMD160, MD2, MD4, MD5, MDC2 and
fdf6c0b6
MC
114whirlpool.
115
116The B<properties> parameter specifies the search criteria that will be used to
117look for an algorithm implementation. Properties are given as a comma delimited
118string of name value pairs. In order for an implementation to match, all the
119properties in the query string must match those defined for that implementation.
120Any properties defined by an implementation but not given in the query string
121are ignored. All algorithm implementations in the default provider have the
122property "default=yes". All algorithm implementations in the legacy provider have
123the property "legacy=yes". All algorithm implementations in the FIPS provider
124have the property "fips=yes". In the event that more than one implementation
125of the given algorithm name matches the specified properties then an unspecified
126one of those implementations may be returned. The B<properties> parameter may be
127NULL in which case any implementation from the available providers with the
128given algorithm name will be returned.
129
130The return value from a call to EVP_MD_fetch() must be freed by the caller using
42738cde
MC
131L<EVP_MD_meth_free(3)>.
132Note that EVP_MD objects are reference counted. See L<EVP_MD_up_ref(3)>.
133
134The return value from a call to EVP_CIPHER_fetch() must be freed by the caller
135using L<EVP_CIPHER_meth_free(3)>.
136Note that EVP_CIPHER objects are reference counted.
137See L<EVP_CIPHER_up_ref(3)>.
fdf6c0b6 138
b7c913c8
MC
139=head1 NOTES
140
141Where an application that previously used implicit fetch is converted to use
142explicit fetch care should be taken with the L<EVP_MD_CTX_md(3)> function.
c2969ff6 143Specifically, this function returns the EVP_MD object originally passed to
b7c913c8
MC
144EVP_DigestInit_ex() (or other similar function). With implicit fetch the
145returned EVP_MD object is guaranteed to be available throughout the application
146lifetime. However, with explicit fetch EVP_MD objects are reference counted.
147EVP_MD_CTX_md does not increment the reference count and so the returned EVP_MD
148object may not be accessible beyond the lifetime of the EVP_MD_CTX it is
149associated with.
150
fdf6c0b6
MC
151=head1 RETURN VALUES
152
153EVP_MD_fetch() returns a pointer to the algorithm implementation represented by
154an EVP_MD object, or NULL on error.
155
156=head1 EXAMPLES
157
158Fetch any available implementation of SHA256 in the default context:
159
160 EVP_MD *md = EVP_MD_fetch(NULL, "SHA256", NULL);
42738cde
MC
161 ...
162 EVP_MD_meth_free(md);
163
164Fetch any available implementation of AES-128-CBC in the default context:
165
166 EVP_CIPHER *cipher = EVP_CIPHER_fetch(NULL, "AES-128-CBC", NULL);
167 ...
168 EVP_CIPHER_meth_free(cipher);
fdf6c0b6
MC
169
170Fetch an implementation of SHA256 from the default provider in the default
171context:
172
173 EVP_MD *md = EVP_MD_fetch(NULL, "SHA256", "default=yes");
174 ...
175 EVP_MD_meth_free(md);
176
177Fetch an implementation of SHA256 that is not from the default provider in the
178default context:
179
180 EVP_MD *md = EVP_MD_fetch(NULL, "SHA256", "default=no");
181 ...
182 EVP_MD_meth_free(md);
183
184Fetch an implementation of SHA256 from the default provider in the specified
185context:
186
187 EVP_MD *md = EVP_MD_fetch(ctx, "SHA256", "default=yes");
188 ...
189 EVP_MD_meth_free(md);
190
191Load the legacy provider into the default context and then fetch an
192implementation of whirlpool from it:
193
194 /* This only needs to be done once - usually at application start up */
195 OSSL_PROVIDER *legacy = OSSL_PROVIDER_load(NULL, "legacy");
196
197 EVP_MD *md = EVP_MD_fetch(NULL, "whirlpool", "legacy=yes");
198 ...
199 EVP_MD_meth_free(md);
200
201Note that in the above example the property string "legacy=yes" is optional
c2969ff6 202since, assuming no other providers have been loaded, the only implementation of
fdf6c0b6
MC
203the "whirlpool" algorithm is in the "legacy" provider. Also note that the
204default provider should be explicitly loaded if it is required in addition to
205other providers:
206
207 /* This only needs to be done once - usually at application start up */
208 OSSL_PROVIDER *legacy = OSSL_PROVIDER_load(NULL, "legacy");
209 OSSL_PROVIDER *default = OSSL_PROVIDER_load(NULL, "default");
210
211 EVP_MD *md_whirlpool = EVP_MD_fetch(NULL, "whirlpool", NULL);
212 EVP_MD *md_sha256 = EVP_MD_fetch(NULL, "SHA256", NULL);
213 ...
214 EVP_MD_meth_free(md_whirlpool);
215 EVP_MD_meth_free(md_sha256);
216
217=head1 SEE ALSO
218
42738cde
MC
219L<EVP_DigestInit_ex(3)>, L<EVP_EncryptInit_ex(3)>, L<EVP_MD_meth_new(3)>,
220L<EVP_MD_meth_free(3)>, L<EVP_CIPHER_meth_new(3)>, L<EVP_CIPHER_meth_free(3)>,
221L<EVP_MD_up_ref(3)>, L<EVP_CIPHER_up_ref(3)>, L<OSSL_PROVIDER_load(3)>,
222L<OPENSSL_CTX(3)>, L<EVP_set_default_properties(3)>
fdf6c0b6
MC
223
224=head1 HISTORY
225
226The functions described here were added in OpenSSL 3.0.
227
228=head1 COPYRIGHT
229
230Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
231
232Licensed under the Apache License 2.0 (the "License"). You may not use
233this file except in compliance with the License. You can obtain a copy
234in the file LICENSE in the source distribution or at
235L<https://www.openssl.org/source/license.html>.
236
237=cut