fc09d5fad89bc064a10de1adc60846d6eada0c4e
[oweals/openssl.git] / doc / man3 / EVP_KDF.pod
1 =pod
2
3 =head1 NAME
4
5 EVP_KDF, EVP_KDF_fetch, EVP_KDF_free, EVP_KDF_provider, EVP_KDF_up_ref,
6 EVP_KDF_name,
7 EVP_KDF_CTX, EVP_KDF_CTX_new, EVP_KDF_CTX_free, EVP_KDF_CTX_kdf,
8 EVP_KDF_reset, EVP_KDF_size, EVP_KDF_derive, EVP_KDF_CTX_dup,
9 EVP_KDF_CTX_get_params, EVP_KDF_CTX_set_params, EVP_KDF_do_all_ex,
10 EVP_KDF_get_params, EVP_KDF_CTX_gettable_params, EVP_KDF_CTX_settable_params,
11 EVP_KDF_gettable_params - EVP KDF routines
12
13 =head1 SYNOPSIS
14
15  #include <openssl/kdf.h>
16
17  typedef struct evp_kdf_st EVP_KDF;
18  typedef struct evp_kdf_ctx_st EVP_KDF_CTX;
19
20  EVP_KDF_CTX *EVP_KDF_CTX_new(const EVP_KDF *kdf);
21  const EVP_KDF *EVP_KDF_CTX_kdf(EVP_KDF_CTX *ctx);
22  void EVP_KDF_CTX_free(EVP_KDF_CTX *ctx);
23  EVP_KDF_CTX *EVP_KDF_CTX_dup(const EVP_KDF_CTX *src);
24  void EVP_KDF_reset(EVP_KDF_CTX *ctx);
25  size_t EVP_KDF_size(EVP_KDF_CTX *ctx);
26  int EVP_KDF_derive(EVP_KDF_CTX *ctx, unsigned char *key, size_t keylen);
27  const char *EVP_KDF_name(const EVP_KDF *kdf);
28  int EVP_KDF_up_ref(EVP_KDF *kdf);
29  void EVP_KDF_free(EVP_KDF *kdf);
30  EVP_KDF *EVP_KDF_fetch(OPENSSL_CTX *libctx, const char *algorithm,
31                         const char *properties);
32  void EVP_KDF_do_all_ex(OPENSSL_CTX *libctx,
33                         void (*fn)(EVP_KDF *kdf, void *arg),
34                         void *arg);
35  int EVP_KDF_get_params(EVP_KDF *kdf, OSSL_PARAM params[]);
36  int EVP_KDF_CTX_get_params(EVP_KDF_CTX *ctx, OSSL_PARAM params[]);
37  int EVP_KDF_CTX_set_params(EVP_KDF_CTX *ctx, const OSSL_PARAM params[]);
38  const OSSL_PARAM *EVP_KDF_gettable_params(const EVP_KDF *kdf);
39  const OSSL_PARAM *EVP_KDF_CTX_gettable_params(const EVP_KDF *kdf);
40  const OSSL_PARAM *EVP_KDF_CTX_settable_params(const EVP_KDF *kdf);
41  const OSSL_PROVIDER *EVP_KDF_provider(const EVP_KDF *kdf);
42
43 =head1 DESCRIPTION
44
45 The EVP KDF routines are a high level interface to Key Derivation Function
46 algorithms and should be used instead of algorithm-specific functions.
47
48 After creating a B<EVP_KDF_CTX> for the required algorithm using
49 EVP_KDF_CTX_new(), inputs to the algorithm are supplied
50 using calls to EVP_KDF_CTX_set_params() before
51 calling EVP_KDF_derive() to derive the key.
52
53 =head2 Types
54
55 B<EVP_KDF> is a type that holds the implementation of a KDF.
56
57 B<EVP_KDF_CTX> is a context type that holds the algorithm inputs.
58
59 =head2 Algorithm implementation fetching
60
61 EVP_KDF_fetch() fetches an implementation of a KDF I<algorithm>, given
62 a library context I<libctx> and a set of I<properties>.
63 See L<provider(7)/Fetching algorithms> for further information.
64
65 The returned value must eventually be freed with
66 L<EVP_KDF_free(3)>.
67
68 EVP_KDF_up_ref() increments the reference count of an already fetched
69 KDF.
70
71 EVP_KDF_free() frees a fetched algorithm.
72 NULL is a valid parameter, for which this function is a no-op.
73
74 =head2 Context manipulation functions
75
76 EVP_KDF_CTX_new() creates a new context for the KDF implementation I<kdf>.
77
78 EVP_KDF_CTX_free() frees up the context C<ctx>.  If I<ctx> is NULL, nothing
79 is done.
80
81 EVP_KDF_CTX_kdf() returns the B<EVP_KDF> associated with the context
82 I<ctx>.
83
84 =head2 Computing functions
85
86 EVP_KDF_reset() resets the context to the default state as if the context
87 had just been created.
88
89 EVP_KDF_derive() derives C<keylen> bytes of key material and places it in the
90 I<key> buffer.  If the algorithm produces a fixed amount of output then an
91 error will occur unless the C<keylen> parameter is equal to that output size,
92 as returned by EVP_KDF_size().
93
94 EVP_KDF_get_params() retrieves details about the implementation
95 I<kdf>.
96 The set of parameters given with I<params> determine exactly what
97 parameters should be retrieved.
98 Note that a parameter that is unknown in the underlying context is
99 simply ignored.
100
101 EVP_KDF_CTX_get_params() retrieves chosen parameters, given the
102 context I<ctx> and its underlying context.
103 The set of parameters given with I<params> determine exactly what
104 parameters should be retrieved.
105 Note that a parameter that is unknown in the underlying context is
106 simply ignored.
107
108 EVP_KDF_CTX_set_params() passes chosen parameters to the underlying
109 context, given a context I<ctx>.
110 The set of parameters given with I<params> determine exactly what
111 parameters are passed down.
112 Note that a parameter that is unknown in the underlying context is
113 simply ignored.
114 Also, what happens when a needed parameter isn't passed down is
115 defined by the implementation.
116
117 EVP_KDF_gettable_params(), EVP_KDF_CTX_gettable_params() and
118 EVP_KDF_CTX_settable_params() get a constant B<OSSL_PARAM> array that
119 decribes the retrievable and settable parameters, i.e. parameters that
120 can be used with EVP_KDF_get_params(), EVP_KDF_CTX_get_params()
121 and EVP_KDF_CTX_set_params(), respectively.
122 See L<OSSL_PARAM(3)> for the use of B<OSSL_PARAM> as parameter descriptor.
123
124 =head2 Information functions
125
126 EVP_KDF_size() returns the output size if the algorithm produces a fixed amount
127 of output and B<SIZE_MAX> otherwise.  If an error occurs then 0 is returned.
128 For some algorithms an error may result if input parameters necessary to
129 calculate a fixed output size have not yet been supplied.
130
131 EVP_KDF_name() returns the name of the given KDF implementation.
132
133 EVP_KDF_provider() returns the provider that holds the implementation
134 of the given I<kdf>.
135
136 EVP_KDF_do_all_ex() traverses all KDF implemented by all activated
137 providers in the given library context I<libctx>, and for each of the
138 implementations, calls the given function I<fn> with the implementation method
139 and the given I<arg> as argument.
140
141 =head1 PARAMETER NAMES
142
143 The standard parameter names are:
144
145 =over 4
146
147 =item B<OSSL_KDF_PARAM_PASSWORD> ("pass") <octet string>
148
149 Some KDF implementations require a password.
150 For those KDF implementations that support it, this parameter sets the password.
151
152 =item B<OSSL_KDF_PARAM_SALT> ("salt") <octet string>
153
154 Some KDF implementations can take a salt.
155 For those KDF implementations that support it, this parameter sets the salt.
156
157 The default value, if any, is implementation dependent.
158
159 =item B<OSSL_KDF_PARAM_ITER> ("iter") <unsigned int>
160
161 Some KDF implementations require an iteration count.
162 For those KDF implementations that support it, this parameter sets the
163 iteration count.
164
165 The default value, if any, is implementation dependent.
166
167 =item B<OSSL_KDF_PARAM_PROPERTIES> ("properties") <UTF8 string>
168
169 Some KDF implementations use other cryptographic algorithms, this parameter
170 sets what property query will be used to fetch the implementation.
171
172 =item B<OSSL_KDF_PARAM_MAC> ("mac") <UTF8 string>
173
174 Some KDF implementations use a MAC as an underlying computation
175 algorithm, this parameter sets what the MAC algorithm should be.
176
177 =item B<OSSL_KDF_PARAM_DIGEST> ("digest") <UTF8 string>
178
179 For MAC implementations that use a message digest as an underlying computation
180 algorithm, this parameter sets what the digest algorithm should be.
181
182 =item B<OSSL_KDF_PARAM_KEY> ("key") <octet string>
183
184 Some KDF implementations require a key.
185 For those KDF implementations that support it, this octet string parameter
186 sets the key.
187
188 =item B<OSSL_KDF_PARAM_MAC_SIZE> ("maclen") <size_t>
189
190 Used by implementations that use a MAC with a variable output size (KMAC).
191 For those KDF implementations that support it, this parameter
192 sets the MAC output size.
193
194 The default value, if any, is implementation dependent.
195
196 =item B<OSSL_KDF_PARAM_SCRYPT_MAXMEM> ("macmaxmem_byteslen") <size_t>
197
198 Memory-hard password-based KDF algorithms, such as scrypt, use an amount of
199 memory that depends on the load factors provided as input.
200 For those KDF implementations that support it, this uint64_t parameter sets
201 an upper limit on the amount of memory that may be consumed while performing
202 a key derivation.
203 If this memory usage limit is exceeded because the load factors are chosen
204 too high, the key derivation will fail.
205
206 The default value is implementation dependent.
207
208 =back
209
210 =head1 RETURN VALUES
211
212 EVP_MAC_fetch() returns a pointer to a newly fetched B<EVP_KDF>, or
213 NULL if allocation failed.
214
215 EVP_KDF_name() returns the name for the given I<kdf>, if it has been
216 added to the object database.
217
218 EVP_KDF_provider() returns a pointer to the provider for the KDF, or
219 NULL on error.
220
221 EVP_MAC_up_ref() returns 1 on success, 0 on error.
222
223 EVP_KDF_CTX_new() returns either the newly allocated
224 C<EVP_KDF_CTX> structure or C<NULL> if an error occurred.
225
226 EVP_KDF_CTX_free() and EVP_KDF_reset() do not return a value.
227
228 EVP_KDF_size() returns the output size.  C<SIZE_MAX> is returned to indicate
229 that the algorithm produces a variable amount of output; 0 to indicate failure.
230
231 The remaining functions return 1 for success and 0 or a negative value for
232 failure.  In particular, a return value of -2 indicates the operation is not
233 supported by the KDF algorithm.
234
235 =head1 SEE ALSO
236
237 L<EVP_KDF-SCRYPT(7)>
238 L<EVP_KDF-TLS1_PRF(7)>
239 L<EVP_KDF-PBKDF2(7)>
240 L<EVP_KDF-HKDF(7)>
241 L<EVP_KDF-SS(7)>
242 L<EVP_KDF-SSHKDF(7)>
243 L<EVP_KDF-X963(7)>
244 L<EVP_KDF-X942(7)>
245
246 =head1 HISTORY
247
248 This functionality was added to OpenSSL 3.0.
249
250 =head1 COPYRIGHT
251
252 Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
253
254 Licensed under the Apache License 2.0 (the "License").  You may not use
255 this file except in compliance with the License.  You can obtain a copy
256 in the file LICENSE in the source distribution or at
257 L<https://www.openssl.org/source/license.html>.
258
259 =cut