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_CTX_get_params, EVP_KDF_CTX_set_params, EVP_KDF_do_all_provided,
10 EVP_KDF_get_params, EVP_KDF_gettable_ctx_params, EVP_KDF_settable_ctx_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 int EVP_KDF_is_a(const EVP_KDF *kdf, const char *name);
33 const OSSL_PROVIDER *EVP_KDF_provider(const EVP_KDF *kdf);
34 void EVP_KDF_do_all_provided(OPENSSL_CTX *libctx,
35 void (*fn)(EVP_KDF *kdf, void *arg),
37 int EVP_KDF_get_params(EVP_KDF *kdf, OSSL_PARAM params[]);
38 int EVP_KDF_CTX_get_params(EVP_KDF_CTX *ctx, OSSL_PARAM params[]);
39 int EVP_KDF_CTX_set_params(EVP_KDF_CTX *ctx, const OSSL_PARAM params[]);
40 const OSSL_PARAM *EVP_KDF_gettable_params(const EVP_KDF *kdf);
41 const OSSL_PARAM *EVP_KDF_gettable_ctx_params(const EVP_KDF *kdf);
42 const OSSL_PARAM *EVP_KDF_settable_ctx_params(const EVP_KDF *kdf);
43 const OSSL_PROVIDER *EVP_KDF_provider(const EVP_KDF *kdf);
47 The EVP KDF routines are a high level interface to Key Derivation Function
48 algorithms and should be used instead of algorithm-specific functions.
50 After creating a B<EVP_KDF_CTX> for the required algorithm using
51 EVP_KDF_CTX_new(), inputs to the algorithm are supplied
52 using calls to EVP_KDF_CTX_set_params() before
53 calling EVP_KDF_derive() to derive the key.
57 B<EVP_KDF> is a type that holds the implementation of a KDF.
59 B<EVP_KDF_CTX> is a context type that holds the algorithm inputs.
61 =head2 Algorithm implementation fetching
63 EVP_KDF_fetch() fetches an implementation of a KDF I<algorithm>, given
64 a library context I<libctx> and a set of I<properties>.
65 See L<provider(7)/Fetching algorithms> for further information.
67 The returned value must eventually be freed with
70 EVP_KDF_up_ref() increments the reference count of an already fetched
73 EVP_KDF_free() frees a fetched algorithm.
74 NULL is a valid parameter, for which this function is a no-op.
76 =head2 Context manipulation functions
78 EVP_KDF_CTX_new() creates a new context for the KDF implementation I<kdf>.
80 EVP_KDF_CTX_free() frees up the context I<ctx>. If I<ctx> is NULL, nothing
83 EVP_KDF_CTX_kdf() returns the B<EVP_KDF> associated with the context
86 =head2 Computing functions
88 EVP_KDF_reset() resets the context to the default state as if the context
89 had just been created.
91 EVP_KDF_derive() derives I<keylen> bytes of key material and places it in the
92 I<key> buffer. If the algorithm produces a fixed amount of output then an
93 error will occur unless the I<keylen> parameter is equal to that output size,
94 as returned by EVP_KDF_size().
96 EVP_KDF_get_params() retrieves details about the implementation
98 The set of parameters given with I<params> determine exactly what
99 parameters should be retrieved.
100 Note that a parameter that is unknown in the underlying context is
103 EVP_KDF_CTX_get_params() retrieves chosen parameters, given the
104 context I<ctx> and its underlying context.
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_set_params() passes chosen parameters to the underlying
111 context, given a context I<ctx>.
112 The set of parameters given with I<params> determine exactly what
113 parameters are passed down.
114 Note that a parameter that is unknown in the underlying context is
116 Also, what happens when a needed parameter isn't passed down is
117 defined by the implementation.
119 EVP_KDF_gettable_params(), EVP_KDF_gettable_ctx_params() and
120 EVP_KDF_settable_ctx_params() get a constant B<OSSL_PARAM> array that
121 decribes the retrievable and settable parameters, i.e. parameters that
122 can be used with EVP_KDF_get_params(), EVP_KDF_CTX_get_params()
123 and EVP_KDF_CTX_set_params(), respectively.
124 See L<OSSL_PARAM(3)> for the use of B<OSSL_PARAM> as parameter descriptor.
126 =head2 Information functions
128 EVP_KDF_size() returns the output size if the algorithm produces a fixed amount
129 of output and B<SIZE_MAX> otherwise. If an error occurs then 0 is returned.
130 For some algorithms an error may result if input parameters necessary to
131 calculate a fixed output size have not yet been supplied.
133 EVP_KDF_name() returns the name of the given KDF implementation.
135 EVP_KDF_is_a() returns 1 if I<kdf> is an implementation of an
136 algorithm that's identifiable with I<name>, otherwise 0.
138 EVP_KDF_provider() returns the provider that holds the implementation
141 EVP_KDF_do_all_provided() traverses all KDF implemented by all activated
142 providers in the given library context I<libctx>, and for each of the
143 implementations, calls the given function I<fn> with the implementation method
144 and the given I<arg> as argument.
148 The standard parameter names are:
152 =item "pass" (B<OSSL_KDF_PARAM_PASSWORD>) <octet string>
154 Some KDF implementations require a password.
155 For those KDF implementations that support it, this parameter sets the password.
157 =item "salt" (B<OSSL_KDF_PARAM_SALT>) <octet string>
159 Some KDF implementations can take a salt.
160 For those KDF implementations that support it, this parameter sets the salt.
162 The default value, if any, is implementation dependent.
164 =item "iter" (B<OSSL_KDF_PARAM_ITER>) <unsigned integer>
166 Some KDF implementations require an iteration count.
167 For those KDF implementations that support it, this parameter sets the
170 The default value, if any, is implementation dependent.
172 =item "properties" (B<OSSL_KDF_PARAM_PROPERTIES>) <UTF8 string>
174 =item "mac" (B<OSSL_KDF_PARAM_MAC>) <UTF8 string>
176 =item "digest" (B<OSSL_KDF_PARAM_DIGEST>) <UTF8 string>
178 For KDF implementations that use an underlying computation MAC or
179 digest, these parameters set what the algorithm should be.
181 The value is always the name of the intended algorithm,
184 Note that not all algorithms may support all possible underlying
187 =item "key" (B<OSSL_KDF_PARAM_KEY>) <octet string>
189 Some KDF implementations require a key.
190 For those KDF implementations that support it, this octet string parameter
193 =item "maclen" (B<OSSL_KDF_PARAM_MAC_SIZE>) <unsigned integer>
195 Used by implementations that use a MAC with a variable output size (KMAC).
196 For those KDF implementations that support it, this parameter
197 sets the MAC output size.
199 The default value, if any, is implementation dependent.
200 The length must never exceed what can be given with a B<size_t>.
202 =item "maxmem_bytes" (B<OSSL_KDF_PARAM_SCRYPT_MAXMEM>) <unsigned integer>
204 Memory-hard password-based KDF algorithms, such as scrypt, use an amount of
205 memory that depends on the load factors provided as input.
206 For those KDF implementations that support it, this B<uint64_t> parameter sets
207 an upper limit on the amount of memory that may be consumed while performing
209 If this memory usage limit is exceeded because the load factors are chosen
210 too high, the key derivation will fail.
212 The default value is implementation dependent.
213 The memory size must never exceed what can be given with a B<size_t>.
219 EVP_KDF_fetch() returns a pointer to a newly fetched B<EVP_KDF>, or
220 NULL if allocation failed.
222 EVP_KDF_name() returns the name for the given I<kdf>, if it has been
223 added to the object database.
225 EVP_KDF_provider() returns a pointer to the provider for the KDF, or
228 EVP_KDF_up_ref() returns 1 on success, 0 on error.
230 EVP_KDF_CTX_new() returns either the newly allocated
231 B<EVP_KDF_CTX> structure or NULL if an error occurred.
233 EVP_KDF_CTX_free() and EVP_KDF_reset() do not return a value.
235 EVP_KDF_size() returns the output size. B<SIZE_MAX> is returned to indicate
236 that the algorithm produces a variable amount of output; 0 to indicate failure.
238 The remaining functions return 1 for success and 0 or a negative value for
239 failure. In particular, a return value of -2 indicates the operation is not
240 supported by the KDF algorithm.
245 L<EVP_KDF-TLS1_PRF(7)>
255 This functionality was added to OpenSSL 3.0.
259 Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
261 Licensed under the Apache License 2.0 (the "License"). You may not use
262 this file except in compliance with the License. You can obtain a copy
263 in the file LICENSE in the source distribution or at
264 L<https://www.openssl.org/source/license.html>.