5 EVP_KDF_CTX, EVP_KDF_CTX_new_id, EVP_KDF_CTX_free, EVP_KDF_reset,
6 EVP_KDF_ctrl, EVP_KDF_vctrl, EVP_KDF_ctrl_str, EVP_KDF_size,
7 EVP_KDF_derive - EVP KDF routines
11 #include <openssl/kdf.h>
13 typedef struct evp_kdf_ctx_st EVP_KDF_CTX;
15 EVP_KDF_CTX *EVP_KDF_CTX_new_id(int id);
16 void EVP_KDF_CTX_free(EVP_KDF_CTX *ctx);
17 void EVP_KDF_reset(EVP_KDF_CTX *ctx);
18 int EVP_KDF_ctrl(EVP_KDF_CTX *ctx, int cmd, ...);
19 int EVP_KDF_vctrl(EVP_KDF_CTX *ctx, int cmd, va_list args);
20 int EVP_KDF_ctrl_str(EVP_KDF_CTX *ctx, const char *type, const char *value);
21 size_t EVP_KDF_size(EVP_KDF_CTX *ctx);
22 int EVP_KDF_derive(EVP_KDF_CTX *ctx, unsigned char *key, size_t keylen);
26 The EVP KDF routines are a high level interface to Key Derivation Function
27 algorithms and should be used instead of algorithm-specific functions.
29 After creating a C<EVP_KDF_CTX> for the required algorithm using
30 EVP_KDF_CTX_new_id(), inputs to the algorithm are supplied using calls to
31 EVP_KDF_ctrl(), EVP_KDF_vctrl() or EVP_KDF_ctrl_str() before calling
32 EVP_KDF_derive() to derive the key.
36 B<EVP_KDF_CTX> is a context type that holds the algorithm inputs.
38 =head2 Context manipulation functions
40 EVP_KDF_CTX_new_id() creates a KDF context for the algorithm identified by the
43 EVP_KDF_CTX_free() frees up the context C<ctx>. If C<ctx> is C<NULL>, nothing
46 =head2 Computing functions
48 EVP_KDF_reset() resets the context to the default state as if the context
49 had just been created.
51 EVP_KDF_ctrl() is used to provide inputs to the KDF algorithm prior to
52 EVP_KDF_derive() being called. The inputs that may be provided will vary
53 depending on the KDF algorithm or its implementation. This functions takes
54 variable arguments, the exact expected arguments depend on C<cmd>.
55 See L</CONTROLS> below for a description of standard controls.
57 EVP_KDF_vctrl() is the variant of EVP_KDF_ctrl() that takes a C<va_list>
58 argument instead of variadic arguments.
60 EVP_KDF_ctrl_str() allows an application to send an algorithm specific control
61 operation to a context C<ctx> in string form. This is intended to be used for
62 options specified on the command line or in text files.
64 EVP_KDF_size() returns the output size if the algorithm produces a fixed amount
65 of output and C<SIZE_MAX> otherwise. If an error occurs then 0 is returned.
66 For some algorithms an error may result if input parameters necessary to
67 calculate a fixed output size have not yet been supplied.
69 EVP_KDF_derive() derives C<keylen> bytes of key material and places it in the
70 C<key> buffer. If the algorithm produces a fixed amount of output then an
71 error will occur unless the C<keylen> parameter is equal to that output size,
72 as returned by EVP_KDF_size().
76 The standard controls are:
80 =item B<EVP_KDF_CTRL_SET_PASS>
82 This control expects two arguments: C<unsigned char *pass>, C<size_t passlen>
84 Some KDF implementations require a password. For those KDF implementations
85 that support it, this control sets the password.
87 EVP_KDF_ctrl_str() takes two type strings for this control:
93 The value string is used as is.
97 The value string is expected to be a hexadecimal number, which will be
98 decoded before being passed on as the control value.
102 =item B<EVP_KDF_CTRL_SET_SALT>
104 This control expects two arguments: C<unsigned char *salt>, C<size_t saltlen>
106 Some KDF implementations can take a salt. For those KDF implementations that
107 support it, this control sets the salt.
109 The default value, if any, is implementation dependent.
111 EVP_KDF_ctrl_str() takes two type strings for this control:
117 The value string is used as is.
121 The value string is expected to be a hexadecimal number, which will be
122 decoded before being passed on as the control value.
126 =item B<EVP_KDF_CTRL_SET_ITER>
128 This control expects one argument: C<int iter>
130 Some KDF implementations require an iteration count. For those KDF implementations that support it, this control sets the iteration count.
132 The default value, if any, is implementation dependent.
134 EVP_KDF_ctrl_str() type string: "iter"
136 The value string is expected to be a decimal number.
138 =item B<EVP_KDF_CTRL_SET_MD>
140 This control expects one argument: C<EVP_MD *md>
142 For MAC implementations that use a message digest as an underlying computation
143 algorithm, this control set what the digest algorithm should be.
145 EVP_KDF_ctrl_str() type string: "md"
147 The value string is expected to be the name of a digest.
149 =item B<EVP_KDF_CTRL_SET_KEY>
151 This control expects two arguments: C<unsigned char *key>, C<size_t keylen>
153 Some KDF implementations require a key. For those KDF implementations that
154 support it, this control sets the key.
156 EVP_KDF_ctrl_str() takes two type strings for this control:
162 The value string is used as is.
166 The value string is expected to be a hexadecimal number, which will be
167 decoded before being passed on as the control value.
171 =item B<EVP_KDF_CTRL_SET_MAXMEM_BYTES>
173 This control expects one argument: C<uint64_t maxmem_bytes>
175 Memory-hard password-based KDF algorithms, such as scrypt, use an amount of
176 memory that depends on the load factors provided as input. For those KDF
177 implementations that support it, this control sets an upper limit on the amount
178 of memory that may be consumed while performing a key derivation. If this
179 memory usage limit is exceeded because the load factors are chosen too high,
180 the key derivation will fail.
182 The default value is implementation dependent.
184 EVP_KDF_ctrl_str() type string: "maxmem_bytes"
186 The value string is expected to be a decimal number.
192 EVP_KDF_CTX_new_id() returns either the newly allocated C<EVP_KDF_CTX>
193 structure or C<NULL> if an error occurred.
195 EVP_KDF_CTX_free() and EVP_KDF_reset() do not return a value.
197 EVP_KDF_size() returns the output size. C<SIZE_MAX> is returned to indicate
198 that the algorithm produces a variable amount of output; 0 to indicate failure.
200 The remaining functions return 1 for success and 0 or a negative value for
201 failure. In particular, a return value of -2 indicates the operation is not
202 supported by the KDF algorithm.
210 Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
212 Licensed under the Apache License 2.0 (the "License"). You may not use
213 this file except in compliance with the License. You can obtain a copy
214 in the file LICENSE in the source distribution or at
215 L<https://www.openssl.org/source/license.html>.