1PROVIDER-KEM(7ossl)                 OpenSSL                PROVIDER-KEM(7ossl)
2
3
4

NAME

6       provider-kem - The kem library <-> provider functions
7

SYNOPSIS

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

DESCRIPTION

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(3) arrays via
51       OSSL_ALGORITHM(3) arrays that are returned by the provider's
52       provider_query_operation() function (see "Provider Functions" in
53       provider-base(7)).
54
55       All these "functions" have a corresponding function type definition
56       named OSSL_FUNC_{name}_fn, and a helper function to retrieve the
57       function pointer from an OSSL_DISPATCH(3) element named
58       OSSL_FUNC_{name}.  For example, the "function" OSSL_FUNC_kem_newctx()
59       has these:
60
61        typedef void *(OSSL_FUNC_kem_newctx_fn)(void *provctx);
62        static ossl_inline OSSL_FUNC_kem_newctx_fn
63            OSSL_FUNC_kem_newctx(const OSSL_DISPATCH *opf);
64
65       OSSL_DISPATCH(3) arrays are indexed by numbers that are provided as
66       macros in openssl-core_dispatch.h(7), as follows:
67
68        OSSL_FUNC_kem_newctx               OSSL_FUNC_KEM_NEWCTX
69        OSSL_FUNC_kem_freectx              OSSL_FUNC_KEM_FREECTX
70        OSSL_FUNC_kem_dupctx               OSSL_FUNC_KEM_DUPCTX
71
72        OSSL_FUNC_kem_encapsulate_init     OSSL_FUNC_KEM_ENCAPSULATE_INIT
73        OSSL_FUNC_kem_encapsulate          OSSL_FUNC_KEM_ENCAPSULATE
74
75        OSSL_FUNC_kem_decapsulate_init     OSSL_FUNC_KEM_DECAPSULATE_INIT
76        OSSL_FUNC_kem_decapsulate          OSSL_FUNC_KEM_DECAPSULATE
77
78        OSSL_FUNC_kem_get_ctx_params       OSSL_FUNC_KEM_GET_CTX_PARAMS
79        OSSL_FUNC_kem_gettable_ctx_params  OSSL_FUNC_KEM_GETTABLE_CTX_PARAMS
80        OSSL_FUNC_kem_set_ctx_params       OSSL_FUNC_KEM_SET_CTX_PARAMS
81        OSSL_FUNC_kem_settable_ctx_params  OSSL_FUNC_KEM_SETTABLE_CTX_PARAMS
82
83       An asymmetric kem algorithm implementation may not implement all of
84       these functions.  In order to be a consistent set of functions a
85       provider must implement OSSL_FUNC_kem_newctx and OSSL_FUNC_kem_freectx.
86       It must also implement both of OSSL_FUNC_kem_encapsulate_init and
87       OSSL_FUNC_kem_encapsulate, or both of OSSL_FUNC_kem_decapsulate_init
88       and OSSL_FUNC_kem_decapsulate.  OSSL_FUNC_kem_get_ctx_params is
89       optional but if it is present then so must
90       OSSL_FUNC_kem_gettable_ctx_params.  Similarly,
91       OSSL_FUNC_kem_set_ctx_params is optional but if it is present then so
92       must OSSL_FUNC_kem_settable_ctx_params.
93
94       An asymmetric kem algorithm must also implement some mechanism for
95       generating, loading or importing keys via the key management
96       (OSSL_OP_KEYMGMT) operation.  See provider-keymgmt(7) for further
97       details.
98
99   Context Management Functions
100       OSSL_FUNC_kem_newctx() should create and return a pointer to a provider
101       side structure for holding context information during an asymmetric kem
102       operation.  A pointer to this context will be passed back in a number
103       of the other asymmetric kem operation function calls.  The parameter
104       provctx is the provider context generated during provider
105       initialisation (see provider(7)).
106
107       OSSL_FUNC_kem_freectx() is passed a pointer to the provider side
108       asymmetric kem context in the ctx parameter.  This function should free
109       any resources associated with that context.
110
111       OSSL_FUNC_kem_dupctx() should duplicate the provider side asymmetric
112       kem context in the ctx parameter and return the duplicate copy.
113
114   Asymmetric Key Encapsulation Functions
115       OSSL_FUNC_kem_encapsulate_init() initialises a context for an
116       asymmetric encapsulation given a provider side asymmetric kem context
117       in the ctx parameter, a pointer to a provider key object in the provkey
118       parameter and the name of the algorithm.  The params, if not NULL,
119       should be set on the context in a manner similar to using
120       OSSL_FUNC_kem_set_ctx_params().  The key object should have been
121       previously generated, loaded or imported into the provider using the
122       key management (OSSL_OP_KEYMGMT) operation (see provider-keymgmt(7)>.
123
124       OSSL_FUNC_kem_encapsulate() performs the actual encapsulation itself.
125       A previously initialised asymmetric kem context is passed in the ctx
126       parameter.  Unless out is NULL, the data to be encapsulated is
127       internally generated, and returned into the buffer pointed to by the
128       secret parameter and the encapsulated data should also be written to
129       the location pointed to by the out parameter. The length of the
130       encapsulated data should be written to *outlen and the length of the
131       generated secret should be written to *secretlen.
132
133       If out is NULL then the maximum length of the encapsulated data should
134       be written to *outlen, and the maximum length of the generated secret
135       should be written to *secretlen.
136
137   Decapsulation Functions
138       OSSL_FUNC_kem_decapsulate_init() initialises a context for an
139       asymmetric decapsulation given a provider side asymmetric kem context
140       in the ctx parameter, a pointer to a provider key object in the provkey
141       parameter, and a name of the algorithm.  The key object should have
142       been previously generated, loaded or imported into the provider using
143       the key management (OSSL_OP_KEYMGMT) operation (see
144       provider-keymgmt(7)>.
145
146       OSSL_FUNC_kem_decapsulate() performs the actual decapsulation itself.
147       A previously initialised asymmetric kem context is passed in the ctx
148       parameter.  The data to be decapsulated is pointed to by the in
149       parameter which is inlen bytes long.  Unless out is NULL, the
150       decapsulated data should be written to the location pointed to by the
151       out parameter.  The length of the decapsulated data should be written
152       to *outlen.  If out is NULL then the maximum length of the decapsulated
153       data should be written to *outlen.
154
155   Asymmetric Key Encapsulation Parameters
156       See OSSL_PARAM(3) for further details on the parameters structure used
157       by the OSSL_FUNC_kem_get_ctx_params() and
158       OSSL_FUNC_kem_set_ctx_params() functions.
159
160       OSSL_FUNC_kem_get_ctx_params() gets asymmetric kem parameters
161       associated with the given provider side asymmetric kem context ctx and
162       stores them in params.  Passing NULL for params should return true.
163
164       OSSL_FUNC_kem_set_ctx_params() sets the asymmetric kem parameters
165       associated with the given provider side asymmetric kem context ctx to
166       params.  Any parameter settings are additional to any that were
167       previously set.  Passing NULL for params should return true.
168
169       No parameters are currently recognised by built-in asymmetric kem
170       algorithms.
171
172       OSSL_FUNC_kem_gettable_ctx_params() and
173       OSSL_FUNC_kem_settable_ctx_params() get a constant OSSL_PARAM(3) array
174       that describes the gettable and settable parameters, i.e. parameters
175       that can be used with OSSL_FUNC_kem_get_ctx_params() and
176       OSSL_FUNC_kem_set_ctx_params() respectively.
177

RETURN VALUES

179       OSSL_FUNC_kem_newctx() and OSSL_FUNC_kem_dupctx() should return the
180       newly created provider side asymmetric kem context, or NULL on failure.
181
182       All other functions should return 1 for success or 0 on error.
183

SEE ALSO

185       provider(7)
186

HISTORY

188       The provider KEM interface was introduced in OpenSSL 3.0.
189
191       Copyright 2020-2022 The OpenSSL Project Authors. All Rights Reserved.
192
193       Licensed under the Apache License 2.0 (the "License").  You may not use
194       this file except in compliance with the License.  You can obtain a copy
195       in the file LICENSE in the source distribution or at
196       <https://www.openssl.org/source/license.html>.
197
198
199
2003.1.1                             2023-08-31               PROVIDER-KEM(7ossl)
Impressum