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