5 EVP_KDF, EVP_KDF_CTX, EVP_KDF_CTX_new, EVP_KDF_CTX_free,
6 EVP_KDF_CTX_kdf, EVP_KDF_reset,
7 EVP_KDF_size, EVP_KDF_derive, EVP_KDF_name,
9 EVP_KDF_CTX_get_params,
10 EVP_KDF_CTX_set_params,
15 EVP_KDF_CTX_gettable_params,
16 EVP_KDF_CTX_settable_params,
17 EVP_KDF_gettable_params,
18 EVP_KDF_provider, EVP_KDF_up_ref,
19 EVP_get_kdfbyname, EVP_get_kdfbynid, EVP_get_kdfbyobj - EVP KDF routines
23 #include <openssl/kdf.h>
25 typedef struct evp_kdf_st EVP_KDF;
26 typedef struct evp_kdf_ctx_st EVP_KDF_CTX;
28 EVP_KDF_CTX *EVP_KDF_CTX_new(const EVP_KDF *kdf);
29 const EVP_KDF *EVP_KDF_CTX_kdf(EVP_KDF_CTX *ctx);
30 void EVP_KDF_CTX_free(EVP_KDF_CTX *ctx);
31 EVP_KDF_CTX *EVP_KDF_CTX_dup(const EVP_KDF_CTX *src);
32 void EVP_KDF_reset(EVP_KDF_CTX *ctx);
33 size_t EVP_KDF_size(EVP_KDF_CTX *ctx);
34 int EVP_KDF_derive(EVP_KDF_CTX *ctx, unsigned char *key, size_t keylen);
35 const char *EVP_KDF_name(const EVP_KDF *kdf);
36 int EVP_KDF_up_ref(EVP_KDF *kdf);
37 void EVP_KDF_free(EVP_KDF *kdf);
38 EVP_KDF *EVP_KDF_fetch(OPENSSL_CTX *libctx, const char *algorithm,
39 const char *properties);
40 void EVP_KDF_do_all_ex(OPENSSL_CTX *libctx,
41 void (*fn)(EVP_KDF *kdf, void *arg),
43 int EVP_KDF_get_params(EVP_KDF *kdf, OSSL_PARAM params[]);
44 int EVP_KDF_CTX_get_params(EVP_KDF_CTX *ctx, OSSL_PARAM params[]);
45 int EVP_KDF_CTX_set_params(EVP_KDF_CTX *ctx, const OSSL_PARAM params[]);
46 const OSSL_PARAM *EVP_KDF_gettable_params(const EVP_KDF *kdf);
47 const OSSL_PARAM *EVP_KDF_CTX_gettable_params(const EVP_KDF *kdf);
48 const OSSL_PARAM *EVP_KDF_CTX_settable_params(const EVP_KDF *kdf);
49 const OSSL_PROVIDER *EVP_KDF_provider(const EVP_KDF *kdf);
50 const EVP_KDF *EVP_get_kdfbyname(const char *name);
51 const EVP_KDF *EVP_get_kdfbynid(int nid);
52 const EVP_KDF *EVP_get_kdfbyobj(const ASN1_OBJECT *o);
56 The EVP KDF routines are a high level interface to Key Derivation Function
57 algorithms and should be used instead of algorithm-specific functions.
59 After creating a C<EVP_KDF_CTX> for the required algorithm using
60 EVP_KDF_CTX_new(), inputs to the algorithm are supplied
61 using calls to EVP_KDF_CTX_set_params() before
62 calling EVP_KDF_derive() to derive the key.
66 B<EVP_KDF> is a type that holds the implementation of a KDF.
68 B<EVP_KDF_CTX> is a context type that holds the algorithm inputs.
70 =head2 Context manipulation functions
72 EVP_KDF_CTX_new() creates a new context for the KDF type C<kdf>.
74 EVP_KDF_CTX_free() frees up the context C<ctx>. If C<ctx> is C<NULL>, nothing
77 EVP_KDF_CTX_kdf() returns the B<EVP_KDF> associated with the context
80 =head2 Computing functions
82 EVP_KDF_reset() resets the context to the default state as if the context
83 had just been created.
85 EVP_KDF_CTX_set_params() is used to provide inputs to the KDF algorithm prior to
86 EVP_KDF_derive() being called. The inputs that may be provided will vary
87 depending on the KDF algorithm or its implementation.
88 See L</CONTROLS> below for a description of standard controls.
90 EVP_KDF_derive() derives C<keylen> bytes of key material and places it in the
91 C<key> buffer. If the algorithm produces a fixed amount of output then an
92 error will occur unless the C<keylen> parameter is equal to that output size,
93 as returned by EVP_KDF_size().
95 =head2 Information functions
97 EVP_KDF_size() returns the output size if the algorithm produces a fixed amount
98 of output and C<SIZE_MAX> otherwise. If an error occurs then 0 is returned.
99 For some algorithms an error may result if input parameters necessary to
100 calculate a fixed output size have not yet been supplied.
102 EVP_KDF_name() returns the name of the given KDF implementation.
104 =head2 Object database functions
106 EVP_get_kdfbyname() fetches a KDF implementation from the object
109 EVP_get_kdfbynid() fetches a KDF implementation from the object
110 database by numeric identity.
112 EVP_get_kdfbyobj() fetches a KDF implementation from the object
113 database by ASN.1 OBJECT (i.e. an encoded OID).
117 The standard controls are:
121 =item B<EVP_KDF_CTRL_SET_PASS>
123 This control expects two arguments: C<unsigned char *pass>, C<size_t passlen>
125 Some KDF implementations require a password. For those KDF implementations
126 that support it, this control sets the password.
132 The value string is used as is.
136 The value string is expected to be a hexadecimal number, which will be
137 decoded before being passed on as the control value.
141 =item B<EVP_KDF_CTRL_SET_SALT>
143 This control expects two arguments: C<unsigned char *salt>, C<size_t saltlen>
145 Some KDF implementations can take a salt. For those KDF implementations that
146 support it, this control sets the salt.
148 The default value, if any, is implementation dependent.
154 The value string is used as is.
158 The value string is expected to be a hexadecimal number, which will be
159 decoded before being passed on as the control value.
163 =item B<EVP_KDF_CTRL_SET_ITER>
165 This control expects one argument: C<int iter>
167 Some KDF implementations require an iteration count. For those KDF implementations that support it, this control sets the iteration count.
169 The default value, if any, is implementation dependent.
171 =item B<EVP_KDF_CTRL_SET_MAC>
173 This control expects one argument: C<EVP_MAC *mac>
175 Some KDF implementations use a MAC as an underlying computation
176 algorithm, this control sets what the MAC algorithm should be.
178 =item B<EVP_KDF_CTRL_SET_MD>
180 This control expects one argument: C<EVP_MD *md>
182 For MAC implementations that use a message digest as an underlying computation
183 algorithm, this control sets what the digest algorithm should be.
185 =item B<EVP_KDF_CTRL_SET_KEY>
187 This control expects two arguments: C<unsigned char *key>, C<size_t keylen>
189 Some KDF implementations require a key. For those KDF implementations that
190 support it, this control sets the key.
196 The value string is used as is.
200 The value string is expected to be a hexadecimal number, which will be
201 decoded before being passed on as the control value.
205 =item B<EVP_KDF_CTRL_SET_MAC_SIZE>
207 This control expects one argument: C<size_t size>
209 Used by implementations that use a MAC with a variable output size (KMAC). For
210 those KDF implementations that support it, this control sets the MAC output size.
212 The default value, if any, is implementation dependent.
214 =item B<EVP_KDF_CTRL_SET_MAXMEM_BYTES>
216 This control expects one argument: C<uint64_t maxmem_bytes>
218 Memory-hard password-based KDF algorithms, such as scrypt, use an amount of
219 memory that depends on the load factors provided as input. For those KDF
220 implementations that support it, this control sets an upper limit on the amount
221 of memory that may be consumed while performing a key derivation. If this
222 memory usage limit is exceeded because the load factors are chosen too high,
223 the key derivation will fail.
225 The default value is implementation dependent.
231 EVP_KDF_CTX_new() returns either the newly allocated
232 C<EVP_KDF_CTX> structure or C<NULL> if an error occurred.
234 EVP_KDF_CTX_free() and EVP_KDF_reset() do not return a value.
236 EVP_KDF_size() returns the output size. C<SIZE_MAX> is returned to indicate
237 that the algorithm produces a variable amount of output; 0 to indicate failure.
239 EVP_KDF_name() returns the name for the given C<kdf>, if it has been
240 added to the object database.
242 EVP_get_kdfbyname(), EVP_get_kdfbynid() and EVP_get_kdfbyobj() return
243 the requested KDF implementation, if it exists in the object database,
246 The remaining functions return 1 for success and 0 or a negative value for
247 failure. In particular, a return value of -2 indicates the operation is not
248 supported by the KDF algorithm.
253 L<EVP_KDF_TLS1_PRF(7)>
263 This functionality was added to OpenSSL 3.0.
267 Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
269 Licensed under the Apache License 2.0 (the "License"). You may not use
270 this file except in compliance with the License. You can obtain a copy
271 in the file LICENSE in the source distribution or at
272 L<https://www.openssl.org/source/license.html>.