Use PARAMETERS instead of PARAMETER NAMES for the heading for consistency.
[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 PARAMETERS
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 integer>
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 =item B<OSSL_KDF_PARAM_MAC> ("mac") <UTF8 string>
170
171 =item B<OSSL_KDF_PARAM_DIGEST> ("digest") <UTF8 string>
172
173 =item B<OSSL_MAC_PARAM_ENGINE> ("engine") <UTF8 string>
174
175 For KDF implementations that use an underlying computation MAC or
176 digest, these parameters set what the algorithm should be, and the
177 engine that implements the algorithm or the properties to fetch it
178 by if needed.
179
180 The value is always the name of the intended engine, algorithm,
181 or the properties.
182
183 Note that not all algorithms may support all possible underlying
184 implementations.
185
186 =item B<OSSL_KDF_PARAM_KEY> ("key") <octet string>
187
188 Some KDF implementations require a key.
189 For those KDF implementations that support it, this octet string parameter
190 sets the key.
191
192 =item B<OSSL_KDF_PARAM_MAC_SIZE> ("maclen") <unsigned integer>
193
194 Used by implementations that use a MAC with a variable output size (KMAC).
195 For those KDF implementations that support it, this parameter
196 sets the MAC output size.
197
198 The default value, if any, is implementation dependent.
199 The length must never exceed what can be given with a B<size_t>.
200
201 =item B<OSSL_KDF_PARAM_SCRYPT_MAXMEM> ("macmaxmem_byteslen") <unsigned integer>
202
203 Memory-hard password-based KDF algorithms, such as scrypt, use an amount of
204 memory that depends on the load factors provided as input.
205 For those KDF implementations that support it, this uint64_t parameter sets
206 an upper limit on the amount of memory that may be consumed while performing
207 a key derivation.
208 If this memory usage limit is exceeded because the load factors are chosen
209 too high, the key derivation will fail.
210
211 The default value is implementation dependent.
212 The memory size must never exceed what can be given with a B<size_t>.
213
214 =back
215
216 =head1 RETURN VALUES
217
218 EVP_MAC_fetch() returns a pointer to a newly fetched B<EVP_KDF>, or
219 NULL if allocation failed.
220
221 EVP_KDF_name() returns the name for the given I<kdf>, if it has been
222 added to the object database.
223
224 EVP_KDF_provider() returns a pointer to the provider for the KDF, or
225 NULL on error.
226
227 EVP_MAC_up_ref() returns 1 on success, 0 on error.
228
229 EVP_KDF_CTX_new() returns either the newly allocated
230 C<EVP_KDF_CTX> structure or C<NULL> if an error occurred.
231
232 EVP_KDF_CTX_free() and EVP_KDF_reset() do not return a value.
233
234 EVP_KDF_size() returns the output size.  C<SIZE_MAX> is returned to indicate
235 that the algorithm produces a variable amount of output; 0 to indicate failure.
236
237 The remaining functions return 1 for success and 0 or a negative value for
238 failure.  In particular, a return value of -2 indicates the operation is not
239 supported by the KDF algorithm.
240
241 =head1 SEE ALSO
242
243 L<EVP_KDF-SCRYPT(7)>
244 L<EVP_KDF-TLS1_PRF(7)>
245 L<EVP_KDF-PBKDF2(7)>
246 L<EVP_KDF-HKDF(7)>
247 L<EVP_KDF-SS(7)>
248 L<EVP_KDF-SSHKDF(7)>
249 L<EVP_KDF-X963(7)>
250 L<EVP_KDF-X942(7)>
251
252 =head1 HISTORY
253
254 This functionality was added to OpenSSL 3.0.
255
256 =head1 COPYRIGHT
257
258 Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
259
260 Licensed under the Apache License 2.0 (the "License").  You may not use
261 this file except in compliance with the License.  You can obtain a copy
262 in the file LICENSE in the source distribution or at
263 L<https://www.openssl.org/source/license.html>.
264
265 =cut