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

RETURN VALUES

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

NOTES

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

SEE ALSO

281       provider(7), life_cycle-kdf(7), EVP_KDF(3).
282

HISTORY

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