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