]> git.ipfire.org Git - thirdparty/openssl.git/blob - doc/man7/provider-kem.pod
Fix windows builds
[thirdparty/openssl.git] / doc / man7 / provider-kem.pod
1 =pod
2
3 =head1 NAME
4
5 provider-kem - The kem 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 *OSSL_FUNC_kem_newctx(void *provctx);
22 void OSSL_FUNC_kem_freectx(void *ctx);
23 void *OSSL_FUNC_kem_dupctx(void *ctx);
24
25 /* Encapsulation */
26 int OSSL_FUNC_kem_encapsulate_init(void *ctx, void *provkey,
27 const OSSL_PARAM params[]);
28 int OSSL_FUNC_kem_auth_encapsulate_init(void *ctx, void *provkey,
29 void *provauthkey,
30 const OSSL_PARAM params[]);
31 int OSSL_FUNC_kem_encapsulate(void *ctx, unsigned char *out, size_t *outlen,
32 unsigned char *secret, size_t *secretlen);
33
34 /* Decapsulation */
35 int OSSL_FUNC_kem_decapsulate_init(void *ctx, void *provkey);
36 int OSSL_FUNC_kem_auth_decapsulate_init(void *ctx, void *provkey,
37 void *provauthkey,
38 const OSSL_PARAM params[]);
39 int OSSL_FUNC_kem_decapsulate(void *ctx, unsigned char *out, size_t *outlen,
40 const unsigned char *in, size_t inlen);
41
42 /* KEM parameters */
43 int OSSL_FUNC_kem_get_ctx_params(void *ctx, OSSL_PARAM params[]);
44 const OSSL_PARAM *OSSL_FUNC_kem_gettable_ctx_params(void *ctx, void *provctx);
45 int OSSL_FUNC_kem_set_ctx_params(void *ctx, const OSSL_PARAM params[]);
46 const OSSL_PARAM *OSSL_FUNC_kem_settable_ctx_params(void *ctx, void *provctx);
47
48 =head1 DESCRIPTION
49
50 This documentation is primarily aimed at provider authors. See L<provider(7)>
51 for further information.
52
53 The asymmetric kem (OSSL_OP_KEM) operation enables providers to
54 implement asymmetric kem algorithms and make them available to applications
55 via the API functions L<EVP_PKEY_encapsulate(3)>,
56 L<EVP_PKEY_decapsulate(3)> and other related functions.
57
58 All "functions" mentioned here are passed as function pointers between
59 F<libcrypto> and the provider in L<OSSL_DISPATCH(3)> arrays via
60 L<OSSL_ALGORITHM(3)> arrays that are returned by the provider's
61 provider_query_operation() function
62 (see L<provider-base(7)/Provider Functions>).
63
64 All these "functions" have a corresponding function type definition
65 named B<OSSL_FUNC_{name}_fn>, and a helper function to retrieve the
66 function pointer from an L<OSSL_DISPATCH(3)> element named
67 B<OSSL_FUNC_{name}>.
68 For example, the "function" OSSL_FUNC_kem_newctx() has these:
69
70 typedef void *(OSSL_FUNC_kem_newctx_fn)(void *provctx);
71 static ossl_inline OSSL_FUNC_kem_newctx_fn
72 OSSL_FUNC_kem_newctx(const OSSL_DISPATCH *opf);
73
74 L<OSSL_DISPATCH(3)> arrays are indexed by numbers that are provided as
75 macros in L<openssl-core_dispatch.h(7)>, as follows:
76
77 OSSL_FUNC_kem_newctx OSSL_FUNC_KEM_NEWCTX
78 OSSL_FUNC_kem_freectx OSSL_FUNC_KEM_FREECTX
79 OSSL_FUNC_kem_dupctx OSSL_FUNC_KEM_DUPCTX
80
81 OSSL_FUNC_kem_encapsulate_init OSSL_FUNC_KEM_ENCAPSULATE_INIT
82 OSSL_FUNC_kem_auth_encapsulate_init OSSL_FUNC_KEM_AUTH_ENCAPSULATE_INIT
83 OSSL_FUNC_kem_encapsulate OSSL_FUNC_KEM_ENCAPSULATE
84
85 OSSL_FUNC_kem_decapsulate_init OSSL_FUNC_KEM_DECAPSULATE_INIT
86 OSSL_FUNC_kem_auth_decapsulate_init OSSL_FUNC_KEM_AUTH_DECAPSULATE_INIT
87 OSSL_FUNC_kem_decapsulate OSSL_FUNC_KEM_DECAPSULATE
88
89 OSSL_FUNC_kem_get_ctx_params OSSL_FUNC_KEM_GET_CTX_PARAMS
90 OSSL_FUNC_kem_gettable_ctx_params OSSL_FUNC_KEM_GETTABLE_CTX_PARAMS
91 OSSL_FUNC_kem_set_ctx_params OSSL_FUNC_KEM_SET_CTX_PARAMS
92 OSSL_FUNC_kem_settable_ctx_params OSSL_FUNC_KEM_SETTABLE_CTX_PARAMS
93
94 An asymmetric kem algorithm implementation may not implement all of these
95 functions.
96 In order to be a consistent set of functions a provider must implement
97 OSSL_FUNC_kem_newctx and OSSL_FUNC_kem_freectx.
98 It must also implement both of OSSL_FUNC_kem_encapsulate_init and
99 OSSL_FUNC_kem_encapsulate, or both of OSSL_FUNC_kem_decapsulate_init and
100 OSSL_FUNC_kem_decapsulate.
101 OSSL_FUNC_kem_auth_encapsulate_init is optional but if it is present then so
102 must OSSL_FUNC_kem_auth_decapsulate_init.
103 OSSL_FUNC_kem_get_ctx_params is optional but if it is present then so must
104 OSSL_FUNC_kem_gettable_ctx_params.
105 Similarly, OSSL_FUNC_kem_set_ctx_params is optional but if it is present then
106 OSSL_FUNC_kem_settable_ctx_params must also be present.
107
108 An asymmetric kem algorithm must also implement some mechanism for generating,
109 loading or importing keys via the key management (OSSL_OP_KEYMGMT) operation.
110 See L<provider-keymgmt(7)> for further details.
111
112 =head2 Context Management Functions
113
114 OSSL_FUNC_kem_newctx() should create and return a pointer to a provider side
115 structure for holding context information during an asymmetric kem operation.
116 A pointer to this context will be passed back in a number of the other
117 asymmetric kem operation function calls.
118 The parameter I<provctx> is the provider context generated during provider
119 initialisation (see L<provider(7)>).
120
121 OSSL_FUNC_kem_freectx() is passed a pointer to the provider side asymmetric
122 kem context in the I<ctx> parameter.
123 This function should free any resources associated with that context.
124
125 OSSL_FUNC_kem_dupctx() should duplicate the provider side asymmetric kem
126 context in the I<ctx> parameter and return the duplicate copy.
127
128 =head2 Asymmetric Key Encapsulation Functions
129
130 OSSL_FUNC_kem_encapsulate_init() initialises a context for an asymmetric
131 encapsulation given a provider side asymmetric kem context in the I<ctx>
132 parameter, a pointer to a provider key object in the I<provkey> parameter and
133 the I<name> of the algorithm.
134 The I<params>, if not NULL, should be set on the context in a manner similar to
135 using OSSL_FUNC_kem_set_ctx_params().
136 The key object should have been previously generated, loaded or imported into
137 the provider using the key management (OSSL_OP_KEYMGMT) operation (see
138 provider-keymgmt(7)>.
139
140 OSSL_FUNC_kem_auth_encapsulate_init() is similiar to
141 OSSL_FUNC_kem_encapsulate_init(), but also passes an additional authentication
142 key I<provauthkey> which cannot be NULL.
143
144 OSSL_FUNC_kem_encapsulate() performs the actual encapsulation itself.
145 A previously initialised asymmetric kem context is passed in the I<ctx>
146 parameter.
147 Unless I<out> is NULL, the data to be encapsulated is internally generated,
148 and returned into the buffer pointed to by the I<secret> parameter and the
149 encapsulated data should also be written to the location pointed to by the
150 I<out> parameter. The length of the encapsulated data should be written to
151 I<*outlen> and the length of the generated secret should be written to
152 I<*secretlen>.
153
154 If I<out> is NULL then the maximum length of the encapsulated data should be
155 written to I<*outlen>, and the maximum length of the generated secret should be
156 written to I<*secretlen>.
157
158 =head2 Decapsulation Functions
159
160 OSSL_FUNC_kem_decapsulate_init() initialises a context for an asymmetric
161 decapsulation given a provider side asymmetric kem context in the I<ctx>
162 parameter, a pointer to a provider key object in the I<provkey> parameter, and
163 a I<name> of the algorithm.
164 The key object should have been previously generated, loaded or imported into
165 the provider using the key management (OSSL_OP_KEYMGMT) operation (see
166 provider-keymgmt(7)>.
167
168 OSSL_FUNC_kem_auth_decapsulate_init() is similiar to
169 OSSL_FUNC_kem_decapsulate_init(), but also passes an additional authentication
170 key I<provauthkey> which cannot be NULL.
171
172 OSSL_FUNC_kem_decapsulate() performs the actual decapsulation itself.
173 A previously initialised asymmetric kem context is passed in the I<ctx>
174 parameter.
175 The data to be decapsulated is pointed to by the I<in> parameter which is I<inlen>
176 bytes long.
177 Unless I<out> is NULL, the decapsulated data should be written to the location
178 pointed to by the I<out> parameter.
179 The length of the decapsulated data should be written to I<*outlen>.
180 If I<out> is NULL then the maximum length of the decapsulated data should be
181 written to I<*outlen>.
182
183 =head2 Asymmetric Key Encapsulation Parameters
184
185 See L<OSSL_PARAM(3)> for further details on the parameters structure used by
186 the OSSL_FUNC_kem_get_ctx_params() and OSSL_FUNC_kem_set_ctx_params()
187 functions.
188
189 OSSL_FUNC_kem_get_ctx_params() gets asymmetric kem parameters associated
190 with the given provider side asymmetric kem context I<ctx> and stores them in
191 I<params>.
192 Passing NULL for I<params> should return true.
193
194 OSSL_FUNC_kem_set_ctx_params() sets the asymmetric kem parameters associated
195 with the given provider side asymmetric kem context I<ctx> to I<params>.
196 Any parameter settings are additional to any that were previously set.
197 Passing NULL for I<params> should return true.
198
199 No parameters are currently recognised by built-in asymmetric kem algorithms.
200
201 OSSL_FUNC_kem_gettable_ctx_params() and OSSL_FUNC_kem_settable_ctx_params()
202 get a constant L<OSSL_PARAM(3)> array that describes the gettable and settable
203 parameters, i.e. parameters that can be used with OSSL_FUNC_kem_get_ctx_params()
204 and OSSL_FUNC_kem_set_ctx_params() respectively.
205
206 =head1 RETURN VALUES
207
208 OSSL_FUNC_kem_newctx() and OSSL_FUNC_kem_dupctx() should return the newly
209 created provider side asymmetric kem context, or NULL on failure.
210
211 All other functions should return 1 for success or 0 on error.
212
213 =head1 SEE ALSO
214
215 L<provider(7)>
216
217 =head1 HISTORY
218
219 The provider KEM interface was introduced in OpenSSL 3.0.
220
221 OSSL_FUNC_kem_auth_encapsulate_init() and OSSL_FUNC_kem_auth_decapsulate_init()
222 were added in OpenSSL 3.2.
223
224 =head1 COPYRIGHT
225
226 Copyright 2020-2022 The OpenSSL Project Authors. All Rights Reserved.
227
228 Licensed under the Apache License 2.0 (the "License"). You may not use
229 this file except in compliance with the License. You can obtain a copy
230 in the file LICENSE in the source distribution or at
231 L<https://www.openssl.org/source/license.html>.
232
233 =cut