Debian Codegraph @

upstream/debian-unstable/man3/EVP_KDF.3ssl

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\" ========================================================================
56 .\"
57 .IX Title "EVP_KDF 3SSL"
58 .TH EVP_KDF 3SSL 2026-04-07 3.6.2 OpenSSL
59 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
60 .\" way too many mistakes in technical documents.
61 .if n .ad l
62 .nh
63 .SH NAME
64 EVP_KDF, EVP_KDF_fetch, EVP_KDF_free, EVP_KDF_up_ref,
65 EVP_KDF_CTX, EVP_KDF_CTX_new, EVP_KDF_CTX_free, EVP_KDF_CTX_dup,
66 EVP_KDF_CTX_reset, EVP_KDF_derive,
67 EVP_KDF_CTX_set_SKEY, EVP_KDF_derive_SKEY,
68 EVP_KDF_CTX_get_kdf_size,
69 EVP_KDF_get0_provider, EVP_KDF_CTX_kdf, EVP_KDF_is_a,
70 EVP_KDF_get0_name, EVP_KDF_names_do_all, EVP_KDF_get0_description,
71 EVP_KDF_CTX_get_params, EVP_KDF_CTX_set_params, EVP_KDF_do_all_provided,
72 EVP_KDF_get_params, EVP_KDF_gettable_params,
73 EVP_KDF_gettable_ctx_params, EVP_KDF_settable_ctx_params,
74 EVP_KDF_CTX_gettable_params, EVP_KDF_CTX_settable_params \- EVP KDF routines
75 .SH SYNOPSIS
76 .IX Header "SYNOPSIS"
77 .Vb 1
78 \& #include <openssl/kdf.h>
79 \&
80 \& typedef struct evp_kdf_st EVP_KDF;
81 \& typedef struct evp_kdf_ctx_st EVP_KDF_CTX;
82 \&
83 \& EVP_KDF_CTX *EVP_KDF_CTX_new(EVP_KDF *kdf);
84 \& const EVP_KDF *EVP_KDF_CTX_kdf(EVP_KDF_CTX *ctx);
85 \& void EVP_KDF_CTX_free(EVP_KDF_CTX *ctx);
86 \& EVP_KDF_CTX *EVP_KDF_CTX_dup(const EVP_KDF_CTX *src);
87 \& void EVP_KDF_CTX_reset(EVP_KDF_CTX *ctx);
88 \& size_t EVP_KDF_CTX_get_kdf_size(EVP_KDF_CTX *ctx);
89 \& int EVP_KDF_derive(EVP_KDF_CTX *ctx, unsigned char *key, size_t keylen,
90 \& const OSSL_PARAM params[]);
91 \& int EVP_KDF_CTX_set_SKEY(EVP_KDF_CTX *ctx, EVP_SKEY *key, const char *paramname);
92 \& EVP_SKEY *EVP_KDF_derive_SKEY(EVP_KDF_CTX *ctx, EVP_SKEYMGMT *mgmt,
93 \& const char *key_type, const char *propquery,
94 \& size_t keylen, const OSSL_PARAM params[]);
95 \& int EVP_KDF_up_ref(EVP_KDF *kdf);
96 \& void EVP_KDF_free(EVP_KDF *kdf);
97 \& EVP_KDF *EVP_KDF_fetch(OSSL_LIB_CTX *libctx, const char *algorithm,
98 \& const char *properties);
99 \& int EVP_KDF_is_a(const EVP_KDF *kdf, const char *name);
100 \& const char *EVP_KDF_get0_name(const EVP_KDF *kdf);
101 \& const char *EVP_KDF_get0_description(const EVP_KDF *kdf);
102 \& const OSSL_PROVIDER *EVP_KDF_get0_provider(const EVP_KDF *kdf);
103 \& void EVP_KDF_do_all_provided(OSSL_LIB_CTX *libctx,
104 \& void (*fn)(EVP_KDF *kdf, void *arg),
105 \& void *arg);
106 \& int EVP_KDF_names_do_all(const EVP_KDF *kdf,
107 \& void (*fn)(const char *name, void *data),
108 \& void *data);
109 \& int EVP_KDF_get_params(EVP_KDF *kdf, OSSL_PARAM params[]);
110 \& int EVP_KDF_CTX_get_params(EVP_KDF_CTX *ctx, OSSL_PARAM params[]);
111 \& int EVP_KDF_CTX_set_params(EVP_KDF_CTX *ctx, const OSSL_PARAM params[]);
112 \& const OSSL_PARAM *EVP_KDF_gettable_params(const EVP_KDF *kdf);
113 \& const OSSL_PARAM *EVP_KDF_gettable_ctx_params(const EVP_KDF *kdf);
114 \& const OSSL_PARAM *EVP_KDF_settable_ctx_params(const EVP_KDF *kdf);
115 \& const OSSL_PARAM *EVP_KDF_CTX_gettable_params(const EVP_KDF *kdf);
116 \& const OSSL_PARAM *EVP_KDF_CTX_settable_params(const EVP_KDF *kdf);
117 \& const OSSL_PROVIDER *EVP_KDF_get0_provider(const EVP_KDF *kdf);
118 .Ve
119 .SH DESCRIPTION
120 .IX Header "DESCRIPTION"
121 The EVP KDF routines are a high-level interface to Key Derivation Function
122 algorithms and should be used instead of algorithm-specific functions.
123 .PP
124 After creating a \fBEVP_KDF_CTX\fR for the required algorithm using
125 \&\fBEVP_KDF_CTX_new()\fR, inputs to the algorithm are supplied either by passing them
126 as part of the \fBEVP_KDF_derive()\fR or \fBEVP_KDF_derive_SKEY()\fR call or using calls to
127 \&\fBEVP_KDF_CTX_set_params()\fR or \fBEVP_KDF_CTX_set_SKEY()\fR before calling
128 \&\fBEVP_KDF_derive()\fR or \fBEVP_KDF_derive_SKEY()\fR to derive the key.
129 .SS Types
130 .IX Subsection "Types"
131 \&\fBEVP_KDF\fR is a type that holds the implementation of a KDF.
132 .PP
133 \&\fBEVP_KDF_CTX\fR is a context type that holds the algorithm inputs.
134 .SS "Algorithm implementation fetching"
135 .IX Subsection "Algorithm implementation fetching"
136 \&\fBEVP_KDF_fetch()\fR fetches an implementation of a KDF \fIalgorithm\fR, given
137 a library context \fIlibctx\fR and a set of \fIproperties\fR.
138 See "ALGORITHM FETCHING" in \fBcrypto\fR\|(7) for further information.
139 .PP
140 See "Key Derivation Function (KDF)" in \fBOSSL_PROVIDER\-default\fR\|(7) for the lists of
141 algorithms supported by the default provider.
142 .PP
143 The returned value must eventually be freed with
144 \&\fBEVP_KDF_free\fR\|(3).
145 .PP
146 \&\fBEVP_KDF_up_ref()\fR increments the reference count of an already fetched
147 KDF.
148 .PP
149 \&\fBEVP_KDF_free()\fR frees a fetched algorithm.
150 NULL is a valid parameter, for which this function is a no-op.
151 .SS "Context manipulation functions"
152 .IX Subsection "Context manipulation functions"
153 \&\fBEVP_KDF_CTX_new()\fR creates a new context for the KDF implementation \fIkdf\fR.
154 .PP
155 \&\fBEVP_KDF_CTX_free()\fR frees up the context \fIctx\fR. If \fIctx\fR is NULL, nothing
156 is done.
157 .PP
158 \&\fBEVP_KDF_CTX_kdf()\fR returns the \fBEVP_KDF\fR associated with the context
159 \&\fIctx\fR.
160 .SS "Computing functions"
161 .IX Subsection "Computing functions"
162 \&\fBEVP_KDF_CTX_reset()\fR resets the context to the default state as if the context
163 had just been created.
164 .PP
165 \&\fBEVP_KDF_derive()\fR processes any parameters in \fIParams\fR and then derives
166 \&\fIkeylen\fR bytes of key material and places it in the \fIkey\fR buffer.
167 If the algorithm produces a fixed amount of output then an error will
168 occur unless the \fIkeylen\fR parameter is equal to that output size,
169 as returned by \fBEVP_KDF_CTX_get_kdf_size()\fR.
170 .PP
171 \&\fBEVP_KDF_derive_SKEY()\fR behaves similarly except it returns an \fBEVP_SKEY\fR
172 object. If the \fIskeymgmt\fR argument is explicitly passed, it will be used for
173 the generated key. If the \fIskeymgmt\fR argument is NULL, the \fIkey_type\fR and
174 \&\fIpropquery\fR will be used for fetching the \fBEVP_SKEYMGMT\fR object linked to the
175 key. If the KDF doesn't support dealing with opaque keys or the passed
176 \&\fBEVP_SKEYMGMT\fR is from a different provider than the KDF method, the operation
177 will try to perform export/import through the raw format.
178 .PP
179 \&\fBEVP_KDF_CTX_set_SKEY()\fR allows setting an skey object as the input parameter for
180 the derivation functions. As different KDFs may accept several parameters as
181 key names, we can specify the particular parameter name we set. If null is
182 passed, the parameter \fBOSSL_KDF_PARAM_KEY\fR is implied. It is used when the
183 input key is represented by \fBEVP_SKEY\fR rather than raw bytes.
184 .PP
185 \&\fBEVP_KDF_get_params()\fR retrieves details about the implementation
186 \&\fIkdf\fR.
187 The set of parameters given with \fIparams\fR determine exactly what
188 parameters should be retrieved.
189 Note that a parameter that is unknown in the underlying context is
190 simply ignored.
191 .PP
192 \&\fBEVP_KDF_CTX_get_params()\fR retrieves chosen parameters, given the
193 context \fIctx\fR and its underlying context.
194 The set of parameters given with \fIparams\fR determine exactly what
195 parameters should be retrieved.
196 Note that a parameter that is unknown in the underlying context is
197 simply ignored.
198 .PP
199 \&\fBEVP_KDF_CTX_set_params()\fR passes chosen parameters to the underlying
200 context, given a context \fIctx\fR.
201 The set of parameters given with \fIparams\fR determine exactly what
202 parameters are passed down.
203 Note that a parameter that is unknown in the underlying context is
204 simply ignored.
205 Also, what happens when a needed parameter isn't passed down is
206 defined by the implementation.
207 .PP
208 \&\fBEVP_KDF_gettable_params()\fR returns an \fBOSSL_PARAM\fR\|(3) array that describes
209 the retrievable and settable parameters. \fBEVP_KDF_gettable_params()\fR
210 returns parameters that can be used with \fBEVP_KDF_get_params()\fR.
211 .PP
212 \&\fBEVP_KDF_gettable_ctx_params()\fR and \fBEVP_KDF_CTX_gettable_params()\fR
213 return constant \fBOSSL_PARAM\fR\|(3) arrays that describe the retrievable
214 parameters that can be used with \fBEVP_KDF_CTX_get_params()\fR.
215 \&\fBEVP_KDF_gettable_ctx_params()\fR returns the parameters that can be retrieved
216 from the algorithm, whereas \fBEVP_KDF_CTX_gettable_params()\fR returns
217 the parameters that can be retrieved in the context's current state.
218 .PP
219 \&\fBEVP_KDF_settable_ctx_params()\fR and \fBEVP_KDF_CTX_settable_params()\fR return
220 constant \fBOSSL_PARAM\fR\|(3) arrays that describe the settable parameters that
221 can be used with \fBEVP_KDF_CTX_set_params()\fR. \fBEVP_KDF_settable_ctx_params()\fR
222 returns the parameters that can be retrieved from the algorithm,
223 whereas \fBEVP_KDF_CTX_settable_params()\fR returns the parameters that can
224 be retrieved in the context's current state.
225 .SS "Information functions"
226 .IX Subsection "Information functions"
227 \&\fBEVP_KDF_CTX_get_kdf_size()\fR returns the output size if the algorithm produces a fixed amount
228 of output and \fBSIZE_MAX\fR otherwise. If an error occurs then 0 is returned.
229 For some algorithms an error may result if input parameters necessary to
230 calculate a fixed output size have not yet been supplied.
231 .PP
232 \&\fBEVP_KDF_is_a()\fR returns 1 if \fIkdf\fR is an implementation of an
233 algorithm that's identifiable with \fIname\fR, otherwise 0.
234 .PP
235 \&\fBEVP_KDF_get0_provider()\fR returns the provider that holds the implementation
236 of the given \fIkdf\fR.
237 .PP
238 \&\fBEVP_KDF_do_all_provided()\fR traverses all KDF implemented by all activated
239 providers in the given library context \fIlibctx\fR, and for each of the
240 implementations, calls the given function \fIfn\fR with the implementation method
241 and the given \fIarg\fR as argument.
242 .PP
243 \&\fBEVP_KDF_get0_name()\fR return the name of the given KDF. For fetched KDFs
244 with multiple names, only one of them is returned; it's
245 recommended to use \fBEVP_KDF_names_do_all()\fR instead.
246 .PP
247 \&\fBEVP_KDF_names_do_all()\fR traverses all names for \fIkdf\fR, and calls
248 \&\fIfn\fR with each name and \fIdata\fR.
249 .PP
250 \&\fBEVP_KDF_get0_description()\fR returns a description of the \fIkdf\fR, meant for
251 display and human consumption. The description is at the discretion of
252 the \fIkdf\fR implementation.
253 .SH PARAMETERS
254 .IX Header "PARAMETERS"
255 The standard parameter names are:
256 .IP """pass"" (\fBOSSL_KDF_PARAM_PASSWORD\fR) <octet string>" 4
257 .IX Item """pass"" (OSSL_KDF_PARAM_PASSWORD) <octet string>"
258 Some KDF implementations require a password.
259 For those KDF implementations that support it, this parameter sets the password.
260 .IP """salt"" (\fBOSSL_KDF_PARAM_SALT\fR) <octet string>" 4
261 .IX Item """salt"" (OSSL_KDF_PARAM_SALT) <octet string>"
262 Some KDF implementations can take a non-secret unique cryptographic salt.
263 For those KDF implementations that support it, this parameter sets the salt.
264 .Sp
265 The default value, if any, is implementation dependent.
266 .IP """iter"" (\fBOSSL_KDF_PARAM_ITER\fR) <unsigned integer>" 4
267 .IX Item """iter"" (OSSL_KDF_PARAM_ITER) <unsigned integer>"
268 Some KDF implementations require an iteration count.
269 For those KDF implementations that support it, this parameter sets the
270 iteration count.
271 .Sp
272 The default value, if any, is implementation dependent.
273 .IP """properties"" (\fBOSSL_KDF_PARAM_PROPERTIES\fR) <UTF8 string>" 4
274 .IX Item """properties"" (OSSL_KDF_PARAM_PROPERTIES) <UTF8 string>"
275 .PD 0
276 .IP """mac"" (\fBOSSL_KDF_PARAM_MAC\fR) <UTF8 string>" 4
277 .IX Item """mac"" (OSSL_KDF_PARAM_MAC) <UTF8 string>"
278 .IP """digest"" (\fBOSSL_KDF_PARAM_DIGEST\fR) <UTF8 string>" 4
279 .IX Item """digest"" (OSSL_KDF_PARAM_DIGEST) <UTF8 string>"
280 .IP """cipher"" (\fBOSSL_KDF_PARAM_CIPHER\fR) <UTF8 string>" 4
281 .IX Item """cipher"" (OSSL_KDF_PARAM_CIPHER) <UTF8 string>"
282 .PD
283 For KDF implementations that use an underlying computation MAC, digest or
284 cipher, these parameters set what the algorithm should be.
285 .Sp
286 The value is always the name of the intended algorithm,
287 or the properties.
288 .Sp
289 Note that not all algorithms may support all possible underlying
290 implementations.
291 .IP """key"" (\fBOSSL_KDF_PARAM_KEY\fR) <octet string>" 4
292 .IX Item """key"" (OSSL_KDF_PARAM_KEY) <octet string>"
293 Some KDF implementations require a key.
294 For those KDF implementations that support it, this octet string parameter
295 sets the key.
296 .IP """info"" (\fBOSSL_KDF_PARAM_INFO\fR) <octet string>" 4
297 .IX Item """info"" (OSSL_KDF_PARAM_INFO) <octet string>"
298 Some KDF implementations, such as \fBEVP_KDF\-HKDF\fR\|(7), take an 'info' parameter
299 for binding the derived key material
300 to application\- and context-specific information.
301 This parameter sets the info, fixed info, other info or shared info argument.
302 You can specify this parameter multiple times, and each instance will
303 be concatenated to form the final value.
304 .IP """maclen"" (\fBOSSL_KDF_PARAM_MAC_SIZE\fR) <unsigned integer>" 4
305 .IX Item """maclen"" (OSSL_KDF_PARAM_MAC_SIZE) <unsigned integer>"
306 Used by implementations that use a MAC with a variable output size (KMAC).
307 For those KDF implementations that support it, this parameter
308 sets the MAC output size.
309 .Sp
310 The default value, if any, is implementation dependent.
311 The length must never exceed what can be given with a \fBsize_t\fR.
312 .IP """maxmem_bytes"" (\fBOSSL_KDF_PARAM_SCRYPT_MAXMEM\fR) <unsigned integer>" 4
313 .IX Item """maxmem_bytes"" (OSSL_KDF_PARAM_SCRYPT_MAXMEM) <unsigned integer>"
314 Memory-hard password-based KDF algorithms, such as scrypt, use an amount of
315 memory that depends on the load factors provided as input.
316 For those KDF implementations that support it, this \fBuint64_t\fR parameter sets
317 an upper limit on the amount of memory that may be consumed while performing
318 a key derivation.
319 If this memory usage limit is exceeded because the load factors are chosen
320 too high, the key derivation will fail.
321 .Sp
322 The default value is implementation dependent.
323 The memory size must never exceed what can be given with a \fBsize_t\fR.
324 .SH "RETURN VALUES"
325 .IX Header "RETURN VALUES"
326 \&\fBEVP_KDF_fetch()\fR returns a pointer to a newly fetched \fBEVP_KDF\fR, or
327 NULL if allocation failed.
328 .PP
329 \&\fBEVP_KDF_get0_provider()\fR returns a pointer to the provider for the KDF, or
330 NULL on error.
331 .PP
332 \&\fBEVP_KDF_up_ref()\fR returns 1 on success, 0 on error.
333 .PP
334 \&\fBEVP_KDF_CTX_new()\fR returns either the newly allocated
335 \&\fBEVP_KDF_CTX\fR structure or NULL if an error occurred.
336 .PP
337 \&\fBEVP_KDF_CTX_free()\fR and \fBEVP_KDF_CTX_reset()\fR do not return a value.
338 .PP
339 \&\fBEVP_KDF_CTX_get_kdf_size()\fR returns the output size. \fBSIZE_MAX\fR is returned to indicate
340 that the algorithm produces a variable amount of output; 0 to indicate failure.
341 .PP
342 \&\fBEVP_KDF_get0_name()\fR returns the name of the KDF, or NULL on error.
343 .PP
344 \&\fBEVP_KDF_names_do_all()\fR returns 1 if the callback was called for all names. A
345 return value of 0 means that the callback was not called for any names.
346 .PP
347 \&\fBEVP_KDF_derive_SKEY()\fR returns the \fBEVP_SKEY\fR object on success or NULL on failure.
348 .PP
349 The remaining functions return 1 for success and 0 for failure.
350 .SH NOTES
351 .IX Header "NOTES"
352 The KDF life-cycle is described in \fBlife_cycle\-kdf\fR\|(7). In the future,
353 the transitions described there will be enforced. When this is done, it will
354 not be considered a breaking change to the API.
355 .SH "SEE ALSO"
356 .IX Header "SEE ALSO"
357 "Key Derivation Function (KDF)" in \fBOSSL_PROVIDER\-default\fR\|(7),
358 \&\fBlife_cycle\-kdf\fR\|(7).
359 .SH HISTORY
360 .IX Header "HISTORY"
361 This functionality was added in OpenSSL 3.0.
362 .PP
363 \&\fBEVP_KDF_derive_SKEY()\fR and \fBEVP_KDF_CTX_set_SKEY()\fR functions were introduced in
364 OpenSSL 3.6.
365 .SH COPYRIGHT
366 .IX Header "COPYRIGHT"
367 Copyright 2019\-2025 The OpenSSL Project Authors. All Rights Reserved.
368 .PP
369 Licensed under the Apache License 2.0 (the "License"). You may not use
370 this file except in compliance with the License. You can obtain a copy
371 in the file LICENSE in the source distribution or at
372 <https://www.openssl.org/source/license.html>.