1PROVIDER-KDF(7ossl)                 OpenSSL                PROVIDER-KDF(7ossl)
2
3
4

NAME

6       provider-kdf - The KDF library <-> provider functions
7

SYNOPSIS

9        #include <openssl/core_dispatch.h>
10        #include <openssl/core_names.h>
11
12        /*
13         * None of these are actual functions, but are displayed like this for
14         * the function signatures for functions that are offered as function
15         * pointers in OSSL_DISPATCH arrays.
16         */
17
18        /* Context management */
19        void *OSSL_FUNC_kdf_newctx(void *provctx);
20        void OSSL_FUNC_kdf_freectx(void *kctx);
21        void *OSSL_FUNC_kdf_dupctx(void *src);
22
23        /* Encryption/decryption */
24        int OSSL_FUNC_kdf_reset(void *kctx);
25        int OSSL_FUNC_kdf_derive(void *kctx, unsigned char *key, size_t keylen,
26                                 const OSSL_PARAM params[]);
27
28        /* KDF parameter descriptors */
29        const OSSL_PARAM *OSSL_FUNC_kdf_gettable_params(void *provctx);
30        const OSSL_PARAM *OSSL_FUNC_kdf_gettable_ctx_params(void *kcxt, void *provctx);
31        const OSSL_PARAM *OSSL_FUNC_kdf_settable_ctx_params(void *kcxt, void *provctx);
32
33        /* KDF parameters */
34        int OSSL_FUNC_kdf_get_params(OSSL_PARAM params[]);
35        int OSSL_FUNC_kdf_get_ctx_params(void *kctx, OSSL_PARAM params[]);
36        int OSSL_FUNC_kdf_set_ctx_params(void *kctx, const OSSL_PARAM params[]);
37

DESCRIPTION

