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