xref: /openssl/include/openssl/core_dispatch.h (revision 4c41aa4b)
1 /*
2  * Copyright 2019-2024 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License 2.0 (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9 
10 #ifndef OPENSSL_CORE_NUMBERS_H
11 # define OPENSSL_CORE_NUMBERS_H
12 # pragma once
13 
14 # include <stdarg.h>
15 # include <openssl/core.h>
16 # include <openssl/indicator.h>
17 
18 # ifdef __cplusplus
19 extern "C" {
20 # endif
21 
22 /*-
23  * Identities
24  * ----------
25  *
26  * All series start with 1, to allow 0 to be an array terminator.
27  * For any FUNC identity, we also provide a function signature typedef
28  * and a static inline function to extract a function pointer from a
29  * OSSL_DISPATCH element in a type safe manner.
30  *
31  * Names:
32  * for any function base name 'foo' (uppercase form 'FOO'), we will have
33  * the following:
34  * - a macro for the identity with the name OSSL_FUNC_'FOO' or derivatives
35  *   thereof (to be specified further down)
36  * - a function signature typedef with the name OSSL_FUNC_'foo'_fn
37  * - a function pointer extractor function with the name OSSL_FUNC_'foo'
38  */
39 
40 /*
41  * Helper macro to create the function signature typedef and the extractor
42  * |type| is the return-type of the function, |name| is the name of the
43  * function to fetch, and |args| is a parenthesized list of parameters
44  * for the function (that is, it is |name|'s function signature).
45  * Note: This is considered a "reserved" internal macro. Applications should
46  * not use this or assume its existence.
47  */
48 #define OSSL_CORE_MAKE_FUNC(type,name,args)                             \
49     typedef type (OSSL_FUNC_##name##_fn)args;                           \
50     static ossl_unused ossl_inline \
51     OSSL_FUNC_##name##_fn *OSSL_FUNC_##name(const OSSL_DISPATCH *opf)   \
52     {                                                                   \
53         return (OSSL_FUNC_##name##_fn *)opf->function;                  \
54     }
55 
56 /*
57  * Core function identities, for the two OSSL_DISPATCH tables being passed
58  * in the OSSL_provider_init call.
59  *
60  * 0 serves as a marker for the end of the OSSL_DISPATCH array, and must
61  * therefore NEVER be used as a function identity.
62  */
63 /* Functions provided by the Core to the provider, reserved numbers 1-1023 */
64 # define OSSL_FUNC_CORE_GETTABLE_PARAMS        1
65 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *,
66                     core_gettable_params,(const OSSL_CORE_HANDLE *prov))
67 # define OSSL_FUNC_CORE_GET_PARAMS             2
68 OSSL_CORE_MAKE_FUNC(int,core_get_params,(const OSSL_CORE_HANDLE *prov,
69                                          OSSL_PARAM params[]))
70 # define OSSL_FUNC_CORE_THREAD_START           3
71 OSSL_CORE_MAKE_FUNC(int,core_thread_start,(const OSSL_CORE_HANDLE *prov,
72                                            OSSL_thread_stop_handler_fn handfn,
73                                            void *arg))
74 # define OSSL_FUNC_CORE_GET_LIBCTX             4
75 OSSL_CORE_MAKE_FUNC(OPENSSL_CORE_CTX *,core_get_libctx,
76                     (const OSSL_CORE_HANDLE *prov))
77 # define OSSL_FUNC_CORE_NEW_ERROR              5
78 OSSL_CORE_MAKE_FUNC(void,core_new_error,(const OSSL_CORE_HANDLE *prov))
79 # define OSSL_FUNC_CORE_SET_ERROR_DEBUG        6
80 OSSL_CORE_MAKE_FUNC(void,core_set_error_debug,
81                     (const OSSL_CORE_HANDLE *prov,
82                      const char *file, int line, const char *func))
83 # define OSSL_FUNC_CORE_VSET_ERROR             7
84 OSSL_CORE_MAKE_FUNC(void,core_vset_error,
85                     (const OSSL_CORE_HANDLE *prov,
86                      uint32_t reason, const char *fmt, va_list args))
87 # define OSSL_FUNC_CORE_SET_ERROR_MARK         8
88 OSSL_CORE_MAKE_FUNC(int, core_set_error_mark, (const OSSL_CORE_HANDLE *prov))
89 # define OSSL_FUNC_CORE_CLEAR_LAST_ERROR_MARK  9
90 OSSL_CORE_MAKE_FUNC(int, core_clear_last_error_mark,
91                     (const OSSL_CORE_HANDLE *prov))
92 # define OSSL_FUNC_CORE_POP_ERROR_TO_MARK     10
93 OSSL_CORE_MAKE_FUNC(int, core_pop_error_to_mark, (const OSSL_CORE_HANDLE *prov))
94 
95 
96 /* Functions to access the OBJ database */
97 
98 #define OSSL_FUNC_CORE_OBJ_ADD_SIGID          11
99 #define OSSL_FUNC_CORE_OBJ_CREATE             12
100 
101 OSSL_CORE_MAKE_FUNC(int, core_obj_add_sigid,
102                     (const OSSL_CORE_HANDLE *prov, const char  *sign_name,
103                      const char *digest_name, const char *pkey_name))
104 OSSL_CORE_MAKE_FUNC(int, core_obj_create,
105                     (const OSSL_CORE_HANDLE *prov, const char *oid,
106                      const char *sn, const char *ln))
107 
108 /* Memory allocation, freeing, clearing. */
109 #define OSSL_FUNC_CRYPTO_MALLOC               20
110 OSSL_CORE_MAKE_FUNC(void *,
111         CRYPTO_malloc, (size_t num, const char *file, int line))
112 #define OSSL_FUNC_CRYPTO_ZALLOC               21
113 OSSL_CORE_MAKE_FUNC(void *,
114         CRYPTO_zalloc, (size_t num, const char *file, int line))
115 #define OSSL_FUNC_CRYPTO_FREE                 22
116 OSSL_CORE_MAKE_FUNC(void,
117         CRYPTO_free, (void *ptr, const char *file, int line))
118 #define OSSL_FUNC_CRYPTO_CLEAR_FREE           23
119 OSSL_CORE_MAKE_FUNC(void,
120         CRYPTO_clear_free, (void *ptr, size_t num, const char *file, int line))
121 #define OSSL_FUNC_CRYPTO_REALLOC              24
122 OSSL_CORE_MAKE_FUNC(void *,
123         CRYPTO_realloc, (void *addr, size_t num, const char *file, int line))
124 #define OSSL_FUNC_CRYPTO_CLEAR_REALLOC        25
125 OSSL_CORE_MAKE_FUNC(void *,
126         CRYPTO_clear_realloc, (void *addr, size_t old_num, size_t num,
127                                const char *file, int line))
128 #define OSSL_FUNC_CRYPTO_SECURE_MALLOC        26
129 OSSL_CORE_MAKE_FUNC(void *,
130         CRYPTO_secure_malloc, (size_t num, const char *file, int line))
131 #define OSSL_FUNC_CRYPTO_SECURE_ZALLOC        27
132 OSSL_CORE_MAKE_FUNC(void *,
133         CRYPTO_secure_zalloc, (size_t num, const char *file, int line))
134 #define OSSL_FUNC_CRYPTO_SECURE_FREE          28
135 OSSL_CORE_MAKE_FUNC(void,
136         CRYPTO_secure_free, (void *ptr, const char *file, int line))
137 #define OSSL_FUNC_CRYPTO_SECURE_CLEAR_FREE    29
138 OSSL_CORE_MAKE_FUNC(void,
139         CRYPTO_secure_clear_free, (void *ptr, size_t num, const char *file,
140                                    int line))
141 #define OSSL_FUNC_CRYPTO_SECURE_ALLOCATED     30
142 OSSL_CORE_MAKE_FUNC(int,
143         CRYPTO_secure_allocated, (const void *ptr))
144 #define OSSL_FUNC_OPENSSL_CLEANSE             31
145 OSSL_CORE_MAKE_FUNC(void,
146         OPENSSL_cleanse, (void *ptr, size_t len))
147 
148 /* Bio functions provided by the core */
149 #define OSSL_FUNC_BIO_NEW_FILE                40
150 #define OSSL_FUNC_BIO_NEW_MEMBUF              41
151 #define OSSL_FUNC_BIO_READ_EX                 42
152 #define OSSL_FUNC_BIO_WRITE_EX                43
153 #define OSSL_FUNC_BIO_UP_REF                  44
154 #define OSSL_FUNC_BIO_FREE                    45
155 #define OSSL_FUNC_BIO_VPRINTF                 46
156 #define OSSL_FUNC_BIO_VSNPRINTF               47
157 #define OSSL_FUNC_BIO_PUTS                    48
158 #define OSSL_FUNC_BIO_GETS                    49
159 #define OSSL_FUNC_BIO_CTRL                    50
160 
161 
162 OSSL_CORE_MAKE_FUNC(OSSL_CORE_BIO *, BIO_new_file, (const char *filename,
163                                                     const char *mode))
164 OSSL_CORE_MAKE_FUNC(OSSL_CORE_BIO *, BIO_new_membuf, (const void *buf, int len))
165 OSSL_CORE_MAKE_FUNC(int, BIO_read_ex, (OSSL_CORE_BIO *bio, void *data,
166                                        size_t data_len, size_t *bytes_read))
167 OSSL_CORE_MAKE_FUNC(int, BIO_write_ex, (OSSL_CORE_BIO *bio, const void *data,
168                                         size_t data_len, size_t *written))
169 OSSL_CORE_MAKE_FUNC(int, BIO_gets, (OSSL_CORE_BIO *bio, char *buf, int size))
170 OSSL_CORE_MAKE_FUNC(int, BIO_puts, (OSSL_CORE_BIO *bio, const char *str))
171 OSSL_CORE_MAKE_FUNC(int, BIO_up_ref, (OSSL_CORE_BIO *bio))
172 OSSL_CORE_MAKE_FUNC(int, BIO_free, (OSSL_CORE_BIO *bio))
173 OSSL_CORE_MAKE_FUNC(int, BIO_vprintf, (OSSL_CORE_BIO *bio, const char *format,
174                                        va_list args))
175 OSSL_CORE_MAKE_FUNC(int, BIO_vsnprintf,
176                    (char *buf, size_t n, const char *fmt, va_list args))
177 OSSL_CORE_MAKE_FUNC(int, BIO_ctrl, (OSSL_CORE_BIO *bio,
178                                     int cmd, long num, void *ptr))
179 
180 /* New seeding functions prototypes with the 101-104 series */
181 #define OSSL_FUNC_CLEANUP_USER_ENTROPY        96
182 #define OSSL_FUNC_CLEANUP_USER_NONCE          97
183 #define OSSL_FUNC_GET_USER_ENTROPY            98
184 #define OSSL_FUNC_GET_USER_NONCE              99
185 
186 #define OSSL_FUNC_INDICATOR_CB                95
187 OSSL_CORE_MAKE_FUNC(void, indicator_cb, (OPENSSL_CORE_CTX *ctx,
188                                          OSSL_INDICATOR_CALLBACK **cb))
189 #define OSSL_FUNC_SELF_TEST_CB               100
190 OSSL_CORE_MAKE_FUNC(void, self_test_cb, (OPENSSL_CORE_CTX *ctx, OSSL_CALLBACK **cb,
191                                          void **cbarg))
192 
193 /* Functions to get seed material from the operating system */
194 #define OSSL_FUNC_GET_ENTROPY                101
195 #define OSSL_FUNC_CLEANUP_ENTROPY            102
196 #define OSSL_FUNC_GET_NONCE                  103
197 #define OSSL_FUNC_CLEANUP_NONCE              104
198 OSSL_CORE_MAKE_FUNC(size_t, get_entropy, (const OSSL_CORE_HANDLE *handle,
199                                           unsigned char **pout, int entropy,
200                                           size_t min_len, size_t max_len))
201 OSSL_CORE_MAKE_FUNC(size_t, get_user_entropy, (const OSSL_CORE_HANDLE *handle,
202                                                unsigned char **pout, int entropy,
203                                                size_t min_len, size_t max_len))
204 OSSL_CORE_MAKE_FUNC(void, cleanup_entropy, (const OSSL_CORE_HANDLE *handle,
205                                             unsigned char *buf, size_t len))
206 OSSL_CORE_MAKE_FUNC(void, cleanup_user_entropy, (const OSSL_CORE_HANDLE *handle,
207                                                  unsigned char *buf, size_t len))
208 OSSL_CORE_MAKE_FUNC(size_t, get_nonce, (const OSSL_CORE_HANDLE *handle,
209                                         unsigned char **pout, size_t min_len,
210                                         size_t max_len, const void *salt,
211                                         size_t salt_len))
212 OSSL_CORE_MAKE_FUNC(size_t, get_user_nonce, (const OSSL_CORE_HANDLE *handle,
213                                              unsigned char **pout, size_t min_len,
214                                              size_t max_len, const void *salt,
215                                              size_t salt_len))
216 OSSL_CORE_MAKE_FUNC(void, cleanup_nonce, (const OSSL_CORE_HANDLE *handle,
217                                           unsigned char *buf, size_t len))
218 OSSL_CORE_MAKE_FUNC(void, cleanup_user_nonce, (const OSSL_CORE_HANDLE *handle,
219                                                unsigned char *buf, size_t len))
220 
221 /* Functions to access the core's providers */
222 #define OSSL_FUNC_PROVIDER_REGISTER_CHILD_CB   105
223 #define OSSL_FUNC_PROVIDER_DEREGISTER_CHILD_CB 106
224 #define OSSL_FUNC_PROVIDER_NAME                107
225 #define OSSL_FUNC_PROVIDER_GET0_PROVIDER_CTX   108
226 #define OSSL_FUNC_PROVIDER_GET0_DISPATCH       109
227 #define OSSL_FUNC_PROVIDER_UP_REF              110
228 #define OSSL_FUNC_PROVIDER_FREE                111
229 
230 OSSL_CORE_MAKE_FUNC(int, provider_register_child_cb,
231                     (const OSSL_CORE_HANDLE *handle,
232                      int (*create_cb)(const OSSL_CORE_HANDLE *provider, void *cbdata),
233                      int (*remove_cb)(const OSSL_CORE_HANDLE *provider, void *cbdata),
234                      int (*global_props_cb)(const char *props, void *cbdata),
235                      void *cbdata))
236 OSSL_CORE_MAKE_FUNC(void, provider_deregister_child_cb,
237                     (const OSSL_CORE_HANDLE *handle))
238 OSSL_CORE_MAKE_FUNC(const char *, provider_name,
239                     (const OSSL_CORE_HANDLE *prov))
240 OSSL_CORE_MAKE_FUNC(void *, provider_get0_provider_ctx,
241                     (const OSSL_CORE_HANDLE *prov))
242 OSSL_CORE_MAKE_FUNC(const OSSL_DISPATCH *, provider_get0_dispatch,
243                     (const OSSL_CORE_HANDLE *prov))
244 OSSL_CORE_MAKE_FUNC(int, provider_up_ref,
245                     (const OSSL_CORE_HANDLE *prov, int activate))
246 OSSL_CORE_MAKE_FUNC(int, provider_free,
247                     (const OSSL_CORE_HANDLE *prov, int deactivate))
248 
249 /* Functions provided by the provider to the Core, reserved numbers 1024-1535 */
250 # define OSSL_FUNC_PROVIDER_TEARDOWN           1024
251 OSSL_CORE_MAKE_FUNC(void,provider_teardown,(void *provctx))
252 # define OSSL_FUNC_PROVIDER_GETTABLE_PARAMS    1025
253 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *,
254                     provider_gettable_params,(void *provctx))
255 # define OSSL_FUNC_PROVIDER_GET_PARAMS         1026
256 OSSL_CORE_MAKE_FUNC(int,provider_get_params,(void *provctx,
257                                              OSSL_PARAM params[]))
258 # define OSSL_FUNC_PROVIDER_QUERY_OPERATION    1027
259 OSSL_CORE_MAKE_FUNC(const OSSL_ALGORITHM *,provider_query_operation,
260                     (void *provctx, int operation_id, int *no_store))
261 # define OSSL_FUNC_PROVIDER_UNQUERY_OPERATION  1028
262 OSSL_CORE_MAKE_FUNC(void, provider_unquery_operation,
263                     (void *provctx, int operation_id, const OSSL_ALGORITHM *))
264 # define OSSL_FUNC_PROVIDER_GET_REASON_STRINGS 1029
265 OSSL_CORE_MAKE_FUNC(const OSSL_ITEM *,provider_get_reason_strings,
266                     (void *provctx))
267 # define OSSL_FUNC_PROVIDER_GET_CAPABILITIES   1030
268 OSSL_CORE_MAKE_FUNC(int, provider_get_capabilities, (void *provctx,
269                     const char *capability, OSSL_CALLBACK *cb, void *arg))
270 # define OSSL_FUNC_PROVIDER_SELF_TEST          1031
271 OSSL_CORE_MAKE_FUNC(int, provider_self_test, (void *provctx))
272 
273 /* Operations */
274 
275 # define OSSL_OP_DIGEST                              1
276 # define OSSL_OP_CIPHER                              2   /* Symmetric Ciphers */
277 # define OSSL_OP_MAC                                 3
278 # define OSSL_OP_KDF                                 4
279 # define OSSL_OP_RAND                                5
280 # define OSSL_OP_KEYMGMT                            10
281 # define OSSL_OP_KEYEXCH                            11
282 # define OSSL_OP_SIGNATURE                          12
283 # define OSSL_OP_ASYM_CIPHER                        13
284 # define OSSL_OP_KEM                                14
285 /* New section for non-EVP operations */
286 # define OSSL_OP_ENCODER                            20
287 # define OSSL_OP_DECODER                            21
288 # define OSSL_OP_STORE                              22
289 /* Highest known operation number */
290 # define OSSL_OP__HIGHEST                           22
291 
292 /* Digests */
293 
294 # define OSSL_FUNC_DIGEST_NEWCTX                     1
295 # define OSSL_FUNC_DIGEST_INIT                       2
296 # define OSSL_FUNC_DIGEST_UPDATE                     3
297 # define OSSL_FUNC_DIGEST_FINAL                      4
298 # define OSSL_FUNC_DIGEST_DIGEST                     5
299 # define OSSL_FUNC_DIGEST_FREECTX                    6
300 # define OSSL_FUNC_DIGEST_DUPCTX                     7
301 # define OSSL_FUNC_DIGEST_GET_PARAMS                 8
302 # define OSSL_FUNC_DIGEST_SET_CTX_PARAMS             9
303 # define OSSL_FUNC_DIGEST_GET_CTX_PARAMS            10
304 # define OSSL_FUNC_DIGEST_GETTABLE_PARAMS           11
305 # define OSSL_FUNC_DIGEST_SETTABLE_CTX_PARAMS       12
306 # define OSSL_FUNC_DIGEST_GETTABLE_CTX_PARAMS       13
307 # define OSSL_FUNC_DIGEST_SQUEEZE                   14
308 # define OSSL_FUNC_DIGEST_COPYCTX                   15
309 
310 OSSL_CORE_MAKE_FUNC(void *, digest_newctx, (void *provctx))
311 OSSL_CORE_MAKE_FUNC(int, digest_init, (void *dctx, const OSSL_PARAM params[]))
312 OSSL_CORE_MAKE_FUNC(int, digest_update,
313                     (void *dctx, const unsigned char *in, size_t inl))
314 OSSL_CORE_MAKE_FUNC(int, digest_final,
315                     (void *dctx,
316                      unsigned char *out, size_t *outl, size_t outsz))
317 OSSL_CORE_MAKE_FUNC(int, digest_squeeze,
318                     (void *dctx,
319                      unsigned char *out, size_t *outl, size_t outsz))
320 OSSL_CORE_MAKE_FUNC(int, digest_digest,
321                     (void *provctx, const unsigned char *in, size_t inl,
322                      unsigned char *out, size_t *outl, size_t outsz))
323 
324 OSSL_CORE_MAKE_FUNC(void, digest_freectx, (void *dctx))
325 OSSL_CORE_MAKE_FUNC(void *, digest_dupctx, (void *dctx))
326 OSSL_CORE_MAKE_FUNC(void, digest_copyctx, (void *outctx, void *inctx))
327 
328 OSSL_CORE_MAKE_FUNC(int, digest_get_params, (OSSL_PARAM params[]))
329 OSSL_CORE_MAKE_FUNC(int, digest_set_ctx_params,
330                     (void *vctx, const OSSL_PARAM params[]))
331 OSSL_CORE_MAKE_FUNC(int, digest_get_ctx_params,
332                     (void *vctx, OSSL_PARAM params[]))
333 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, digest_gettable_params,
334                     (void *provctx))
335 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, digest_settable_ctx_params,
336                     (void *dctx, void *provctx))
337 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, digest_gettable_ctx_params,
338                     (void *dctx, void *provctx))
339 
340 /* Symmetric Ciphers */
341 
342 # define OSSL_FUNC_CIPHER_NEWCTX                     1
343 # define OSSL_FUNC_CIPHER_ENCRYPT_INIT               2
344 # define OSSL_FUNC_CIPHER_DECRYPT_INIT               3
345 # define OSSL_FUNC_CIPHER_UPDATE                     4
346 # define OSSL_FUNC_CIPHER_FINAL                      5
347 # define OSSL_FUNC_CIPHER_CIPHER                     6
348 # define OSSL_FUNC_CIPHER_FREECTX                    7
349 # define OSSL_FUNC_CIPHER_DUPCTX                     8
350 # define OSSL_FUNC_CIPHER_GET_PARAMS                 9
351 # define OSSL_FUNC_CIPHER_GET_CTX_PARAMS            10
352 # define OSSL_FUNC_CIPHER_SET_CTX_PARAMS            11
353 # define OSSL_FUNC_CIPHER_GETTABLE_PARAMS           12
354 # define OSSL_FUNC_CIPHER_GETTABLE_CTX_PARAMS       13
355 # define OSSL_FUNC_CIPHER_SETTABLE_CTX_PARAMS       14
356 
357 OSSL_CORE_MAKE_FUNC(void *, cipher_newctx, (void *provctx))
358 OSSL_CORE_MAKE_FUNC(int, cipher_encrypt_init, (void *cctx,
359                                                   const unsigned char *key,
360                                                   size_t keylen,
361                                                   const unsigned char *iv,
362                                                   size_t ivlen,
363                                                   const OSSL_PARAM params[]))
364 OSSL_CORE_MAKE_FUNC(int, cipher_decrypt_init, (void *cctx,
365                                                   const unsigned char *key,
366                                                   size_t keylen,
367                                                   const unsigned char *iv,
368                                                   size_t ivlen,
369                                                   const OSSL_PARAM params[]))
370 OSSL_CORE_MAKE_FUNC(int, cipher_update,
371                     (void *cctx,
372                      unsigned char *out, size_t *outl, size_t outsize,
373                      const unsigned char *in, size_t inl))
374 OSSL_CORE_MAKE_FUNC(int, cipher_final,
375                     (void *cctx,
376                      unsigned char *out, size_t *outl, size_t outsize))
377 OSSL_CORE_MAKE_FUNC(int, cipher_cipher,
378                     (void *cctx,
379                      unsigned char *out, size_t *outl, size_t outsize,
380                      const unsigned char *in, size_t inl))
381 OSSL_CORE_MAKE_FUNC(void, cipher_freectx, (void *cctx))
382 OSSL_CORE_MAKE_FUNC(void *, cipher_dupctx, (void *cctx))
383 OSSL_CORE_MAKE_FUNC(int, cipher_get_params, (OSSL_PARAM params[]))
384 OSSL_CORE_MAKE_FUNC(int, cipher_get_ctx_params, (void *cctx,
385                                                     OSSL_PARAM params[]))
386 OSSL_CORE_MAKE_FUNC(int, cipher_set_ctx_params, (void *cctx,
387                                                     const OSSL_PARAM params[]))
388 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, cipher_gettable_params,
389                     (void *provctx))
390 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, cipher_settable_ctx_params,
391                     (void *cctx, void *provctx))
392 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, cipher_gettable_ctx_params,
393                     (void *cctx, void *provctx))
394 
395 /* MACs */
396 
397 # define OSSL_FUNC_MAC_NEWCTX                        1
398 # define OSSL_FUNC_MAC_DUPCTX                        2
399 # define OSSL_FUNC_MAC_FREECTX                       3
400 # define OSSL_FUNC_MAC_INIT                          4
401 # define OSSL_FUNC_MAC_UPDATE                        5
402 # define OSSL_FUNC_MAC_FINAL                         6
403 # define OSSL_FUNC_MAC_GET_PARAMS                    7
404 # define OSSL_FUNC_MAC_GET_CTX_PARAMS                8
405 # define OSSL_FUNC_MAC_SET_CTX_PARAMS                9
406 # define OSSL_FUNC_MAC_GETTABLE_PARAMS              10
407 # define OSSL_FUNC_MAC_GETTABLE_CTX_PARAMS          11
408 # define OSSL_FUNC_MAC_SETTABLE_CTX_PARAMS          12
409 
410 OSSL_CORE_MAKE_FUNC(void *, mac_newctx, (void *provctx))
411 OSSL_CORE_MAKE_FUNC(void *, mac_dupctx, (void *src))
412 OSSL_CORE_MAKE_FUNC(void, mac_freectx, (void *mctx))
413 OSSL_CORE_MAKE_FUNC(int, mac_init, (void *mctx, const unsigned char *key,
414                                     size_t keylen, const OSSL_PARAM params[]))
415 OSSL_CORE_MAKE_FUNC(int, mac_update,
416                     (void *mctx, const unsigned char *in, size_t inl))
417 OSSL_CORE_MAKE_FUNC(int, mac_final,
418                     (void *mctx,
419                      unsigned char *out, size_t *outl, size_t outsize))
420 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, mac_gettable_params, (void *provctx))
421 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, mac_gettable_ctx_params,
422                     (void *mctx, void *provctx))
423 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, mac_settable_ctx_params,
424                     (void *mctx, void *provctx))
425 OSSL_CORE_MAKE_FUNC(int, mac_get_params, (OSSL_PARAM params[]))
426 OSSL_CORE_MAKE_FUNC(int, mac_get_ctx_params,
427                     (void *mctx, OSSL_PARAM params[]))
428 OSSL_CORE_MAKE_FUNC(int, mac_set_ctx_params,
429                     (void *mctx, const OSSL_PARAM params[]))
430 
431 /* KDFs and PRFs */
432 
433 # define OSSL_FUNC_KDF_NEWCTX                        1
434 # define OSSL_FUNC_KDF_DUPCTX                        2
435 # define OSSL_FUNC_KDF_FREECTX                       3
436 # define OSSL_FUNC_KDF_RESET                         4
437 # define OSSL_FUNC_KDF_DERIVE                        5
438 # define OSSL_FUNC_KDF_GETTABLE_PARAMS               6
439 # define OSSL_FUNC_KDF_GETTABLE_CTX_PARAMS           7
440 # define OSSL_FUNC_KDF_SETTABLE_CTX_PARAMS           8
441 # define OSSL_FUNC_KDF_GET_PARAMS                    9
442 # define OSSL_FUNC_KDF_GET_CTX_PARAMS               10
443 # define OSSL_FUNC_KDF_SET_CTX_PARAMS               11
444 
445 OSSL_CORE_MAKE_FUNC(void *, kdf_newctx, (void *provctx))
446 OSSL_CORE_MAKE_FUNC(void *, kdf_dupctx, (void *src))
447 OSSL_CORE_MAKE_FUNC(void, kdf_freectx, (void *kctx))
448 OSSL_CORE_MAKE_FUNC(void, kdf_reset, (void *kctx))
449 OSSL_CORE_MAKE_FUNC(int, kdf_derive, (void *kctx, unsigned char *key,
450                                       size_t keylen, const OSSL_PARAM params[]))
451 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, kdf_gettable_params, (void *provctx))
452 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, kdf_gettable_ctx_params,
453                     (void *kctx, void *provctx))
454 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, kdf_settable_ctx_params,
455                     (void *kctx, void *provctx))
456 OSSL_CORE_MAKE_FUNC(int, kdf_get_params, (OSSL_PARAM params[]))
457 OSSL_CORE_MAKE_FUNC(int, kdf_get_ctx_params,
458                     (void *kctx, OSSL_PARAM params[]))
459 OSSL_CORE_MAKE_FUNC(int, kdf_set_ctx_params,
460                     (void *kctx, const OSSL_PARAM params[]))
461 
462 /* RAND */
463 
464 # define OSSL_FUNC_RAND_NEWCTX                        1
465 # define OSSL_FUNC_RAND_FREECTX                       2
466 # define OSSL_FUNC_RAND_INSTANTIATE                   3
467 # define OSSL_FUNC_RAND_UNINSTANTIATE                 4
468 # define OSSL_FUNC_RAND_GENERATE                      5
469 # define OSSL_FUNC_RAND_RESEED                        6
470 # define OSSL_FUNC_RAND_NONCE                         7
471 # define OSSL_FUNC_RAND_ENABLE_LOCKING                8
472 # define OSSL_FUNC_RAND_LOCK                          9
473 # define OSSL_FUNC_RAND_UNLOCK                       10
474 # define OSSL_FUNC_RAND_GETTABLE_PARAMS              11
475 # define OSSL_FUNC_RAND_GETTABLE_CTX_PARAMS          12
476 # define OSSL_FUNC_RAND_SETTABLE_CTX_PARAMS          13
477 # define OSSL_FUNC_RAND_GET_PARAMS                   14
478 # define OSSL_FUNC_RAND_GET_CTX_PARAMS               15
479 # define OSSL_FUNC_RAND_SET_CTX_PARAMS               16
480 # define OSSL_FUNC_RAND_VERIFY_ZEROIZATION           17
481 # define OSSL_FUNC_RAND_GET_SEED                     18
482 # define OSSL_FUNC_RAND_CLEAR_SEED                   19
483 
484 OSSL_CORE_MAKE_FUNC(void *,rand_newctx,
485                     (void *provctx, void *parent,
486                     const OSSL_DISPATCH *parent_calls))
487 OSSL_CORE_MAKE_FUNC(void,rand_freectx, (void *vctx))
488 OSSL_CORE_MAKE_FUNC(int,rand_instantiate,
489                     (void *vdrbg, unsigned int strength,
490                      int prediction_resistance,
491                      const unsigned char *pstr, size_t pstr_len,
492                      const OSSL_PARAM params[]))
493 OSSL_CORE_MAKE_FUNC(int,rand_uninstantiate, (void *vdrbg))
494 OSSL_CORE_MAKE_FUNC(int,rand_generate,
495                     (void *vctx, unsigned char *out, size_t outlen,
496                      unsigned int strength, int prediction_resistance,
497                      const unsigned char *addin, size_t addin_len))
498 OSSL_CORE_MAKE_FUNC(int,rand_reseed,
499                     (void *vctx, int prediction_resistance,
500                      const unsigned char *ent, size_t ent_len,
501                      const unsigned char *addin, size_t addin_len))
502 OSSL_CORE_MAKE_FUNC(size_t,rand_nonce,
503                     (void *vctx, unsigned char *out, unsigned int strength,
504                      size_t min_noncelen, size_t max_noncelen))
505 OSSL_CORE_MAKE_FUNC(int,rand_enable_locking, (void *vctx))
506 OSSL_CORE_MAKE_FUNC(int,rand_lock, (void *vctx))
507 OSSL_CORE_MAKE_FUNC(void,rand_unlock, (void *vctx))
508 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *,rand_gettable_params, (void *provctx))
509 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *,rand_gettable_ctx_params,
510                     (void *vctx, void *provctx))
511 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *,rand_settable_ctx_params,
512                     (void *vctx, void *provctx))
513 OSSL_CORE_MAKE_FUNC(int,rand_get_params, (OSSL_PARAM params[]))
514 OSSL_CORE_MAKE_FUNC(int,rand_get_ctx_params,
515                     (void *vctx, OSSL_PARAM params[]))
516 OSSL_CORE_MAKE_FUNC(int,rand_set_ctx_params,
517                     (void *vctx, const OSSL_PARAM params[]))
518 OSSL_CORE_MAKE_FUNC(void,rand_set_callbacks,
519                     (void *vctx, OSSL_INOUT_CALLBACK *get_entropy,
520                      OSSL_CALLBACK *cleanup_entropy,
521                      OSSL_INOUT_CALLBACK *get_nonce,
522                      OSSL_CALLBACK *cleanup_nonce, void *arg))
523 OSSL_CORE_MAKE_FUNC(int,rand_verify_zeroization,
524                     (void *vctx))
525 OSSL_CORE_MAKE_FUNC(size_t,rand_get_seed,
526                     (void *vctx, unsigned char **buffer,
527                      int entropy, size_t min_len, size_t max_len,
528                      int prediction_resistance,
529                      const unsigned char *adin, size_t adin_len))
530 OSSL_CORE_MAKE_FUNC(void,rand_clear_seed,
531                     (void *vctx, unsigned char *buffer, size_t b_len))
532 
533 /*-
534  * Key management
535  *
536  * The Key Management takes care of provider side key objects, and includes
537  * all current functionality to create them, destroy them, set parameters
538  * and key material, etc, essentially everything that manipulates the keys
539  * themselves and their parameters.
540  *
541  * The key objects are commonly referred to as |keydata|, and it MUST be able
542  * to contain parameters if the key has any, the public key and the private
543  * key.  All parts are optional, but their presence determines what can be
544  * done with the key object in terms of encryption, signature, and so on.
545  * The assumption from libcrypto is that the key object contains any of the
546  * following data combinations:
547  *
548  * - parameters only
549  * - public key only
550  * - public key + private key
551  * - parameters + public key
552  * - parameters + public key + private key
553  *
554  * What "parameters", "public key" and "private key" means in detail is left
555  * to the implementation.  In the case of DH and DSA, they would typically
556  * include domain parameters, while for certain variants of RSA, they would
557  * typically include PSS or OAEP parameters.
558  *
559  * Key objects are created with OSSL_FUNC_keymgmt_new() and destroyed with
560  * OSSL_FUNC_keymgmt_free().  Key objects can have data filled in with
561  * OSSL_FUNC_keymgmt_import().
562  *
563  * Three functions are made available to check what selection of data is
564  * present in a key object: OSSL_FUNC_keymgmt_has_parameters(),
565  * OSSL_FUNC_keymgmt_has_public_key(), and OSSL_FUNC_keymgmt_has_private_key(),
566  */
567 
568 /* Key data subset selection - individual bits */
569 # define OSSL_KEYMGMT_SELECT_PRIVATE_KEY            0x01
570 # define OSSL_KEYMGMT_SELECT_PUBLIC_KEY             0x02
571 # define OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS      0x04
572 # define OSSL_KEYMGMT_SELECT_OTHER_PARAMETERS       0x80
573 
574 /* Key data subset selection - combinations */
575 # define OSSL_KEYMGMT_SELECT_ALL_PARAMETERS     \
576     ( OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS     \
577       | OSSL_KEYMGMT_SELECT_OTHER_PARAMETERS)
578 # define OSSL_KEYMGMT_SELECT_KEYPAIR            \
579     ( OSSL_KEYMGMT_SELECT_PRIVATE_KEY | OSSL_KEYMGMT_SELECT_PUBLIC_KEY )
580 # define OSSL_KEYMGMT_SELECT_ALL                \
581     ( OSSL_KEYMGMT_SELECT_KEYPAIR | OSSL_KEYMGMT_SELECT_ALL_PARAMETERS )
582 
583 # define OSSL_KEYMGMT_VALIDATE_FULL_CHECK              0
584 # define OSSL_KEYMGMT_VALIDATE_QUICK_CHECK             1
585 
586 /* Basic key object creation */
587 # define OSSL_FUNC_KEYMGMT_NEW                         1
588 OSSL_CORE_MAKE_FUNC(void *, keymgmt_new, (void *provctx))
589 
590 /* Generation, a more complex constructor */
591 # define OSSL_FUNC_KEYMGMT_GEN_INIT                    2
592 # define OSSL_FUNC_KEYMGMT_GEN_SET_TEMPLATE            3
593 # define OSSL_FUNC_KEYMGMT_GEN_SET_PARAMS              4
594 # define OSSL_FUNC_KEYMGMT_GEN_SETTABLE_PARAMS         5
595 # define OSSL_FUNC_KEYMGMT_GEN                         6
596 # define OSSL_FUNC_KEYMGMT_GEN_CLEANUP                 7
597 # define OSSL_FUNC_KEYMGMT_GEN_GET_PARAMS              15
598 # define OSSL_FUNC_KEYMGMT_GEN_GETTABLE_PARAMS         16
599 
600 OSSL_CORE_MAKE_FUNC(void *, keymgmt_gen_init,
601                     (void *provctx, int selection, const OSSL_PARAM params[]))
602 OSSL_CORE_MAKE_FUNC(int, keymgmt_gen_set_template,
603                     (void *genctx, void *templ))
604 OSSL_CORE_MAKE_FUNC(int, keymgmt_gen_set_params,
605                     (void *genctx, const OSSL_PARAM params[]))
606 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *,
607                     keymgmt_gen_settable_params,
608                     (void *genctx, void *provctx))
609 OSSL_CORE_MAKE_FUNC(int, keymgmt_gen_get_params,
610                     (void *genctx, OSSL_PARAM params[]))
611 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, keymgmt_gen_gettable_params,
612                     (void *genctx, void *provctx))
613 OSSL_CORE_MAKE_FUNC(void *, keymgmt_gen,
614                     (void *genctx, OSSL_CALLBACK *cb, void *cbarg))
615 OSSL_CORE_MAKE_FUNC(void, keymgmt_gen_cleanup, (void *genctx))
616 
617 /* Key loading by object reference */
618 # define OSSL_FUNC_KEYMGMT_LOAD                        8
619 OSSL_CORE_MAKE_FUNC(void *, keymgmt_load,
620                     (const void *reference, size_t reference_sz))
621 
622 /* Basic key object destruction */
623 # define OSSL_FUNC_KEYMGMT_FREE                       10
624 OSSL_CORE_MAKE_FUNC(void, keymgmt_free, (void *keydata))
625 
626 /* Key object information, with discovery */
627 #define OSSL_FUNC_KEYMGMT_GET_PARAMS                  11
628 #define OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS             12
629 OSSL_CORE_MAKE_FUNC(int, keymgmt_get_params,
630                     (void *keydata, OSSL_PARAM params[]))
631 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, keymgmt_gettable_params,
632                     (void *provctx))
633 
634 #define OSSL_FUNC_KEYMGMT_SET_PARAMS                  13
635 #define OSSL_FUNC_KEYMGMT_SETTABLE_PARAMS             14
636 OSSL_CORE_MAKE_FUNC(int, keymgmt_set_params,
637                     (void *keydata, const OSSL_PARAM params[]))
638 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, keymgmt_settable_params,
639                     (void *provctx))
640 
641 /* Key checks - discovery of supported operations */
642 # define OSSL_FUNC_KEYMGMT_QUERY_OPERATION_NAME       20
643 OSSL_CORE_MAKE_FUNC(const char *, keymgmt_query_operation_name,
644                     (int operation_id))
645 
646 /* Key checks - key data content checks */
647 # define OSSL_FUNC_KEYMGMT_HAS                        21
648 OSSL_CORE_MAKE_FUNC(int, keymgmt_has, (const void *keydata, int selection))
649 
650 /* Key checks - validation */
651 # define OSSL_FUNC_KEYMGMT_VALIDATE                   22
652 OSSL_CORE_MAKE_FUNC(int, keymgmt_validate, (const void *keydata, int selection,
653                                             int checktype))
654 
655 /* Key checks - matching */
656 # define OSSL_FUNC_KEYMGMT_MATCH                      23
657 OSSL_CORE_MAKE_FUNC(int, keymgmt_match,
658                     (const void *keydata1, const void *keydata2,
659                      int selection))
660 
661 /* Import and export functions, with discovery */
662 # define OSSL_FUNC_KEYMGMT_IMPORT                     40
663 # define OSSL_FUNC_KEYMGMT_IMPORT_TYPES               41
664 # define OSSL_FUNC_KEYMGMT_EXPORT                     42
665 # define OSSL_FUNC_KEYMGMT_EXPORT_TYPES               43
666 OSSL_CORE_MAKE_FUNC(int, keymgmt_import,
667                     (void *keydata, int selection, const OSSL_PARAM params[]))
668 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, keymgmt_import_types,
669                     (int selection))
670 OSSL_CORE_MAKE_FUNC(int, keymgmt_export,
671                     (void *keydata, int selection,
672                      OSSL_CALLBACK *param_cb, void *cbarg))
673 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, keymgmt_export_types,
674                     (int selection))
675 
676 /* Dup function, constructor */
677 # define OSSL_FUNC_KEYMGMT_DUP                        44
678 OSSL_CORE_MAKE_FUNC(void *, keymgmt_dup,
679                     (const void *keydata_from, int selection))
680 
681 /* Extended import and export functions */
682 # define OSSL_FUNC_KEYMGMT_IMPORT_TYPES_EX            45
683 # define OSSL_FUNC_KEYMGMT_EXPORT_TYPES_EX            46
684 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, keymgmt_import_types_ex,
685                     (void *provctx, int selection))
686 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, keymgmt_export_types_ex,
687                     (void *provctx, int selection))
688 
689 /* Key Exchange */
690 
691 # define OSSL_FUNC_KEYEXCH_NEWCTX                      1
692 # define OSSL_FUNC_KEYEXCH_INIT                        2
693 # define OSSL_FUNC_KEYEXCH_DERIVE                      3
694 # define OSSL_FUNC_KEYEXCH_SET_PEER                    4
695 # define OSSL_FUNC_KEYEXCH_FREECTX                     5
696 # define OSSL_FUNC_KEYEXCH_DUPCTX                      6
697 # define OSSL_FUNC_KEYEXCH_SET_CTX_PARAMS              7
698 # define OSSL_FUNC_KEYEXCH_SETTABLE_CTX_PARAMS         8
699 # define OSSL_FUNC_KEYEXCH_GET_CTX_PARAMS              9
700 # define OSSL_FUNC_KEYEXCH_GETTABLE_CTX_PARAMS        10
701 
702 OSSL_CORE_MAKE_FUNC(void *, keyexch_newctx, (void *provctx))
703 OSSL_CORE_MAKE_FUNC(int, keyexch_init, (void *ctx, void *provkey,
704                                         const OSSL_PARAM params[]))
705 OSSL_CORE_MAKE_FUNC(int, keyexch_derive, (void *ctx,  unsigned char *secret,
706                                              size_t *secretlen, size_t outlen))
707 OSSL_CORE_MAKE_FUNC(int, keyexch_set_peer, (void *ctx, void *provkey))
708 OSSL_CORE_MAKE_FUNC(void, keyexch_freectx, (void *ctx))
709 OSSL_CORE_MAKE_FUNC(void *, keyexch_dupctx, (void *ctx))
710 OSSL_CORE_MAKE_FUNC(int, keyexch_set_ctx_params, (void *ctx,
711                                                      const OSSL_PARAM params[]))
712 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, keyexch_settable_ctx_params,
713                     (void *ctx, void *provctx))
714 OSSL_CORE_MAKE_FUNC(int, keyexch_get_ctx_params, (void *ctx,
715                                                      OSSL_PARAM params[]))
716 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, keyexch_gettable_ctx_params,
717                     (void *ctx, void *provctx))
718 
719 /* Signature */
720 
721 # define OSSL_FUNC_SIGNATURE_NEWCTX                  1
722 # define OSSL_FUNC_SIGNATURE_SIGN_INIT               2
723 # define OSSL_FUNC_SIGNATURE_SIGN                    3
724 # define OSSL_FUNC_SIGNATURE_VERIFY_INIT             4
725 # define OSSL_FUNC_SIGNATURE_VERIFY                  5
726 # define OSSL_FUNC_SIGNATURE_VERIFY_RECOVER_INIT     6
727 # define OSSL_FUNC_SIGNATURE_VERIFY_RECOVER          7
728 # define OSSL_FUNC_SIGNATURE_DIGEST_SIGN_INIT        8
729 # define OSSL_FUNC_SIGNATURE_DIGEST_SIGN_UPDATE      9
730 # define OSSL_FUNC_SIGNATURE_DIGEST_SIGN_FINAL      10
731 # define OSSL_FUNC_SIGNATURE_DIGEST_SIGN            11
732 # define OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_INIT     12
733 # define OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_UPDATE   13
734 # define OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_FINAL    14
735 # define OSSL_FUNC_SIGNATURE_DIGEST_VERIFY          15
736 # define OSSL_FUNC_SIGNATURE_FREECTX                16
737 # define OSSL_FUNC_SIGNATURE_DUPCTX                 17
738 # define OSSL_FUNC_SIGNATURE_GET_CTX_PARAMS         18
739 # define OSSL_FUNC_SIGNATURE_GETTABLE_CTX_PARAMS    19
740 # define OSSL_FUNC_SIGNATURE_SET_CTX_PARAMS         20
741 # define OSSL_FUNC_SIGNATURE_SETTABLE_CTX_PARAMS    21
742 # define OSSL_FUNC_SIGNATURE_GET_CTX_MD_PARAMS      22
743 # define OSSL_FUNC_SIGNATURE_GETTABLE_CTX_MD_PARAMS 23
744 # define OSSL_FUNC_SIGNATURE_SET_CTX_MD_PARAMS      24
745 # define OSSL_FUNC_SIGNATURE_SETTABLE_CTX_MD_PARAMS 25
746 # define OSSL_FUNC_SIGNATURE_QUERY_KEY_TYPES        26
747 # define OSSL_FUNC_SIGNATURE_SIGN_MESSAGE_INIT      27
748 # define OSSL_FUNC_SIGNATURE_SIGN_MESSAGE_UPDATE    28
749 # define OSSL_FUNC_SIGNATURE_SIGN_MESSAGE_FINAL     29
750 # define OSSL_FUNC_SIGNATURE_VERIFY_MESSAGE_INIT    30
751 # define OSSL_FUNC_SIGNATURE_VERIFY_MESSAGE_UPDATE  31
752 # define OSSL_FUNC_SIGNATURE_VERIFY_MESSAGE_FINAL   32
753 
754 OSSL_CORE_MAKE_FUNC(void *, signature_newctx, (void *provctx,
755                                                const char *propq))
756 OSSL_CORE_MAKE_FUNC(int, signature_sign_init, (void *ctx, void *provkey,
757                                                const OSSL_PARAM params[]))
758 OSSL_CORE_MAKE_FUNC(int, signature_sign, (void *ctx,  unsigned char *sig,
759                                           size_t *siglen, size_t sigsize,
760                                           const unsigned char *tbs,
761                                           size_t tbslen))
762 OSSL_CORE_MAKE_FUNC(int, signature_sign_message_init,
763                     (void *ctx, void *provkey, const OSSL_PARAM params[]))
764 OSSL_CORE_MAKE_FUNC(int, signature_sign_message_update,
765                     (void *ctx, const unsigned char *in, size_t inlen))
766 OSSL_CORE_MAKE_FUNC(int, signature_sign_message_final,
767                     (void *ctx, unsigned char *sig,
768                      size_t *siglen, size_t sigsize))
769 OSSL_CORE_MAKE_FUNC(int, signature_verify_init, (void *ctx, void *provkey,
770                                                  const OSSL_PARAM params[]))
771 OSSL_CORE_MAKE_FUNC(int, signature_verify, (void *ctx,
772                                             const unsigned char *sig,
773                                             size_t siglen,
774                                             const unsigned char *tbs,
775                                             size_t tbslen))
776 OSSL_CORE_MAKE_FUNC(int, signature_verify_message_init,
777                     (void *ctx, void *provkey, const OSSL_PARAM params[]))
778 OSSL_CORE_MAKE_FUNC(int, signature_verify_message_update,
779                     (void *ctx, const unsigned char *in, size_t inlen))
780 /*
781  * signature_verify_final requires that the signature to be verified against
782  * is specified via an OSSL_PARAM.
783  */
784 OSSL_CORE_MAKE_FUNC(int, signature_verify_message_final, (void *ctx))
785 OSSL_CORE_MAKE_FUNC(int, signature_verify_recover_init,
786                     (void *ctx, void *provkey, const OSSL_PARAM params[]))
787 OSSL_CORE_MAKE_FUNC(int, signature_verify_recover,
788                     (void *ctx, unsigned char *rout, size_t *routlen,
789                      size_t routsize, const unsigned char *sig, size_t siglen))
790 OSSL_CORE_MAKE_FUNC(int, signature_digest_sign_init,
791                     (void *ctx, const char *mdname, void *provkey,
792                      const OSSL_PARAM params[]))
793 OSSL_CORE_MAKE_FUNC(int, signature_digest_sign_update,
794                     (void *ctx, const unsigned char *data, size_t datalen))
795 OSSL_CORE_MAKE_FUNC(int, signature_digest_sign_final,
796                     (void *ctx, unsigned char *sig, size_t *siglen,
797                      size_t sigsize))
798 OSSL_CORE_MAKE_FUNC(int, signature_digest_sign,
799                     (void *ctx, unsigned char *sigret, size_t *siglen,
800                      size_t sigsize, const unsigned char *tbs, size_t tbslen))
801 OSSL_CORE_MAKE_FUNC(int, signature_digest_verify_init,
802                     (void *ctx, const char *mdname, void *provkey,
803                      const OSSL_PARAM params[]))
804 OSSL_CORE_MAKE_FUNC(int, signature_digest_verify_update,
805                     (void *ctx, const unsigned char *data, size_t datalen))
806 OSSL_CORE_MAKE_FUNC(int, signature_digest_verify_final,
807                     (void *ctx, const unsigned char *sig, size_t siglen))
808 OSSL_CORE_MAKE_FUNC(int, signature_digest_verify,
809                     (void *ctx, const unsigned char *sig, size_t siglen,
810                      const unsigned char *tbs, size_t tbslen))
811 OSSL_CORE_MAKE_FUNC(void, signature_freectx, (void *ctx))
812 OSSL_CORE_MAKE_FUNC(void *, signature_dupctx, (void *ctx))
813 OSSL_CORE_MAKE_FUNC(int, signature_get_ctx_params,
814                     (void *ctx, OSSL_PARAM params[]))
815 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, signature_gettable_ctx_params,
816                     (void *ctx, void *provctx))
817 OSSL_CORE_MAKE_FUNC(int, signature_set_ctx_params,
818                     (void *ctx, const OSSL_PARAM params[]))
819 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, signature_settable_ctx_params,
820                     (void *ctx, void *provctx))
821 OSSL_CORE_MAKE_FUNC(int, signature_get_ctx_md_params,
822                     (void *ctx, OSSL_PARAM params[]))
823 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, signature_gettable_ctx_md_params,
824                     (void *ctx))
825 OSSL_CORE_MAKE_FUNC(int, signature_set_ctx_md_params,
826                     (void *ctx, const OSSL_PARAM params[]))
827 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, signature_settable_ctx_md_params,
828                     (void *ctx))
829 OSSL_CORE_MAKE_FUNC(const char **, signature_query_key_types, (void))
830 
831 /* Asymmetric Ciphers */
832 
833 # define OSSL_FUNC_ASYM_CIPHER_NEWCTX                  1
834 # define OSSL_FUNC_ASYM_CIPHER_ENCRYPT_INIT            2
835 # define OSSL_FUNC_ASYM_CIPHER_ENCRYPT                 3
836 # define OSSL_FUNC_ASYM_CIPHER_DECRYPT_INIT            4
837 # define OSSL_FUNC_ASYM_CIPHER_DECRYPT                 5
838 # define OSSL_FUNC_ASYM_CIPHER_FREECTX                 6
839 # define OSSL_FUNC_ASYM_CIPHER_DUPCTX                  7
840 # define OSSL_FUNC_ASYM_CIPHER_GET_CTX_PARAMS          8
841 # define OSSL_FUNC_ASYM_CIPHER_GETTABLE_CTX_PARAMS     9
842 # define OSSL_FUNC_ASYM_CIPHER_SET_CTX_PARAMS         10
843 # define OSSL_FUNC_ASYM_CIPHER_SETTABLE_CTX_PARAMS    11
844 
845 OSSL_CORE_MAKE_FUNC(void *, asym_cipher_newctx, (void *provctx))
846 OSSL_CORE_MAKE_FUNC(int, asym_cipher_encrypt_init, (void *ctx, void *provkey,
847                                                     const OSSL_PARAM params[]))
848 OSSL_CORE_MAKE_FUNC(int, asym_cipher_encrypt, (void *ctx, unsigned char *out,
849                                                   size_t *outlen,
850                                                   size_t outsize,
851                                                   const unsigned char *in,
852                                                   size_t inlen))
853 OSSL_CORE_MAKE_FUNC(int, asym_cipher_decrypt_init, (void *ctx, void *provkey,
854                                                     const OSSL_PARAM params[]))
855 OSSL_CORE_MAKE_FUNC(int, asym_cipher_decrypt, (void *ctx, unsigned char *out,
856                                                   size_t *outlen,
857                                                   size_t outsize,
858                                                   const unsigned char *in,
859                                                   size_t inlen))
860 OSSL_CORE_MAKE_FUNC(void, asym_cipher_freectx, (void *ctx))
861 OSSL_CORE_MAKE_FUNC(void *, asym_cipher_dupctx, (void *ctx))
862 OSSL_CORE_MAKE_FUNC(int, asym_cipher_get_ctx_params,
863                     (void *ctx, OSSL_PARAM params[]))
864 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, asym_cipher_gettable_ctx_params,
865                     (void *ctx, void *provctx))
866 OSSL_CORE_MAKE_FUNC(int, asym_cipher_set_ctx_params,
867                     (void *ctx, const OSSL_PARAM params[]))
868 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, asym_cipher_settable_ctx_params,
869                     (void *ctx, void *provctx))
870 
871 /* Asymmetric Key encapsulation */
872 # define OSSL_FUNC_KEM_NEWCTX                  1
873 # define OSSL_FUNC_KEM_ENCAPSULATE_INIT        2
874 # define OSSL_FUNC_KEM_ENCAPSULATE             3
875 # define OSSL_FUNC_KEM_DECAPSULATE_INIT        4
876 # define OSSL_FUNC_KEM_DECAPSULATE             5
877 # define OSSL_FUNC_KEM_FREECTX                 6
878 # define OSSL_FUNC_KEM_DUPCTX                  7
879 # define OSSL_FUNC_KEM_GET_CTX_PARAMS          8
880 # define OSSL_FUNC_KEM_GETTABLE_CTX_PARAMS     9
881 # define OSSL_FUNC_KEM_SET_CTX_PARAMS         10
882 # define OSSL_FUNC_KEM_SETTABLE_CTX_PARAMS    11
883 # define OSSL_FUNC_KEM_AUTH_ENCAPSULATE_INIT  12
884 # define OSSL_FUNC_KEM_AUTH_DECAPSULATE_INIT  13
885 
886 OSSL_CORE_MAKE_FUNC(void *, kem_newctx, (void *provctx))
887 OSSL_CORE_MAKE_FUNC(int, kem_encapsulate_init, (void *ctx, void *provkey,
888                                                 const OSSL_PARAM params[]))
889 OSSL_CORE_MAKE_FUNC(int, kem_auth_encapsulate_init, (void *ctx, void *provkey,
890                                                      void *authprivkey,
891                                                      const OSSL_PARAM params[]))
892 OSSL_CORE_MAKE_FUNC(int, kem_encapsulate, (void *ctx,
893                                            unsigned char *out, size_t *outlen,
894                                            unsigned char *secret,
895                                            size_t *secretlen))
896 OSSL_CORE_MAKE_FUNC(int, kem_decapsulate_init, (void *ctx, void *provkey,
897                                                 const OSSL_PARAM params[]))
898 OSSL_CORE_MAKE_FUNC(int, kem_auth_decapsulate_init, (void *ctx, void *provkey,
899                                                      void *authpubkey,
900                                                      const OSSL_PARAM params[]))
901 OSSL_CORE_MAKE_FUNC(int, kem_decapsulate, (void *ctx,
902                                            unsigned char *out, size_t *outlen,
903                                            const unsigned char *in, size_t inlen))
904 OSSL_CORE_MAKE_FUNC(void, kem_freectx, (void *ctx))
905 OSSL_CORE_MAKE_FUNC(void *, kem_dupctx, (void *ctx))
906 OSSL_CORE_MAKE_FUNC(int, kem_get_ctx_params, (void *ctx, OSSL_PARAM params[]))
907 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, kem_gettable_ctx_params,
908                     (void *ctx, void *provctx))
909 OSSL_CORE_MAKE_FUNC(int, kem_set_ctx_params,
910                     (void *ctx, const OSSL_PARAM params[]))
911 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, kem_settable_ctx_params,
912                     (void *ctx, void *provctx))
913 
914 /* Encoders and decoders */
915 # define OSSL_FUNC_ENCODER_NEWCTX                      1
916 # define OSSL_FUNC_ENCODER_FREECTX                     2
917 # define OSSL_FUNC_ENCODER_GET_PARAMS                  3
918 # define OSSL_FUNC_ENCODER_GETTABLE_PARAMS             4
919 # define OSSL_FUNC_ENCODER_SET_CTX_PARAMS              5
920 # define OSSL_FUNC_ENCODER_SETTABLE_CTX_PARAMS         6
921 # define OSSL_FUNC_ENCODER_DOES_SELECTION             10
922 # define OSSL_FUNC_ENCODER_ENCODE                     11
923 # define OSSL_FUNC_ENCODER_IMPORT_OBJECT              20
924 # define OSSL_FUNC_ENCODER_FREE_OBJECT                21
925 OSSL_CORE_MAKE_FUNC(void *, encoder_newctx, (void *provctx))
926 OSSL_CORE_MAKE_FUNC(void, encoder_freectx, (void *ctx))
927 OSSL_CORE_MAKE_FUNC(int, encoder_get_params, (OSSL_PARAM params[]))
928 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, encoder_gettable_params,
929                     (void *provctx))
930 OSSL_CORE_MAKE_FUNC(int, encoder_set_ctx_params,
931                     (void *ctx, const OSSL_PARAM params[]))
932 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, encoder_settable_ctx_params,
933                     (void *provctx))
934 
935 OSSL_CORE_MAKE_FUNC(int, encoder_does_selection,
936                     (void *provctx, int selection))
937 OSSL_CORE_MAKE_FUNC(int, encoder_encode,
938                     (void *ctx, OSSL_CORE_BIO *out,
939                      const void *obj_raw, const OSSL_PARAM obj_abstract[],
940                      int selection,
941                      OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg))
942 
943 OSSL_CORE_MAKE_FUNC(void *, encoder_import_object,
944                     (void *ctx, int selection, const OSSL_PARAM params[]))
945 OSSL_CORE_MAKE_FUNC(void, encoder_free_object, (void *obj))
946 
947 # define OSSL_FUNC_DECODER_NEWCTX                      1
948 # define OSSL_FUNC_DECODER_FREECTX                     2
949 # define OSSL_FUNC_DECODER_GET_PARAMS                  3
950 # define OSSL_FUNC_DECODER_GETTABLE_PARAMS             4
951 # define OSSL_FUNC_DECODER_SET_CTX_PARAMS              5
952 # define OSSL_FUNC_DECODER_SETTABLE_CTX_PARAMS         6
953 # define OSSL_FUNC_DECODER_DOES_SELECTION             10
954 # define OSSL_FUNC_DECODER_DECODE                     11
955 # define OSSL_FUNC_DECODER_EXPORT_OBJECT              20
956 OSSL_CORE_MAKE_FUNC(void *, decoder_newctx, (void *provctx))
957 OSSL_CORE_MAKE_FUNC(void, decoder_freectx, (void *ctx))
958 OSSL_CORE_MAKE_FUNC(int, decoder_get_params, (OSSL_PARAM params[]))
959 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, decoder_gettable_params,
960                     (void *provctx))
961 OSSL_CORE_MAKE_FUNC(int, decoder_set_ctx_params,
962                     (void *ctx, const OSSL_PARAM params[]))
963 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, decoder_settable_ctx_params,
964                     (void *provctx))
965 
966 OSSL_CORE_MAKE_FUNC(int, decoder_does_selection,
967                     (void *provctx, int selection))
968 OSSL_CORE_MAKE_FUNC(int, decoder_decode,
969                     (void *ctx, OSSL_CORE_BIO *in, int selection,
970                      OSSL_CALLBACK *data_cb, void *data_cbarg,
971                      OSSL_PASSPHRASE_CALLBACK *pw_cb, void *pw_cbarg))
972 OSSL_CORE_MAKE_FUNC(int, decoder_export_object,
973                     (void *ctx, const void *objref, size_t objref_sz,
974                      OSSL_CALLBACK *export_cb, void *export_cbarg))
975 
976 /*-
977  * Store
978  *
979  * Objects are scanned by using the 'open', 'load', 'eof' and 'close'
980  * functions, which implement an OSSL_STORE loader.
981  *
982  * store_load() works in a way that's very similar to the decoders, in
983  * that they pass an abstract object through a callback, either as a DER
984  * octet string or as an object reference, which libcrypto will have to
985  * deal with.
986  */
987 
988 #define OSSL_FUNC_STORE_OPEN                        1
989 #define OSSL_FUNC_STORE_ATTACH                      2
990 #define OSSL_FUNC_STORE_SETTABLE_CTX_PARAMS         3
991 #define OSSL_FUNC_STORE_SET_CTX_PARAMS              4
992 #define OSSL_FUNC_STORE_LOAD                        5
993 #define OSSL_FUNC_STORE_EOF                         6
994 #define OSSL_FUNC_STORE_CLOSE                       7
995 #define OSSL_FUNC_STORE_EXPORT_OBJECT               8
996 #define OSSL_FUNC_STORE_DELETE                      9
997 #define OSSL_FUNC_STORE_OPEN_EX                     10
998 OSSL_CORE_MAKE_FUNC(void *, store_open, (void *provctx, const char *uri))
999 OSSL_CORE_MAKE_FUNC(void *, store_attach, (void *provctx, OSSL_CORE_BIO *in))
1000 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, store_settable_ctx_params,
1001                     (void *provctx))
1002 OSSL_CORE_MAKE_FUNC(int, store_set_ctx_params,
1003                     (void *loaderctx, const OSSL_PARAM params[]))
1004 OSSL_CORE_MAKE_FUNC(int, store_load,
1005                     (void *loaderctx,
1006                      OSSL_CALLBACK *object_cb, void *object_cbarg,
1007                      OSSL_PASSPHRASE_CALLBACK *pw_cb, void *pw_cbarg))
1008 OSSL_CORE_MAKE_FUNC(int, store_eof, (void *loaderctx))
1009 OSSL_CORE_MAKE_FUNC(int, store_close, (void *loaderctx))
1010 OSSL_CORE_MAKE_FUNC(int, store_export_object,
1011                     (void *loaderctx, const void *objref, size_t objref_sz,
1012                      OSSL_CALLBACK *export_cb, void *export_cbarg))
1013 OSSL_CORE_MAKE_FUNC(int, store_delete,
1014                     (void *provctx, const char *uri, const OSSL_PARAM params[],
1015                      OSSL_PASSPHRASE_CALLBACK *pw_cb, void *pw_cbarg))
1016 OSSL_CORE_MAKE_FUNC(void *, store_open_ex,
1017                     (void *provctx, const char *uri, const OSSL_PARAM params[],
1018                      OSSL_PASSPHRASE_CALLBACK *pw_cb, void *pw_cbarg))
1019 
1020 # ifdef __cplusplus
1021 }
1022 # endif
1023 
1024 #endif
1025