Rename the hash implementations KMAC{128,256} to KECCAK_KMAC{128,256}
[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 comment multiple includes
10
11  #include <openssl/core_numbers.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_params(void *ctx, const OSSL_PARAM params[]);
33
34
35 =head1 DESCRIPTION
36
37 This documentation is primarily aimed at provider authors. See L<provider(7)>
38 for further information.
39
40 The key exchange (OSSL_OP_KEYEXCH) operation enables providers to implement key
41 exchange algorithms and make them available to applications via the API
42 functions L<EVP_PKEY_derive_init_ex(3)>, and L<EVP_PKEY_derive(3)> (as well as
43 other related functions).
44
45 All "functions" mentioned here are passed as function pointers between
46 F<libcrypto> and the provider in B<OSSL_DISPATCH> arrays via
47 B<OSSL_ALGORITHM> arrays that are returned by the provider's
48 provider_query_operation() function
49 (see L<provider-base(7)/Provider Functions>).
50
51 All these "functions" have a corresponding function type definition
52 named B<OSSL_{name}_fn>, and a helper function to retrieve the
53 function pointer from an B<OSSL_DISPATCH> element named
54 B<OSSL_get_{name}>.
55 For example, the "function" OP_keyexch_newctx() has these:
56
57  typedef void *(OSSL_OP_keyexch_newctx_fn)(void *provctx);
58  static ossl_inline OSSL_OP_keyexch_newctx_fn
59      OSSL_get_OP_keyexch_newctx(const OSSL_DISPATCH *opf);
60
61 B<OSSL_DISPATCH> arrays are indexed by numbers that are provided as
62 macros in L<openssl-core_numbers.h(7)>, as follows:
63
64  OP_keyexch_newctx           OSSL_FUNC_KEYEXCH_NEWCTX
65  OP_keyexch_freectx          OSSL_FUNC_KEYEXCH_FREECTX
66  OP_keyexch_dupctx           OSSL_FUNC_KEYEXCH_DUPCTX
67
68  OP_keyexch_init             OSSL_FUNC_KEYEXCH_INIT
69  OP_keyexch_set_peer         OSSL_FUNC_KEYEXCH_SET_PEER
70  OP_keyexch_derive           OSSL_FUNC_KEYEXCH_DERIVE
71
72  OP_keyexch_set_params       OSSL_FUNC_KEYEXCH_SET_PARAMS
73
74 A key exchange algorithm implementation may not implement all of these functions.
75 In order to be a consistent set of functions a provider must implement
76 OP_keyexch_newctx, OP_keyexch_freectx, OP_keyexch_init and OP_keyexch_derive.
77 All other functions are optional.
78
79 A key exchange algorithm must also implement some mechanism for generating,
80 loading or importing keys via the key management (OSSL_OP_KEYMGMT) operation.
81 See L<provider-keymgmt(7)> for further details.
82
83 =head2 Context Management Functions
84
85 OP_keyexch_newctx() should create and return a pointer to a provider side
86 structure for holding context information during a key exchange operation.
87 A pointer to this context will be passed back in a number of the other key
88 exchange operation function calls.
89 The paramater B<provctx> is the provider context generated during provider
90 initialisation (see L<provider(3)>).
91
92 OP_keyexch_freectx() is passed a pointer to the provider side key exchange
93 context in the B<ctx> parameter.
94 This function should free any resources associated with that context.
95
96 OP_keyexch_dupctx() should duplicate the provider side key exchange context in
97 the B<ctx> parameter and return the duplicate copy.
98
99 =head2 Shared Secret Derivation Functions
100
101 OP_keyexch_init() initialises a key exchange operation given a provider side key
102 exchange context in the B<ctx> paramter, and a pointer to a provider key object
103 in the B<provkey> parameter. The key object should have been previously
104 generated, loaded or imported into the provider using the key management
105 (OSSL_OP_KEYMGMT) operation (see provider-keymgmt(7)>.
106
107 OP_keyexch_set_peer() is called to supply the peer's public key (in the
108 B<provkey> parameter) to be used when deriving the shared secret.
109 It is also passed a previously initialised key exchange context in the B<ctx>
110 parameter.
111 The key object should have been previously generated, loaded or imported into
112 the provider using the key management (OSSL_OP_KEYMGMT) operation (see
113 provider-keymgmt(7)>.
114
115 OP_keyexch_derive() performs the actual key exchange itself by deriving a shared
116 secret.
117 A previously initialised key exchange context is passed in the B<ctx>
118 parameter.
119 The derived secret should be written to the location B<secret> which should not
120 exceed B<outlen> bytes.
121 The length of the shared secret should be written to B<*secretlen>.
122 If B<secret> is NULL then the maximum length of the shared secret should be
123 written to B<*secretlen>.
124
125 =head2 Key Exchange Parameters
126
127 See L<OSSL_PARAM(3)> for further details on the parameters structure used by
128 the OP_keyexch_set_params() function.
129
130 OP_keyexch_set_params() sets key exchange parameters associated with the given
131 provider side key exchange context B<ctx> to B<params>.
132 Any parameter settings are additional to any that were previously set.
133
134 Parameters currently recognised by built-in key exchange algorithms are as
135 follows.
136 Not all parameters are relevant to, or are understood by all key exchange
137 algorithms:
138
139 =over 4
140
141 =item B<OSSL_EXCHANGE_PARAM_PAD> (int)
142
143 Sets the padding mode for the associated key exchange ctx.
144 Setting a value of 1 will turn padding on.
145 Setting a vlue of 0 will turn padding off.
146 If padding is off then the derived shared secret may be smaller than the largest
147 possible secret size.
148 If padding is on then the derived shared secret will have its first bytes filled
149 with 0s where necessary to make the shared secret the same size as the largest
150 possible secret size.
151
152 =back
153
154 =head1 RETURN VALUES
155
156 OP_keyexch_newctx() and OP_keyexch_dupctx() should return the newly created
157 provider side key exchange context, or NULL on failure.
158
159 OP_keyexch_init(), OP_keyexch_set_peer(), OP_keyexch_derive() and
160 OP_keyexch_set_params() should return 1 for success or 0 on error.
161
162 =head1 SEE ALSO
163
164 L<provider(7)>
165
166 =head1 HISTORY
167
168 The provider KEYEXCH interface was introduced in OpenSSL 3.0.
169
170 =head1 COPYRIGHT
171
172 Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
173
174 Licensed under the Apache License 2.0 (the "License").  You may not use
175 this file except in compliance with the License.  You can obtain a copy
176 in the file LICENSE in the source distribution or at
177 L<https://www.openssl.org/source/license.html>.
178
179 =cut