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_number, EVP_KDF_names_do_all,
10 EVP_KDF_CTX_get_params, EVP_KDF_CTX_set_params, EVP_KDF_do_all_provided,
11 EVP_KDF_get_params, EVP_KDF_gettable_ctx_params, EVP_KDF_settable_ctx_params,
12 EVP_KDF_gettable_params - EVP KDF routines
16 #include <openssl/kdf.h>
18 typedef struct evp_kdf_st EVP_KDF;
19 typedef struct evp_kdf_ctx_st EVP_KDF_CTX;
21 EVP_KDF_CTX *EVP_KDF_CTX_new(const EVP_KDF *kdf);
22 const EVP_KDF *EVP_KDF_CTX_kdf(EVP_KDF_CTX *ctx);
23 void EVP_KDF_CTX_free(EVP_KDF_CTX *ctx);
24 EVP_KDF_CTX *EVP_KDF_CTX_dup(const EVP_KDF_CTX *src);
25 void EVP_KDF_reset(EVP_KDF_CTX *ctx);
26 size_t EVP_KDF_size(EVP_KDF_CTX *ctx);
27 int EVP_KDF_derive(EVP_KDF_CTX *ctx, unsigned char *key, size_t keylen);
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_number(const EVP_KDF *kdf);
33 int EVP_KDF_is_a(const EVP_KDF *kdf, const char *name);
34 const OSSL_PROVIDER *EVP_KDF_provider(const EVP_KDF *kdf);
35 void EVP_KDF_do_all_provided(OPENSSL_CTX *libctx,
36 void (*fn)(EVP_KDF *kdf, void *arg),
38 void EVP_KDF_names_do_all(const EVP_KDF *kdf,
39 void (*fn)(const char *name, void *data),
41 int EVP_KDF_get_params(EVP_KDF *kdf, OSSL_PARAM params[]);
42 int EVP_KDF_CTX_get_params(EVP_KDF_CTX *ctx, OSSL_PARAM params[]);
43 int EVP_KDF_CTX_set_params(EVP_KDF_CTX *ctx, const OSSL_PARAM params[]);
44 const OSSL_PARAM *EVP_KDF_gettable_params(const EVP_KDF *kdf);
45 const OSSL_PARAM *EVP_KDF_gettable_ctx_params(const EVP_KDF *kdf);
46 const OSSL_PARAM *EVP_KDF_settable_ctx_params(const EVP_KDF *kdf);
47 const OSSL_PROVIDER *EVP_KDF_provider(const EVP_KDF *kdf);
51 The EVP KDF routines are a high-level interface to Key Derivation Function
52 algorithms and should be used instead of algorithm-specific functions.
54 After creating a B<EVP_KDF_CTX> for the required algorithm using
55 EVP_KDF_CTX_new(), inputs to the algorithm are supplied
56 using calls to EVP_KDF_CTX_set_params() before
57 calling EVP_KDF_derive() to derive the key.
61 B<EVP_KDF> is a type that holds the implementation of a KDF.
63 B<EVP_KDF_CTX> is a context type that holds the algorithm inputs.
65 =head2 Algorithm implementation fetching
67 EVP_KDF_fetch() fetches an implementation of a KDF I<algorithm>, given
68 a library context I<libctx> and a set of I<properties>.
69 See L<provider(7)/Fetching algorithms> for further information.
71 See L<OSSL_PROVIDER-default(7)/Key Derivation Function (KDF)> for the lists of
72 algorithms supported by the default provider.
74 The returned value must eventually be freed with
77 EVP_KDF_up_ref() increments the reference count of an already fetched
80 EVP_KDF_free() frees a fetched algorithm.
81 NULL is a valid parameter, for which this function is a no-op.
83 =head2 Context manipulation functions
85 EVP_KDF_CTX_new() creates a new context for the KDF implementation I<kdf>.
87 EVP_KDF_CTX_free() frees up the context I<ctx>. If I<ctx> is NULL, nothing
90 EVP_KDF_CTX_kdf() returns the B<EVP_KDF> associated with the context
93 =head2 Computing functions
95 EVP_KDF_reset() resets the context to the default state as if the context
96 had just been created.
98 EVP_KDF_derive() derives I<keylen> bytes of key material and places it in the
99 I<key> buffer. If the algorithm produces a fixed amount of output then an
100 error will occur unless the I<keylen> parameter is equal to that output size,
101 as returned by EVP_KDF_size().
103 EVP_KDF_get_params() retrieves details about the implementation
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
110 EVP_KDF_CTX_get_params() retrieves chosen parameters, given the
111 context I<ctx> and its underlying context.
112 The set of parameters given with I<params> determine exactly what
113 parameters should be retrieved.
114 Note that a parameter that is unknown in the underlying context is
117 EVP_KDF_CTX_set_params() passes chosen parameters to the underlying
118 context, given a context I<ctx>.
119 The set of parameters given with I<params> determine exactly what
120 parameters are passed down.
121 Note that a parameter that is unknown in the underlying context is
123 Also, what happens when a needed parameter isn't passed down is
124 defined by the implementation.
126 EVP_KDF_gettable_params(), EVP_KDF_gettable_ctx_params() and
127 EVP_KDF_settable_ctx_params() get a constant B<OSSL_PARAM> array that
128 describes the retrievable and settable parameters, i.e. parameters that
129 can be used with EVP_KDF_get_params(), EVP_KDF_CTX_get_params()
130 and EVP_KDF_CTX_set_params(), respectively.
131 See L<OSSL_PARAM(3)> for the use of B<OSSL_PARAM> as parameter descriptor.
133 =head2 Information functions
135 EVP_KDF_size() returns the output size if the algorithm produces a fixed amount
136 of output and B<SIZE_MAX> otherwise. If an error occurs then 0 is returned.
137 For some algorithms an error may result if input parameters necessary to
138 calculate a fixed output size have not yet been supplied.
140 EVP_KDF_is_a() returns 1 if I<kdf> is an implementation of an
141 algorithm that's identifiable with I<name>, otherwise 0.
143 EVP_KDF_provider() returns the provider that holds the implementation
146 EVP_KDF_do_all_provided() traverses all KDF implemented by all activated
147 providers in the given library context I<libctx>, and for each of the
148 implementations, calls the given function I<fn> with the implementation method
149 and the given I<arg> as argument.
151 EVP_KDF_number() returns the internal dynamic number assigned to
154 EVP_KDF_names_do_all() traverses all names for I<kdf>, and calls
155 I<fn> with each name and I<data>.
159 The standard parameter names are:
163 =item "pass" (B<OSSL_KDF_PARAM_PASSWORD>) <octet string>
165 Some KDF implementations require a password.
166 For those KDF implementations that support it, this parameter sets the password.
168 =item "salt" (B<OSSL_KDF_PARAM_SALT>) <octet string>
170 Some KDF implementations can take a salt.
171 For those KDF implementations that support it, this parameter sets the salt.
173 The default value, if any, is implementation dependent.
175 =item "iter" (B<OSSL_KDF_PARAM_ITER>) <unsigned integer>
177 Some KDF implementations require an iteration count.
178 For those KDF implementations that support it, this parameter sets the
181 The default value, if any, is implementation dependent.
183 =item "properties" (B<OSSL_KDF_PARAM_PROPERTIES>) <UTF8 string>
185 =item "mac" (B<OSSL_KDF_PARAM_MAC>) <UTF8 string>
187 =item "digest" (B<OSSL_KDF_PARAM_DIGEST>) <UTF8 string>
189 =item "cipher" (B<OSSL_KDF_PARAM_CIPHER>) <UTF8 string>
191 For KDF implementations that use an underlying computation MAC, digest or
192 cipher, these parameters set what the algorithm should be.
194 The value is always the name of the intended algorithm,
197 Note that not all algorithms may support all possible underlying
200 =item "key" (B<OSSL_KDF_PARAM_KEY>) <octet string>
202 Some KDF implementations require a key.
203 For those KDF implementations that support it, this octet string parameter
206 =item "maclen" (B<OSSL_KDF_PARAM_MAC_SIZE>) <unsigned integer>
208 Used by implementations that use a MAC with a variable output size (KMAC).
209 For those KDF implementations that support it, this parameter
210 sets the MAC output size.
212 The default value, if any, is implementation dependent.
213 The length must never exceed what can be given with a B<size_t>.
215 =item "maxmem_bytes" (B<OSSL_KDF_PARAM_SCRYPT_MAXMEM>) <unsigned integer>
217 Memory-hard password-based KDF algorithms, such as scrypt, use an amount of
218 memory that depends on the load factors provided as input.
219 For those KDF implementations that support it, this B<uint64_t> parameter sets
220 an upper limit on the amount of memory that may be consumed while performing
222 If this memory usage limit is exceeded because the load factors are chosen
223 too high, the key derivation will fail.
225 The default value is implementation dependent.
226 The memory size must never exceed what can be given with a B<size_t>.
232 EVP_KDF_fetch() returns a pointer to a newly fetched B<EVP_KDF>, or
233 NULL if allocation failed.
235 EVP_KDF_provider() returns a pointer to the provider for the KDF, or
238 EVP_KDF_up_ref() returns 1 on success, 0 on error.
240 EVP_KDF_CTX_new() returns either the newly allocated
241 B<EVP_KDF_CTX> structure or NULL if an error occurred.
243 EVP_KDF_CTX_free() and EVP_KDF_reset() do not return a value.
245 EVP_KDF_size() returns the output size. B<SIZE_MAX> is returned to indicate
246 that the algorithm produces a variable amount of output; 0 to indicate failure.
248 The remaining functions return 1 for success and 0 or a negative value for
249 failure. In particular, a return value of -2 indicates the operation is not
250 supported by the KDF algorithm.
254 L<OSSL_PROVIDER-default(7)/Key Derivation Function (KDF)>
258 This functionality was added to OpenSSL 3.0.
262 Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
264 Licensed under the Apache License 2.0 (the "License"). You may not use
265 this file except in compliance with the License. You can obtain a copy
266 in the file LICENSE in the source distribution or at
267 L<https://www.openssl.org/source/license.html>.