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