Rename <openssl/core_numbers.h> -> <openssl/core_dispatch.h>
[oweals/openssl.git] / doc / man7 / provider-keyexch.pod
1 =pod
2
3 =head1 NAME
4
5 provider-keyexch - The keyexch library E<lt>-E<gt> provider functions
6
7 =head1 SYNOPSIS
8
9 =for openssl multiple includes
10
11  #include <openssl/core_dispatch.h>
12  #include <openssl/core_names.h>
13
14  /*
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.
18   */
19
20  /* Context management */
21  void *OP_keyexch_newctx(void *provctx);
22  void OP_keyexch_freectx(void *ctx);
23  void *OP_keyexch_dupctx(void *ctx);
24
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,
29                        size_t outlen);
30
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);
36
37 =head1 DESCRIPTION
38
39 This documentation is primarily aimed at provider authors. See L<provider(7)>
40 for further information.
41
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).
46
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>).
52
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
56 B<OSSL_get_{name}>.
57 For example, the "function" OP_keyexch_newctx() has these:
58
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);
62
63 B<OSSL_DISPATCH> arrays are indexed by numbers that are provided as
64 macros in L<openssl-core_dispatch.h(7)>, as follows:
65
66  OP_keyexch_newctx                OSSL_FUNC_KEYEXCH_NEWCTX
67  OP_keyexch_freectx               OSSL_FUNC_KEYEXCH_FREECTX
68  OP_keyexch_dupctx                OSSL_FUNC_KEYEXCH_DUPCTX
69
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
73
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
78
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.
83
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.
87
88 =head2 Context Management Functions
89
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)>).
96
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.
100
101 OP_keyexch_dupctx() should duplicate the provider side key exchange context in
102 the I<ctx> parameter and return the duplicate copy.
103
104 =head2 Shared Secret Derivation Functions
105
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)>.
111
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>
115 parameter.
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)>.
119
120 OP_keyexch_derive() performs the actual key exchange itself by deriving a shared
121 secret.
122 A previously initialised key exchange context is passed in the I<ctx>
123 parameter.
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>.
129
130 =head2 Key Exchange Parameters Functions
131
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</Common Key Exchange parameters>.
135 Any parameter settings are additional to any that were previously set.
136
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</Common Key Exchange parameters>.
140
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.
152
153 Notice that not all settable parameters are also gettable, and vice versa.
154
155 =head2 Common Key Exchange parameters
156
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.
159
160 Common parameters currently recognised by built-in key exchange algorithms are
161 as follows.
162
163 =over 4
164
165 =item "pad" (B<OSSL_EXCHANGE_PARAM_PAD>) <unsigned integer>
166
167 Sets the padding mode for the associated key exchange ctx.
168 Setting a value of 1 will turn padding on.
169 Setting a value of 0 will turn padding off.
170 If padding is off then the derived shared secret may be smaller than the largest
171 possible secret size.
172 If padding is on then the derived shared secret will have its first bytes filled
173 with 0s where necessary to make the shared secret the same size as the largest
174 possible secret size.
175
176 =back
177
178 =head1 RETURN VALUES
179
180 OP_keyexch_newctx() and OP_keyexch_dupctx() should return the newly created
181 provider side key exchange context, or NULL on failure.
182
183 OP_keyexch_init(), OP_keyexch_set_peer(), OP_keyexch_derive(),
184 OP_keyexch_set_params(), and OP_keyexch_get_params() should return 1 for success
185 or 0 on error.
186
187 OP_keyexch_settable_ctx_params() and OP_keyexch_gettable_ctx_params() should
188 always return a constant B<OSSL_PARAM> array.
189
190 =head1 SEE ALSO
191
192 L<provider(7)>
193
194 =head1 HISTORY
195
196 The provider KEYEXCH interface was introduced in OpenSSL 3.0.
197
198 =head1 COPYRIGHT
199
200 Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
201
202 Licensed under the Apache License 2.0 (the "License").  You may not use
203 this file except in compliance with the License.  You can obtain a copy
204 in the file LICENSE in the source distribution or at
205 L<https://www.openssl.org/source/license.html>.
206
207 =cut