39       This documentation is primarily aimed at provider authors. See
40       provider(7) for further information.
41
42       The KDF operation enables providers to implement KDF algorithms and
43       make them available to applications via the API functions
44       EVP_KDF_CTX_reset(3), and EVP_KDF_derive(3).
45
46       All "functions" mentioned here are passed as function pointers between
47       libcrypto and the provider in OSSL_DISPATCH(3) arrays via
48       OSSL_ALGORITHM(3) arrays that are returned by the provider's
49       provider_query_operation() function (see "Provider Functions" in
50       provider-base(7)).
51
52       All these "functions" have a corresponding function type definition
53       named OSSL_FUNC_{name}_fn, and a helper function to retrieve the
54       function pointer from an OSSL_DISPATCH(3) element named
55       OSSL_FUNC_{name}.  For example, the "function" OSSL_FUNC_kdf_newctx()
56       has these:
57
58        typedef void *(OSSL_FUNC_kdf_newctx_fn)(void *provctx);
59        static ossl_inline OSSL_FUNC_kdf_newctx_fn
60            OSSL_FUNC_kdf_newctx(const OSSL_DISPATCH *opf);
61
62       OSSL_DISPATCH(3) array entries are identified by numbers that are
63       provided as macros in openssl-core_dispatch.h(7), as follows:
64
65        OSSL_FUNC_kdf_newctx               OSSL_FUNC_KDF_NEWCTX
66        OSSL_FUNC_kdf_freectx              OSSL_FUNC_KDF_FREECTX
67        OSSL_FUNC_kdf_dupctx               OSSL_FUNC_KDF_DUPCTX
68
69        OSSL_FUNC_kdf_reset                OSSL_FUNC_KDF_RESET
70        OSSL_FUNC_kdf_derive               OSSL_FUNC_KDF_DERIVE
71
72        OSSL_FUNC_kdf_get_params           OSSL_FUNC_KDF_GET_PARAMS
73        OSSL_FUNC_kdf_get_ctx_params       OSSL_FUNC_KDF_GET_CTX_PARAMS
74        OSSL_FUNC_kdf_set_ctx_params       OSSL_FUNC_KDF_SET_CTX_PARAMS
75
76        OSSL_FUNC_kdf_gettable_params      OSSL_FUNC_KDF_GETTABLE_PARAMS
77        OSSL_FUNC_kdf_gettable_ctx_params  OSSL_FUNC_KDF_GETTABLE_CTX_PARAMS
78        OSSL_FUNC_kdf_settable_ctx_params  OSSL_FUNC_KDF_SETTABLE_CTX_PARAMS
79
80       A KDF algorithm implementation may not implement all of these
81       functions.  In order to be a consistent set of functions, at least the
82       following functions must be implemented: OSSL_FUNC_kdf_newctx(),
83       OSSL_FUNC_kdf_freectx(), OSSL_FUNC_kdf_set_ctx_params(),
84       OSSL_FUNC_kdf_derive().  All other functions are optional.
85
86   Context Management Functions
87       OSSL_FUNC_kdf_newctx() should create and return a pointer to a provider
88       side structure for holding context information during a KDF operation.
89       A pointer to this context will be passed back in a number of the other
90       KDF operation function calls.  The parameter provctx is the provider
91       context generated during provider initialisation (see provider(7)).
92
93       OSSL_FUNC_kdf_freectx() is passed a pointer to the provider side KDF
94       context in the kctx parameter.  If it receives NULL as kctx value, it
95       should not do anything other than return.  This function should free
96       any resources associated with that context.
97
98       OSSL_FUNC_kdf_dupctx() should duplicate the provider side KDF context
99       in the kctx parameter and return the duplicate copy.
100
101   Encryption/Decryption Functions
102       OSSL_FUNC_kdf_reset() initialises a KDF operation given a provider side
103       KDF context in the kctx parameter.
104
105       OSSL_FUNC_kdf_derive() performs the KDF operation after processing the
106       params as per OSSL_FUNC_kdf_set_ctx_params().  The kctx parameter
107       contains a pointer to the provider side context.  The resulting key of
108       the desired keylen should be written to key.  If the algorithm does not
109       support the requested keylen the function must return error.
110
111   KDF Parameters
112       See OSSL_PARAM(3) for further details on the parameters structure used
113       by these functions.
114
115       OSSL_FUNC_kdf_get_params() gets details of parameter values associated
116       with the provider algorithm and stores them in params.
117
118       OSSL_FUNC_kdf_set_ctx_params() sets KDF parameters associated with the
119       given provider side KDF context kctx to params.  Any parameter settings
120       are additional to any that were previously set.  Passing NULL for
121       params should return true.
122
123       OSSL_FUNC_kdf_get_ctx_params() retrieves gettable parameter values
124       associated with the given provider side KDF context kctx and stores
125       them in params.  Passing NULL for params should return true.
126
127       OSSL_FUNC_kdf_gettable_params(), OSSL_FUNC_kdf_gettable_ctx_params(),
128       and OSSL_FUNC_kdf_settable_ctx_params() all return constant
129       OSSL_PARAM(3) arrays as descriptors of the parameters that
130       OSSL_FUNC_kdf_get_params(), OSSL_FUNC_kdf_get_ctx_params(), and
131       OSSL_FUNC_kdf_set_ctx_params() can handle, respectively.
132       OSSL_FUNC_kdf_gettable_ctx_params() and
133       OSSL_FUNC_kdf_settable_ctx_params() will return the parameters
134       associated with the provider side context kctx in its current state if
135       it is not NULL.  Otherwise, they return the parameters associated with
136       the provider side algorithm provctx.
137
138       Parameters currently recognised by built-in KDFs are as follows. Not
139       all parameters are relevant to, or are understood by all KDFs:
140
141       "size" (OSSL_KDF_PARAM_SIZE) <unsigned integer>
142           Gets the output size from the associated KDF ctx.  If the algorithm
143           produces a variable amount of output, SIZE_MAX should be returned.
144           If the input parameters required to calculate the fixed output size
145           have not yet been supplied, 0 should be returned indicating an
146           error.
147
148       "key" (OSSL_KDF_PARAM_KEY) <octet string>
149           Sets the key in the associated KDF ctx.
150
151       "secret" (OSSL_KDF_PARAM_SECRET) <octet string>
152           Sets the secret in the associated KDF ctx.
153
154       "pass" (OSSL_KDF_PARAM_PASSWORD) <octet string>
155           Sets the password in the associated KDF ctx.
156
157       "cipher" (OSSL_KDF_PARAM_CIPHER) <UTF8 string>
158       "digest" (OSSL_KDF_PARAM_DIGEST) <UTF8 string>
159       "mac" (OSSL_KDF_PARAM_MAC) <UTF8 string>
160           Sets the name of the underlying cipher, digest or MAC to be used.
161           It must name a suitable algorithm for the KDF that's being used.
162
163       "maclen" (OSSL_KDF_PARAM_MAC_SIZE) <octet string>
164           Sets the length of the MAC in the associated KDF ctx.
165
166       "properties" (OSSL_KDF_PARAM_PROPERTIES) <UTF8 string>
167           Sets the properties to be queried when trying to fetch the
168           underlying algorithm.  This must be given together with the
169           algorithm naming parameter to be considered valid.
170
171       "iter" (OSSL_KDF_PARAM_ITER) <unsigned integer>
172           Sets the number of iterations in the associated KDF ctx.
173
174       "mode" (OSSL_KDF_PARAM_MODE) <UTF8 string>
175           Sets the mode in the associated KDF ctx.
176
177       "pkcs5" (OSSL_KDF_PARAM_PKCS5) <integer>
178           Enables or diables the SP800-132 compliance checks.  A mode of 0
179           enables the compliance checks.
180
181           The checks performed are:
182
183           - the iteration count is at least 1000.
184           - the salt length is at least 128 bits.
185           - the derived key length is at least 112 bits.
186       "ukm" (OSSL_KDF_PARAM_UKM) <octet string>
187           Sets an optional random string that is provided by the sender
188           called "partyAInfo".  In CMS this is the user keying material.
189
190       "cekalg" (OSSL_KDF_PARAM_CEK_ALG) <UTF8 string>
191           Sets the CEK wrapping algorithm name in the associated KDF ctx.
192
193       "n" (OSSL_KDF_PARAM_SCRYPT_N) <unsigned integer>
194           Sets the scrypt work factor parameter N in the associated KDF ctx.
195
196       "r" (OSSL_KDF_PARAM_SCRYPT_R) <unsigned integer>
197           Sets the scrypt work factor parameter r in the associated KDF ctx.
198
199       "p" (OSSL_KDF_PARAM_SCRYPT_P) <unsigned integer>
200           Sets the scrypt work factor parameter p in the associated KDF ctx.
201
202       "maxmem_bytes" (OSSL_KDF_PARAM_SCRYPT_MAXMEM) <unsigned integer>
203           Sets the scrypt work factor parameter maxmem in the associated KDF
204           ctx.
205
206       "prefix" (OSSL_KDF_PARAM_PREFIX) <octet string>
207           Sets the prefix string using by the TLS 1.3 version of HKDF in the
208           associated KDF ctx.
209
210       "label" (OSSL_KDF_PARAM_LABEL) <octet string>
211           Sets the label string using by the TLS 1.3 version of HKDF in the
212           associated KDF ctx.
213
214       "data" (OSSL_KDF_PARAM_DATA) <octet string>
215           Sets the context string using by the TLS 1.3 version of HKDF in the
216           associated KDF ctx.
217
218       "info" (OSSL_KDF_PARAM_INFO) <octet string>
219           Sets the optional shared info in the associated KDF ctx.
220
221       "seed" (OSSL_KDF_PARAM_SEED) <octet string>
222           Sets the IV in the associated KDF ctx.
223
224       "xcghash" (OSSL_KDF_PARAM_SSHKDF_XCGHASH) <octet string>
225           Sets the xcghash in the associated KDF ctx.
226
227       "session_id" (OSSL_KDF_PARAM_SSHKDF_SESSION_ID) <octet string>
228           Sets the session ID in the associated KDF ctx.
229
230       "type" (OSSL_KDF_PARAM_SSHKDF_TYPE) <UTF8 string>
231           Sets the SSH KDF type parameter in the associated KDF ctx.  There
232           are six supported types:
233
234           EVP_KDF_SSHKDF_TYPE_INITIAL_IV_CLI_TO_SRV
235               The Initial IV from client to server.  A single char of value
236               65 (ASCII char 'A').
237
238           EVP_KDF_SSHKDF_TYPE_INITIAL_IV_SRV_TO_CLI
239               The Initial IV from server to client A single char of value 66
240               (ASCII char 'B').
241
242           EVP_KDF_SSHKDF_TYPE_ENCRYPTION_KEY_CLI_TO_SRV
243               The Encryption Key from client to server A single char of value
244               67 (ASCII char 'C').
245
246           EVP_KDF_SSHKDF_TYPE_ENCRYPTION_KEY_SRV_TO_CLI
247               The Encryption Key from server to client A single char of value
248               68 (ASCII char 'D').
249
250           EVP_KDF_SSHKDF_TYPE_INTEGRITY_KEY_CLI_TO_SRV
251               The Integrity Key from client to server A single char of value
252               69 (ASCII char 'E').
253
254           EVP_KDF_SSHKDF_TYPE_INTEGRITY_KEY_SRV_TO_CLI
255               The Integrity Key from client to server A single char of value
256               70 (ASCII char 'F').
257
258       "constant" (OSSL_KDF_PARAM_CONSTANT) <octet string>
259           Sets the constant value in the associated KDF ctx.
260
261       "id" (OSSL_KDF_PARAM_PKCS12_ID) <integer>
262           Sets the intended usage of the output bits in the associated KDF
263           ctx.  It is defined as per RFC 7292 section B.3.
264

