c4cb021185803080c9c4f41bc7b35266d755052a
[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_ctx_params(void *ctx, const OSSL_PARAM params[]);
33  const OSSL_PARAM *OP_keyexch_settable_ctx_params(void);
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_ctx_params        OSSL_FUNC_KEYEXCH_SET_CTX_PARAMS
73  OP_keyexch_settable_ctx_params   OSSL_FUNC_KEYEXCH_SETTABLE_CTX_PARAMS
74
75 A key exchange algorithm implementation may not implement all of these functions.
76 In order to be a consistent set of functions a provider must implement
77 OP_keyexch_newctx, OP_keyexch_freectx, OP_keyexch_init and OP_keyexch_derive.
78 All other functions are optional.
79
80 A key exchange algorithm must also implement some mechanism for generating,
81 loading or importing keys via the key management (OSSL_OP_KEYMGMT) operation.
82 See L<provider-keymgmt(7)> for further details.
83
84 =head2 Context Management Functions
85
86 OP_keyexch_newctx() should create and return a pointer to a provider side
87 structure for holding context information during a key exchange operation.
88 A pointer to this context will be passed back in a number of the other key
89 exchange operation function calls.
90 The paramater I<provctx> is the provider context generated during provider
91 initialisation (see L<provider(3)>).
92
93 OP_keyexch_freectx() is passed a pointer to the provider side key exchange
94 context in the I<ctx> parameter.
95 This function should free any resources associated with that context.
96
97 OP_keyexch_dupctx() should duplicate the provider side key exchange context in
98 the I<ctx> parameter and return the duplicate copy.
99
100 =head2 Shared Secret Derivation Functions
101
102 OP_keyexch_init() initialises a key exchange operation given a provider side key
103 exchange context in the I<ctx> paramter, and a pointer to a provider key object
104 in the I<provkey> parameter. The key object should have been previously
105 generated, loaded or imported into the provider using the key management
106 (OSSL_OP_KEYMGMT) operation (see provider-keymgmt(7)>.
107
108 OP_keyexch_set_peer() is called to supply the peer's public key (in the
109 I<provkey> parameter) to be used when deriving the shared secret.
110 It is also passed a previously initialised key exchange context in the I<ctx>
111 parameter.
112 The key object should have been previously generated, loaded or imported into
113 the provider using the key management (OSSL_OP_KEYMGMT) operation (see
114 provider-keymgmt(7)>.
115
116 OP_keyexch_derive() performs the actual key exchange itself by deriving a shared
117 secret.
118 A previously initialised key exchange context is passed in the I<ctx>
119 parameter.
120 The derived secret should be written to the location I<secret> which should not
121 exceed I<outlen> bytes.
122 The length of the shared secret should be written to I<*secretlen>.
123 If I<secret> is NULL then the maximum length of the shared secret should be
124 written to I<*secretlen>.
125
126 =head2 Key Exchange Parameters
127
128 See L<OSSL_PARAM(3)> for further details on the parameters structure used by
129 the OP_keyexch_set_params() function.
130
131 OP_keyexch_set_ctx_params() sets key exchange parameters associated with the
132 given provider side key exchange context I<ctx> to I<params>.
133 Any parameter settings are additional to any that were previously set.
134
135 Parameters currently recognised by built-in key exchange algorithms are as
136 follows.
137 Not all parameters are relevant to, or are understood by all key exchange
138 algorithms:
139
140 =over 4
141
142 =item "pad" (B<OSSL_EXCHANGE_PARAM_PAD>) <unsigned integer>
143
144 Sets the padding mode for the associated key exchange ctx.
145 Setting a value of 1 will turn padding on.
146 Setting a vlue of 0 will turn padding off.
147 If padding is off then the derived shared secret may be smaller than the largest
148 possible secret size.
149 If padding is on then the derived shared secret will have its first bytes filled
150 with 0s where necessary to make the shared secret the same size as the largest
151 possible secret size.
152
153 =back
154
155 OP_keyexch_settable_ctx_params() gets a constant B<OSSL_PARAM> array that
156 decribes the settable parameters, i.e. parameters that can be used with
157 OP_signature_set_ctx_params().
158 See L<OSSL_PARAM(3)> for the use of B<OSSL_PARAM> as parameter descriptor.
159
160 =head1 RETURN VALUES
161
162 OP_keyexch_newctx() and OP_keyexch_dupctx() should return the newly created
163 provider side key exchange context, or NULL on failure.
164
165 OP_keyexch_init(), OP_keyexch_set_peer(), OP_keyexch_derive() and
166 OP_keyexch_set_params() should return 1 for success or 0 on error.
167
168 =head1 SEE ALSO
169
170 L<provider(7)>
171
172 =head1 HISTORY
173
174 The provider KEYEXCH interface was introduced in OpenSSL 3.0.
175
176 =head1 COPYRIGHT
177
178 Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
179
180 Licensed under the Apache License 2.0 (the "License").  You may not use
181 this file except in compliance with the License.  You can obtain a copy
182 in the file LICENSE in the source distribution or at
183 L<https://www.openssl.org/source/license.html>.
184
185 =cut