2 * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
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
10 #ifndef OSSL_CORE_NUMBERS_H
11 # define OSSL_CORE_NUMBERS_H
14 # include <openssl/core.h>
24 * All series start with 1, to allow 0 to be an array terminator.
25 * For any FUNC identity, we also provide a function signature typedef
26 * and a static inline function to extract a function pointer from a
27 * OSSL_DISPATCH element in a type safe manner.
30 * for any function base name 'foo' (uppercase form 'FOO'), we will have
32 * - a macro for the identity with the name OSSL_FUNC_'FOO' or derivates
33 * thereof (to be specified further down)
34 * - a function signature typedef with the name OSSL_'foo'_fn
35 * - a function pointer extractor function with the name OSSL_'foo'
39 * Helper macro to create the function signature typedef and the extractor
40 * |type| is the return-type of the function, |name| is the name of the
41 * function to fetch, and |args| is a parenthesized list of parameters
42 * for the function (that is, it is |name|'s function signature).
44 #define OSSL_CORE_MAKE_FUNC(type,name,args) \
45 typedef type (OSSL_##name##_fn)args; \
47 OSSL_##name##_fn *OSSL_get_##name(const OSSL_DISPATCH *opf) \
49 return (OSSL_##name##_fn *)opf->function; \
53 * Core function identities, for the two OSSL_DISPATCH tables being passed
54 * in the OSSL_provider_init call.
56 * 0 serves as a marker for the end of the OSSL_DISPATCH array, and must
57 * therefore NEVER be used as a function identity.
59 /* Functions provided by the Core to the provider, reserved numbers 1-1023 */
60 # define OSSL_FUNC_CORE_GET_PARAM_TYPES 1
61 OSSL_CORE_MAKE_FUNC(const OSSL_ITEM *,
62 core_get_param_types,(const OSSL_PROVIDER *prov))
63 # define OSSL_FUNC_CORE_GET_PARAMS 2
64 OSSL_CORE_MAKE_FUNC(int,core_get_params,(const OSSL_PROVIDER *prov,
66 # define OSSL_FUNC_CORE_THREAD_START 3
67 OSSL_CORE_MAKE_FUNC(int,core_thread_start,(const OSSL_PROVIDER *prov,
68 OSSL_thread_stop_handler_fn handfn))
69 # define OSSL_FUNC_CORE_PUT_ERROR 4
70 OSSL_CORE_MAKE_FUNC(void,core_put_error,
71 (const OSSL_PROVIDER *prov,
72 uint32_t reason, const char *file, int line))
73 # define OSSL_FUNC_CORE_ADD_ERROR_VDATA 5
74 OSSL_CORE_MAKE_FUNC(void,core_add_error_vdata,(const OSSL_PROVIDER *prov,
75 int num, va_list args))
76 # define OSSL_FUNC_CORE_GET_LIBRARY_CONTEXT 6
77 OSSL_CORE_MAKE_FUNC(OPENSSL_CTX *,core_get_library_context,
78 (const OSSL_PROVIDER *prov))
81 /* Memory allocation, freeing, clearing. */
82 #define OSSL_FUNC_CRYPTO_MALLOC 10
83 OSSL_CORE_MAKE_FUNC(void *,
84 CRYPTO_malloc, (size_t num, const char *file, int line))
85 #define OSSL_FUNC_CRYPTO_ZALLOC 11
86 OSSL_CORE_MAKE_FUNC(void *,
87 CRYPTO_zalloc, (size_t num, const char *file, int line))
88 #define OSSL_FUNC_CRYPTO_MEMDUP 12
89 OSSL_CORE_MAKE_FUNC(void *,
90 CRYPTO_memdup, (const void *str, size_t siz, const char *file, int line))
91 #define OSSL_FUNC_CRYPTO_STRDUP 13
92 OSSL_CORE_MAKE_FUNC(char *,
93 CRYPTO_strdup, (const char *str, const char *file, int line))
94 #define OSSL_FUNC_CRYPTO_STRNDUP 14
95 OSSL_CORE_MAKE_FUNC(char *,
96 CRYPTO_strndup, (const char *str, size_t s, const char *file, int line))
97 #define OSSL_FUNC_CRYPTO_FREE 15
98 OSSL_CORE_MAKE_FUNC(void,
99 CRYPTO_free, (void *ptr, const char *file, int line))
100 #define OSSL_FUNC_CRYPTO_CLEAR_FREE 16
101 OSSL_CORE_MAKE_FUNC(void,
102 CRYPTO_clear_free, (void *ptr, size_t num, const char *file, int line))
103 #define OSSL_FUNC_CRYPTO_REALLOC 17
104 OSSL_CORE_MAKE_FUNC(void *,
105 CRYPTO_realloc, (void *addr, size_t num, const char *file, int line))
106 #define OSSL_FUNC_CRYPTO_CLEAR_REALLOC 18
107 OSSL_CORE_MAKE_FUNC(void *,
108 CRYPTO_clear_realloc, (void *addr, size_t old_num, size_t num, const char *file, int line))
109 #define OSSL_FUNC_CRYPTO_SECURE_MALLOC 19
110 OSSL_CORE_MAKE_FUNC(void *,
111 CRYPTO_secure_malloc, (size_t num, const char *file, int line))
112 #define OSSL_FUNC_CRYPTO_SECURE_ZALLOC 20
113 OSSL_CORE_MAKE_FUNC(void *,
114 CRYPTO_secure_zalloc, (size_t num, const char *file, int line))
115 #define OSSL_FUNC_CRYPTO_SECURE_FREE 21
116 OSSL_CORE_MAKE_FUNC(void,
117 CRYPTO_secure_free, (void *ptr, const char *file, int line))
118 #define OSSL_FUNC_CRYPTO_SECURE_CLEAR_FREE 22
119 OSSL_CORE_MAKE_FUNC(void,
120 CRYPTO_secure_clear_free, (void *ptr, size_t num, const char *file, int line))
121 #define OSSL_FUNC_CRYPTO_SECURE_ALLOCATED 23
122 OSSL_CORE_MAKE_FUNC(int,
123 CRYPTO_secure_allocated, (const void *ptr))
124 #define OSSL_FUNC_OPENSSL_CLEANSE 24
125 OSSL_CORE_MAKE_FUNC(void,
126 OPENSSL_cleanse, (void *ptr, size_t len))
127 # define OSSL_FUNC_OPENSSL_HEXSTR2BUF 25
128 OSSL_CORE_MAKE_FUNC(unsigned char *,
129 OPENSSL_hexstr2buf, (const char *str, long *len))
131 /* Functions provided by the provider to the Core, reserved numbers 1024-1535 */
132 # define OSSL_FUNC_PROVIDER_TEARDOWN 1024
133 OSSL_CORE_MAKE_FUNC(void,provider_teardown,(void *provctx))
134 # define OSSL_FUNC_PROVIDER_GET_PARAM_TYPES 1025
135 OSSL_CORE_MAKE_FUNC(const OSSL_ITEM *,
136 provider_get_param_types,(void *provctx))
137 # define OSSL_FUNC_PROVIDER_GET_PARAMS 1026
138 OSSL_CORE_MAKE_FUNC(int,provider_get_params,(void *provctx,
139 OSSL_PARAM params[]))
140 # define OSSL_FUNC_PROVIDER_QUERY_OPERATION 1027
141 OSSL_CORE_MAKE_FUNC(const OSSL_ALGORITHM *,provider_query_operation,
142 (void *provctx, int operation_id, const int *no_store))
143 # define OSSL_FUNC_PROVIDER_GET_REASON_STRINGS 1028
144 OSSL_CORE_MAKE_FUNC(const OSSL_ITEM *,provider_get_reason_strings,
149 # define OSSL_OP_DIGEST 1
151 # define OSSL_FUNC_DIGEST_NEWCTX 1
152 # define OSSL_FUNC_DIGEST_INIT 2
153 # define OSSL_FUNC_DIGEST_UPDATE 3
154 # define OSSL_FUNC_DIGEST_FINAL 4
155 # define OSSL_FUNC_DIGEST_DIGEST 5
156 # define OSSL_FUNC_DIGEST_FREECTX 6
157 # define OSSL_FUNC_DIGEST_DUPCTX 7
158 # define OSSL_FUNC_DIGEST_SIZE 8
159 # define OSSL_FUNC_DIGEST_BLOCK_SIZE 9
160 # define OSSL_FUNC_DIGEST_SET_PARAMS 10
161 # define OSSL_FUNC_DIGEST_GET_PARAMS 11
163 OSSL_CORE_MAKE_FUNC(void *, OP_digest_newctx, (void *provctx))
164 OSSL_CORE_MAKE_FUNC(int, OP_digest_init, (void *dctx))
165 OSSL_CORE_MAKE_FUNC(int, OP_digest_update,
166 (void *dctx, const unsigned char *in, size_t inl))
167 OSSL_CORE_MAKE_FUNC(int, OP_digest_final,
169 unsigned char *out, size_t *outl, size_t outsz))
170 OSSL_CORE_MAKE_FUNC(int, OP_digest_digest,
171 (void *provctx, const unsigned char *in, size_t inl,
172 unsigned char *out, size_t *out_l, size_t outsz))
174 OSSL_CORE_MAKE_FUNC(void, OP_digest_cleanctx, (void *dctx))
175 OSSL_CORE_MAKE_FUNC(void, OP_digest_freectx, (void *dctx))
176 OSSL_CORE_MAKE_FUNC(void *, OP_digest_dupctx, (void *dctx))
178 OSSL_CORE_MAKE_FUNC(size_t, OP_digest_size, (void))
179 OSSL_CORE_MAKE_FUNC(size_t, OP_digest_block_size, (void))
180 OSSL_CORE_MAKE_FUNC(int, OP_digest_set_params,
181 (void *vctx, const OSSL_PARAM params[]))
182 OSSL_CORE_MAKE_FUNC(int, OP_digest_get_params,
183 (void *vctx, OSSL_PARAM params[]))
184 OSSL_CORE_MAKE_FUNC(unsigned long, OP_cipher_get_flags, (void))
186 /* Symmetric Ciphers */
188 # define OSSL_OP_CIPHER 2
190 # define OSSL_FUNC_CIPHER_NEWCTX 1
191 # define OSSL_FUNC_CIPHER_ENCRYPT_INIT 2
192 # define OSSL_FUNC_CIPHER_DECRYPT_INIT 3
193 # define OSSL_FUNC_CIPHER_UPDATE 4
194 # define OSSL_FUNC_CIPHER_FINAL 5
195 # define OSSL_FUNC_CIPHER_CIPHER 6
196 # define OSSL_FUNC_CIPHER_FREECTX 7
197 # define OSSL_FUNC_CIPHER_DUPCTX 8
198 # define OSSL_FUNC_CIPHER_GET_PARAMS 9
199 # define OSSL_FUNC_CIPHER_CTX_GET_PARAMS 10
200 # define OSSL_FUNC_CIPHER_CTX_SET_PARAMS 11
202 OSSL_CORE_MAKE_FUNC(void *, OP_cipher_newctx, (void *provctx))
203 OSSL_CORE_MAKE_FUNC(int, OP_cipher_encrypt_init, (void *cctx,
204 const unsigned char *key,
206 const unsigned char *iv,
208 OSSL_CORE_MAKE_FUNC(int, OP_cipher_decrypt_init, (void *cctx,
209 const unsigned char *key,
211 const unsigned char *iv,
213 OSSL_CORE_MAKE_FUNC(int, OP_cipher_update,
215 unsigned char *out, size_t *outl, size_t outsize,
216 const unsigned char *in, size_t inl))
217 OSSL_CORE_MAKE_FUNC(int, OP_cipher_final,
219 unsigned char *out, size_t *outl, size_t outsize))
220 OSSL_CORE_MAKE_FUNC(int, OP_cipher_cipher,
222 unsigned char *out, size_t *outl, size_t outsize,
223 const unsigned char *in, size_t inl))
224 OSSL_CORE_MAKE_FUNC(void, OP_cipher_freectx, (void *cctx))
225 OSSL_CORE_MAKE_FUNC(void *, OP_cipher_dupctx, (void *cctx))
226 OSSL_CORE_MAKE_FUNC(int, OP_cipher_get_params, (OSSL_PARAM params[]))
227 OSSL_CORE_MAKE_FUNC(int, OP_cipher_ctx_get_params, (void *cctx,
228 OSSL_PARAM params[]))
229 OSSL_CORE_MAKE_FUNC(int, OP_cipher_ctx_set_params, (void *cctx,
230 const OSSL_PARAM params[]))
235 * Key domain parameter references can be created in several manners:
236 * - by importing the domain parameter material via an OSSL_PARAM array.
237 * - by generating key domain parameters, given input via an OSSL_PARAM
240 * Key references can be created in several manners:
241 * - by importing the key material via an OSSL_PARAM array.
242 * - by generating a key, given optional domain parameters and
243 * additional keygen parameters.
244 * If domain parameters are given, they must have been generated using
245 * the domain parameter generator functions.
246 * If the domain parameters comes from a different provider, results
248 * THE CALLER MUST ENSURE THAT CORRECT DOMAIN PARAMETERS ARE USED.
249 * - by loading an internal key, given a binary blob that forms an identity.
250 * THE CALLER MUST ENSURE THAT A CORRECT IDENTITY IS USED.
253 # define OSSL_OP_KEYMGMT 10
255 /* Key domain parameter creation and destruction */
256 # define OSSL_FUNC_KEYMGMT_IMPORTDOMPARAMS 1
257 # define OSSL_FUNC_KEYMGMT_GENDOMPARAMS 2
258 # define OSSL_FUNC_KEYMGMT_FREEDOMPARAMS 3
259 OSSL_CORE_MAKE_FUNC(void *, OP_keymgmt_importdomparams,
260 (void *provctx, const OSSL_PARAM params[]))
261 OSSL_CORE_MAKE_FUNC(void *, OP_keymgmt_gendomparams,
262 (void *provctx, const OSSL_PARAM params[]))
263 OSSL_CORE_MAKE_FUNC(void, OP_keymgmt_freedomparams, (void *domparams))
265 /* Key domain parameter export */
266 # define OSSL_FUNC_KEYMGMT_EXPORTDOMPARAMS 4
267 OSSL_CORE_MAKE_FUNC(int, OP_keymgmt_exportdomparams,
268 (void *domparams, OSSL_PARAM params[]))
270 /* Key domain parameter discovery */
271 # define OSSL_FUNC_KEYMGMT_IMPORTDOMPARAM_TYPES 5
272 # define OSSL_FUNC_KEYMGMT_EXPORTDOMPARAM_TYPES 6
273 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_keymgmt_importdomparam_types,
275 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_keymgmt_exportdomparam_types,
278 /* Key creation and destruction */
279 # define OSSL_FUNC_KEYMGMT_IMPORTKEY 10
280 # define OSSL_FUNC_KEYMGMT_GENKEY 11
281 # define OSSL_FUNC_KEYMGMT_LOADKEY 12
282 # define OSSL_FUNC_KEYMGMT_FREEKEY 13
283 OSSL_CORE_MAKE_FUNC(void *, OP_keymgmt_importkey,
284 (void *provctx, const OSSL_PARAM params[]))
285 OSSL_CORE_MAKE_FUNC(void *, OP_keymgmt_genkey,
287 void *domparams, const OSSL_PARAM genkeyparams[]))
288 OSSL_CORE_MAKE_FUNC(void *, OP_keymgmt_loadkey,
289 (void *provctx, void *id, size_t idlen))
290 OSSL_CORE_MAKE_FUNC(void, OP_keymgmt_freekey, (void *key))
293 # define OSSL_FUNC_KEYMGMT_EXPORTKEY 14
294 OSSL_CORE_MAKE_FUNC(int, OP_keymgmt_exportkey,
295 (void *key, OSSL_PARAM params[]))
298 # define OSSL_FUNC_KEYMGMT_IMPORTKEY_TYPES 15
299 # define OSSL_FUNC_KEYMGMT_EXPORTKEY_TYPES 16
300 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_keymgmt_importkey_types, (void))
301 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_keymgmt_exportkey_types, (void))
305 # define OSSL_OP_KEYEXCH 11
307 # define OSSL_FUNC_KEYEXCH_NEWCTX 1
308 # define OSSL_FUNC_KEYEXCH_INIT 2
309 # define OSSL_FUNC_KEYEXCH_DERIVE 3
310 # define OSSL_FUNC_KEYEXCH_SET_PEER 4
311 # define OSSL_FUNC_KEYEXCH_FREECTX 5
312 # define OSSL_FUNC_KEYEXCH_DUPCTX 6
313 # define OSSL_FUNC_KEYEXCH_SET_PARAMS 7
315 OSSL_CORE_MAKE_FUNC(void *, OP_keyexch_newctx, (void *provctx))
316 OSSL_CORE_MAKE_FUNC(int, OP_keyexch_init, (void *ctx,
317 OSSL_PARAM params[]))
318 OSSL_CORE_MAKE_FUNC(int, OP_keyexch_derive, (void *ctx, unsigned char *key,
319 size_t *keylen, size_t outlen))
320 OSSL_CORE_MAKE_FUNC(int, OP_keyexch_set_peer, (void *ctx,
321 OSSL_PARAM params[]))
322 OSSL_CORE_MAKE_FUNC(void, OP_keyexch_freectx, (void *ctx))
323 OSSL_CORE_MAKE_FUNC(void *, OP_keyexch_dupctx, (void *ctx))
324 OSSL_CORE_MAKE_FUNC(int, OP_keyexch_set_params, (void *ctx,
325 OSSL_PARAM params[]))
327 /* Highest known operation number */
328 # define OSSL_OP__HIGHEST 3