RETURN VALUES

266       OSSL_FUNC_kdf_newctx() and OSSL_FUNC_kdf_dupctx() should return the
267       newly created provider side KDF context, or NULL on failure.
268
269       OSSL_FUNC_kdf_derive(), OSSL_FUNC_kdf_get_params(),
270       OSSL_FUNC_kdf_get_ctx_params() and OSSL_FUNC_kdf_set_ctx_params()
271       should return 1 for success or 0 on error.
272
273       OSSL_FUNC_kdf_gettable_params(), OSSL_FUNC_kdf_gettable_ctx_params()
274       and OSSL_FUNC_kdf_settable_ctx_params() should return a constant
275       OSSL_PARAM(3) array, or NULL if none is offered.
276

NOTES

278       The KDF life-cycle is described in life_cycle-kdf(7).  Providers should
279       ensure that the various transitions listed there are supported.  At
280       some point the EVP layer will begin enforcing the listed transitions.
281

SEE ALSO

283       provider(7), life_cycle-kdf(7), EVP_KDF(3).
284

HISTORY

286       The provider KDF interface was introduced in OpenSSL 3.0.
287
289       Copyright 2020-2022 The OpenSSL Project Authors. All Rights Reserved.
290
291       Licensed under the Apache License 2.0 (the "License").  You may not use
292       this file except in compliance with the License.  You can obtain a copy
293       in the file LICENSE in the source distribution or at
294       <https://www.openssl.org/source/license.html>.
295
296
297
2983.0.9                             2023-07-27               PROVIDER-KDF(7ossl)
Impressum