5 EVP_KDF, EVP_KDF_fetch, EVP_KDF_free, EVP_KDF_provider, EVP_KDF_up_ref,
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
15 #include <openssl/kdf.h>
17 typedef struct evp_kdf_st EVP_KDF;
18 typedef struct evp_kdf_ctx_st EVP_KDF_CTX;
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),
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);
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.
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.
55 B<EVP_KDF> is a type that holds the implementation of a KDF.
57 B<EVP_KDF_CTX> is a context type that holds the algorithm inputs.
59 =head2 Algorithm implementation fetching
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.
65 The returned value must eventually be freed with
68 EVP_KDF_up_ref() increments the reference count of an already fetched
71 EVP_KDF_free() frees a fetched algorithm.
72 NULL is a valid parameter, for which this function is a no-op.
74 =head2 Context manipulation functions
76 EVP_KDF_CTX_new() creates a new context for the KDF implementation I<kdf>.
78 EVP_KDF_CTX_free() frees up the context C<ctx>. If I<ctx> is NULL, nothing
81 EVP_KDF_CTX_kdf() returns the B<EVP_KDF> associated with the context
84 =head2 Computing functions
86 EVP_KDF_reset() resets the context to the default state as if the context
87 had just been created.
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().
94 EVP_KDF_get_params() retrieves details about the implementation
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
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
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
114 Also, what happens when a needed parameter isn't passed down is
115 defined by the implementation.
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.
124 =head2 Information functions
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.
131 EVP_KDF_name() returns the name of the given KDF implementation.
133 EVP_KDF_provider() returns the provider that holds the implementation
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.
143 The standard parameter names are:
147 =item B<OSSL_KDF_PARAM_PASSWORD> ("pass") <octet string>
149 Some KDF implementations require a password.
150 For those KDF implementations that support it, this parameter sets the password.
152 =item B<OSSL_KDF_PARAM_SALT> ("salt") <octet string>
154 Some KDF implementations can take a salt.
155 For those KDF implementations that support it, this parameter sets the salt.
157 The default value, if any, is implementation dependent.
159 =item B<OSSL_KDF_PARAM_ITER> ("iter") <unsigned integer>
161 Some KDF implementations require an iteration count.
162 For those KDF implementations that support it, this parameter sets the
165 The default value, if any, is implementation dependent.
167 =item B<OSSL_KDF_PARAM_PROPERTIES> ("properties") <UTF8 string>
169 =item B<OSSL_KDF_PARAM_MAC> ("mac") <UTF8 string>
171 =item B<OSSL_KDF_PARAM_DIGEST> ("digest") <UTF8 string>
173 For KDF implementations that use an underlying computation MAC or
174 digest, these parameters set what the algorithm should be.
176 The value is always the name of the intended algorithm,
179 Note that not all algorithms may support all possible underlying
182 =item B<OSSL_KDF_PARAM_KEY> ("key") <octet string>
184 Some KDF implementations require a key.
185 For those KDF implementations that support it, this octet string parameter
188 =item B<OSSL_KDF_PARAM_MAC_SIZE> ("maclen") <unsigned integer>
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.
194 The default value, if any, is implementation dependent.
195 The length must never exceed what can be given with a B<size_t>.
197 =item B<OSSL_KDF_PARAM_SCRYPT_MAXMEM> ("macmaxmem_byteslen") <unsigned integer>
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 uint64_t parameter sets
202 an upper limit on the amount of memory that may be consumed while performing
204 If this memory usage limit is exceeded because the load factors are chosen
205 too high, the key derivation will fail.
207 The default value is implementation dependent.
208 The memory size must never exceed what can be given with a B<size_t>.
214 EVP_MAC_fetch() returns a pointer to a newly fetched B<EVP_KDF>, or
215 NULL if allocation failed.
217 EVP_KDF_name() returns the name for the given I<kdf>, if it has been
218 added to the object database.
220 EVP_KDF_provider() returns a pointer to the provider for the KDF, or
223 EVP_MAC_up_ref() returns 1 on success, 0 on error.
225 EVP_KDF_CTX_new() returns either the newly allocated
226 C<EVP_KDF_CTX> structure or C<NULL> if an error occurred.
228 EVP_KDF_CTX_free() and EVP_KDF_reset() do not return a value.
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.
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.
240 L<EVP_KDF-TLS1_PRF(7)>
250 This functionality was added to OpenSSL 3.0.
254 Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
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>.