5 provider-keyexch - The keyexch library E<lt>-E<gt> provider functions
9 =for openssl multiple includes
11 #include <openssl/core_numbers.h>
12 #include <openssl/core_names.h>
15 * None of these are actual functions, but are displayed like this for
16 * the function signatures for functions that are offered as function
17 * pointers in OSSL_DISPATCH arrays.
20 /* Context management */
21 void *OP_keyexch_newctx(void *provctx);
22 void OP_keyexch_freectx(void *ctx);
23 void *OP_keyexch_dupctx(void *ctx);
25 /* Shared secret derivation */
26 int OP_keyexch_init(void *ctx, void *provkey);
27 int OP_keyexch_set_peer(void *ctx, void *provkey);
28 int OP_keyexch_derive(void *ctx, unsigned char *secret, size_t *secretlen,
31 /* Key Exchange parameters */
32 int OP_keyexch_set_ctx_params(void *ctx, const OSSL_PARAM params[]);
33 const OSSL_PARAM *OP_keyexch_settable_ctx_params(void);
34 int OP_keyexch_get_ctx_params(void *ctx, OSSL_PARAM params[]);
35 const OSSL_PARAM *OP_keyexch_gettable_ctx_params(void);
39 This documentation is primarily aimed at provider authors. See L<provider(7)>
40 for further information.
42 The key exchange (OSSL_OP_KEYEXCH) operation enables providers to implement key
43 exchange algorithms and make them available to applications via
44 L<EVP_PKEY_derive(3)> and
45 other related functions).
47 All "functions" mentioned here are passed as function pointers between
48 F<libcrypto> and the provider in B<OSSL_DISPATCH> arrays via
49 B<OSSL_ALGORITHM> arrays that are returned by the provider's
50 provider_query_operation() function
51 (see L<provider-base(7)/Provider Functions>).
53 All these "functions" have a corresponding function type definition
54 named B<OSSL_{name}_fn>, and a helper function to retrieve the
55 function pointer from an B<OSSL_DISPATCH> element named
57 For example, the "function" OP_keyexch_newctx() has these:
59 typedef void *(OSSL_OP_keyexch_newctx_fn)(void *provctx);
60 static ossl_inline OSSL_OP_keyexch_newctx_fn
61 OSSL_get_OP_keyexch_newctx(const OSSL_DISPATCH *opf);
63 B<OSSL_DISPATCH> arrays are indexed by numbers that are provided as
64 macros in L<openssl-core_numbers.h(7)>, as follows:
66 OP_keyexch_newctx OSSL_FUNC_KEYEXCH_NEWCTX
67 OP_keyexch_freectx OSSL_FUNC_KEYEXCH_FREECTX
68 OP_keyexch_dupctx OSSL_FUNC_KEYEXCH_DUPCTX
70 OP_keyexch_init OSSL_FUNC_KEYEXCH_INIT
71 OP_keyexch_set_peer OSSL_FUNC_KEYEXCH_SET_PEER
72 OP_keyexch_derive OSSL_FUNC_KEYEXCH_DERIVE
74 OP_keyexch_set_ctx_params OSSL_FUNC_KEYEXCH_SET_CTX_PARAMS
75 OP_keyexch_settable_ctx_params OSSL_FUNC_KEYEXCH_SETTABLE_CTX_PARAMS
76 OP_keyexch_get_ctx_params OSSL_FUNC_KEYEXCH_GET_CTX_PARAMS
77 OP_keyexch_gettable_ctx_params OSSL_FUNC_KEYEXCH_GETTABLE_CTX_PARAMS
79 A key exchange algorithm implementation may not implement all of these functions.
80 In order to be a consistent set of functions a provider must implement
81 OP_keyexch_newctx, OP_keyexch_freectx, OP_keyexch_init and OP_keyexch_derive.
82 All other functions are optional.
84 A key exchange algorithm must also implement some mechanism for generating,
85 loading or importing keys via the key management (OSSL_OP_KEYMGMT) operation.
86 See L<provider-keymgmt(7)> for further details.
88 =head2 Context Management Functions
90 OP_keyexch_newctx() should create and return a pointer to a provider side
91 structure for holding context information during a key exchange operation.
92 A pointer to this context will be passed back in a number of the other key
93 exchange operation function calls.
94 The parameter I<provctx> is the provider context generated during provider
95 initialisation (see L<provider(7)>).
97 OP_keyexch_freectx() is passed a pointer to the provider side key exchange
98 context in the I<ctx> parameter.
99 This function should free any resources associated with that context.
101 OP_keyexch_dupctx() should duplicate the provider side key exchange context in
102 the I<ctx> parameter and return the duplicate copy.
104 =head2 Shared Secret Derivation Functions
106 OP_keyexch_init() initialises a key exchange operation given a provider side key
107 exchange context in the I<ctx> parameter, and a pointer to a provider key object
108 in the I<provkey> parameter. The key object should have been previously
109 generated, loaded or imported into the provider using the key management
110 (OSSL_OP_KEYMGMT) operation (see provider-keymgmt(7)>.
112 OP_keyexch_set_peer() is called to supply the peer's public key (in the
113 I<provkey> parameter) to be used when deriving the shared secret.
114 It is also passed a previously initialised key exchange context in the I<ctx>
116 The key object should have been previously generated, loaded or imported into
117 the provider using the key management (OSSL_OP_KEYMGMT) operation (see
118 provider-keymgmt(7)>.
120 OP_keyexch_derive() performs the actual key exchange itself by deriving a shared
122 A previously initialised key exchange context is passed in the I<ctx>
124 The derived secret should be written to the location I<secret> which should not
125 exceed I<outlen> bytes.
126 The length of the shared secret should be written to I<*secretlen>.
127 If I<secret> is NULL then the maximum length of the shared secret should be
128 written to I<*secretlen>.
130 =head2 Key Exchange Parameters Functions
132 OP_keyexch_set_ctx_params() sets key exchange parameters associated with the
133 given provider side key exchange context I<ctx> to I<params>,
134 see L</Key Exchange Parameters>.
135 Any parameter settings are additional to any that were previously set.
137 OP_keyexch_get_ctx_params() gets key exchange parameters associated with the
138 given provider side key exchange context I<ctx> into I<params>,
139 see L</Key Exchange Parameters>.
141 OP_keyexch_settable_ctx_params() yields a constant B<OSSL_PARAM> array that
142 describes the settable parameters, i.e. parameters that can be used with
143 OP_signature_set_ctx_params().
144 If OP_keyexch_settable_ctx_params() is present, OP_keyexch_set_ctx_params() must
145 also be present, and vice versa.
146 Similarly, OP_keyexch_gettable_ctx_params() yields a constant B<OSSL_PARAM>
147 array that describes the gettable parameters, i.e. parameters that can be
148 handled by OP_signature_get_ctx_params().
149 If OP_keyexch_gettable_ctx_params() is present, OP_keyexch_get_ctx_params() must
150 also be present, and vice versa.
151 See L<OSSL_PARAM(3)> for the use of B<OSSL_PARAM> as parameter descriptor.
153 Notice that not all settable parameters are also gettable, and vice versa.
155 =head2 Key Exchange Parameters
157 See L<OSSL_PARAM(3)> for further details on the parameters structure used by
158 the OP_keyexch_set_ctx_params() and OP_keyexch_get_ctx_params() functions.
160 Parameters currently recognised by built-in key exchange algorithms are as
162 Not all parameters are relevant to, or are understood by all key exchange
167 =item "pad" (B<OSSL_EXCHANGE_PARAM_PAD>) <unsigned integer>
169 Sets the padding mode for the associated key exchange ctx.
170 Setting a value of 1 will turn padding on.
171 Setting a vlue of 0 will turn padding off.
172 If padding is off then the derived shared secret may be smaller than the largest
173 possible secret size.
174 If padding is on then the derived shared secret will have its first bytes filled
175 with 0s where necessary to make the shared secret the same size as the largest
176 possible secret size.
178 =item "ecdh-cofactor-mode" (B<OSSL_EXCHANGE_PARAM_EC_ECDH_COFACTOR_MODE>) <integer>
180 Sets/gets the ECDH mode of operation for the associated key exchange ctx.
182 In the context of an Elliptic Curve Diffie-Hellman key exchange, this parameter
183 can be used to select between the plain Diffie-Hellman (DH) or Cofactor
184 Diffie-Hellman (CDH) variants of the key exchange algorithm.
186 When setting, the value should be 1, 0 or -1, respectively forcing cofactor mode
187 on, off, or resetting it to the default for the private key associated with the
188 given key exchange ctx.
190 When getting, the value should be either 1 or 0, respectively signaling if the
191 cofactor mode is on or off.
193 See also L<provider-keymgmt(7)> for the related
194 B<OSSL_PKEY_PARAM_USE_COFACTOR_ECDH> parameter that can be set on a
197 =item "kdf-type" (B<OSSL_EXCHANGE_PARAM_KDF_TYPE>) <utf8_string>
199 Sets/gets the Key Derivation Function type to apply within the associated key
202 =item "kdf-digest" (B<OSSL_EXCHANGE_PARAM_KDF_DIGEST>) <utf8_string>
204 Sets/gets the Digest algorithm to be used as part of the Key Derivation Function
205 associated with the given key exchange ctx.
207 =item "kdf-digest-props" (B<OSSL_EXCHANGE_PARAM_KDF_DIGEST_PROPS>) <utf8_string>
209 Sets properties to be used upon look up of the implementation for the selected
210 Digest algorithm for the Key Derivation Function associated with the given key
213 =item "kdf-outlen" (B<OSSL_EXCHANGE_PARAM_KDF_OUTLEN>) <size_t>
215 Sets/gets the desired size for the output of the chosen Key Derivation Function
216 associated with the given key exchange ctx.
218 =item "kdf-ukm" (B<OSSL_EXCHANGE_PARAM_KDF_UKM>) <octet_string>
220 Sets/gets User Key Material to be used as part of the selected Key Derivation
221 Function associated with the given key exchange ctx.
223 =item "kdf-ukm-len" (B<OSSL_EXCHANGE_PARAM_KDF_UKM_LEN>) <size_t>
225 Sets/gets the size of the User Key Material to be used as part of the selected
226 Key Derivation Function associated with the given key exchange ctx.
232 OP_keyexch_newctx() and OP_keyexch_dupctx() should return the newly created
233 provider side key exchange context, or NULL on failure.
235 OP_keyexch_init(), OP_keyexch_set_peer(), OP_keyexch_derive(),
236 OP_keyexch_set_params(), and OP_keyexch_get_params() should return 1 for success
239 OP_keyexch_settable_ctx_params() and OP_keyexch_gettable_ctx_params() should
240 always return a constant B<OSSL_PARAM> array.
248 The provider KEYEXCH interface was introduced in OpenSSL 3.0.
252 Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
254 Licensed under the Apache License 2.0 (the "License"). You may not use
255 this file except in compliance with the License. You can obtain a copy
256 in the file LICENSE in the source distribution or at
257 L<https://www.openssl.org/source/license.html>.