]>
Commit | Line | Data |
---|---|---|
4c2883a9 RL |
1 | /* |
2 | * Copyright 2019 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 OSSL_CORE_NUMBERS_H | |
11 | # define OSSL_CORE_NUMBERS_H | |
12 | ||
3593266d | 13 | # include <stdarg.h> |
4c2883a9 RL |
14 | # include <openssl/core.h> |
15 | ||
16 | # ifdef __cplusplus | |
17 | extern "C" { | |
18 | # endif | |
19 | ||
20 | /*- | |
21 | * Identities | |
22 | * ---------- | |
23 | * | |
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. | |
28 | * | |
29 | * Names: | |
30 | * for any function base name 'foo' (uppercase form 'FOO'), we will have | |
31 | * the following: | |
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' | |
36 | */ | |
37 | ||
b60cba3c RS |
38 | /* |
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). | |
43 | */ | |
4c2883a9 RL |
44 | #define OSSL_CORE_MAKE_FUNC(type,name,args) \ |
45 | typedef type (OSSL_##name##_fn)args; \ | |
46 | static ossl_inline \ | |
47 | OSSL_##name##_fn *OSSL_get_##name(const OSSL_DISPATCH *opf) \ | |
48 | { \ | |
49 | return (OSSL_##name##_fn *)opf->function; \ | |
50 | } | |
51 | ||
52 | /* | |
53 | * Core function identities, for the two OSSL_DISPATCH tables being passed | |
54 | * in the OSSL_provider_init call. | |
55 | * | |
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. | |
58 | */ | |
59 | /* Functions provided by the Core to the provider, reserved numbers 1-1023 */ | |
60 | # define OSSL_FUNC_CORE_GET_PARAM_TYPES 1 | |
26175013 | 61 | OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, |
4c2883a9 RL |
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, | |
4e7991b4 | 65 | OSSL_PARAM params[])) |
da747958 MC |
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 | |
6ebc2f56 RL |
70 | OSSL_CORE_MAKE_FUNC(void,core_put_error, |
71 | (const OSSL_PROVIDER *prov, | |
72 | uint32_t reason, const char *file, int line)) | |
da747958 | 73 | # define OSSL_FUNC_CORE_ADD_ERROR_VDATA 5 |
6ebc2f56 RL |
74 | OSSL_CORE_MAKE_FUNC(void,core_add_error_vdata,(const OSSL_PROVIDER *prov, |
75 | int num, va_list args)) | |
da747958 | 76 | # define OSSL_FUNC_CORE_GET_LIBRARY_CONTEXT 6 |
e7706e63 RL |
77 | OSSL_CORE_MAKE_FUNC(OPENSSL_CTX *,core_get_library_context, |
78 | (const OSSL_PROVIDER *prov)) | |
3593266d | 79 | |
4c2883a9 | 80 | |
b60cba3c RS |
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)) | |
037439c4 | 88 | #define OSSL_FUNC_CRYPTO_FREE 12 |
b60cba3c RS |
89 | OSSL_CORE_MAKE_FUNC(void, |
90 | CRYPTO_free, (void *ptr, const char *file, int line)) | |
037439c4 | 91 | #define OSSL_FUNC_CRYPTO_CLEAR_FREE 13 |
b60cba3c RS |
92 | OSSL_CORE_MAKE_FUNC(void, |
93 | CRYPTO_clear_free, (void *ptr, size_t num, const char *file, int line)) | |
037439c4 | 94 | #define OSSL_FUNC_CRYPTO_REALLOC 14 |
b60cba3c RS |
95 | OSSL_CORE_MAKE_FUNC(void *, |
96 | CRYPTO_realloc, (void *addr, size_t num, const char *file, int line)) | |
037439c4 | 97 | #define OSSL_FUNC_CRYPTO_CLEAR_REALLOC 15 |
b60cba3c RS |
98 | OSSL_CORE_MAKE_FUNC(void *, |
99 | CRYPTO_clear_realloc, (void *addr, size_t old_num, size_t num, const char *file, int line)) | |
037439c4 | 100 | #define OSSL_FUNC_CRYPTO_SECURE_MALLOC 16 |
b60cba3c RS |
101 | OSSL_CORE_MAKE_FUNC(void *, |
102 | CRYPTO_secure_malloc, (size_t num, const char *file, int line)) | |
037439c4 | 103 | #define OSSL_FUNC_CRYPTO_SECURE_ZALLOC 17 |
b60cba3c RS |
104 | OSSL_CORE_MAKE_FUNC(void *, |
105 | CRYPTO_secure_zalloc, (size_t num, const char *file, int line)) | |
037439c4 | 106 | #define OSSL_FUNC_CRYPTO_SECURE_FREE 18 |
b60cba3c RS |
107 | OSSL_CORE_MAKE_FUNC(void, |
108 | CRYPTO_secure_free, (void *ptr, const char *file, int line)) | |
037439c4 | 109 | #define OSSL_FUNC_CRYPTO_SECURE_CLEAR_FREE 19 |
b60cba3c RS |
110 | OSSL_CORE_MAKE_FUNC(void, |
111 | CRYPTO_secure_clear_free, (void *ptr, size_t num, const char *file, int line)) | |
037439c4 | 112 | #define OSSL_FUNC_CRYPTO_SECURE_ALLOCATED 20 |
b60cba3c RS |
113 | OSSL_CORE_MAKE_FUNC(int, |
114 | CRYPTO_secure_allocated, (const void *ptr)) | |
037439c4 | 115 | #define OSSL_FUNC_OPENSSL_CLEANSE 21 |
b60cba3c RS |
116 | OSSL_CORE_MAKE_FUNC(void, |
117 | OPENSSL_cleanse, (void *ptr, size_t len)) | |
b60cba3c | 118 | |
4c2883a9 RL |
119 | /* Functions provided by the provider to the Core, reserved numbers 1024-1535 */ |
120 | # define OSSL_FUNC_PROVIDER_TEARDOWN 1024 | |
a39eb840 | 121 | OSSL_CORE_MAKE_FUNC(void,provider_teardown,(void *provctx)) |
4c2883a9 | 122 | # define OSSL_FUNC_PROVIDER_GET_PARAM_TYPES 1025 |
26175013 | 123 | OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, |
a39eb840 | 124 | provider_get_param_types,(void *provctx)) |
4c2883a9 | 125 | # define OSSL_FUNC_PROVIDER_GET_PARAMS 1026 |
a39eb840 | 126 | OSSL_CORE_MAKE_FUNC(int,provider_get_params,(void *provctx, |
4e7991b4 | 127 | OSSL_PARAM params[])) |
099bd339 RL |
128 | # define OSSL_FUNC_PROVIDER_QUERY_OPERATION 1027 |
129 | OSSL_CORE_MAKE_FUNC(const OSSL_ALGORITHM *,provider_query_operation, | |
a39eb840 | 130 | (void *provctx, int operation_id, const int *no_store)) |
6ebc2f56 RL |
131 | # define OSSL_FUNC_PROVIDER_GET_REASON_STRINGS 1028 |
132 | OSSL_CORE_MAKE_FUNC(const OSSL_ITEM *,provider_get_reason_strings, | |
133 | (void *provctx)) | |
4c2883a9 | 134 | |
3653d0c2 MC |
135 | /* Digests */ |
136 | ||
137 | # define OSSL_OP_DIGEST 1 | |
138 | ||
139 | # define OSSL_FUNC_DIGEST_NEWCTX 1 | |
140 | # define OSSL_FUNC_DIGEST_INIT 2 | |
df05f2ce | 141 | # define OSSL_FUNC_DIGEST_UPDATE 3 |
3653d0c2 MC |
142 | # define OSSL_FUNC_DIGEST_FINAL 4 |
143 | # define OSSL_FUNC_DIGEST_DIGEST 5 | |
144 | # define OSSL_FUNC_DIGEST_FREECTX 6 | |
8c8cf0d9 MC |
145 | # define OSSL_FUNC_DIGEST_DUPCTX 7 |
146 | # define OSSL_FUNC_DIGEST_SIZE 8 | |
7556b9df | 147 | # define OSSL_FUNC_DIGEST_BLOCK_SIZE 9 |
d5e5e2ff SL |
148 | # define OSSL_FUNC_DIGEST_SET_PARAMS 10 |
149 | # define OSSL_FUNC_DIGEST_GET_PARAMS 11 | |
df05f2ce | 150 | |
a39eb840 RL |
151 | OSSL_CORE_MAKE_FUNC(void *, OP_digest_newctx, (void *provctx)) |
152 | OSSL_CORE_MAKE_FUNC(int, OP_digest_init, (void *dctx)) | |
3653d0c2 | 153 | OSSL_CORE_MAKE_FUNC(int, OP_digest_update, |
a39eb840 | 154 | (void *dctx, const unsigned char *in, size_t inl)) |
3653d0c2 | 155 | OSSL_CORE_MAKE_FUNC(int, OP_digest_final, |
a39eb840 RL |
156 | (void *dctx, |
157 | unsigned char *out, size_t *outl, size_t outsz)) | |
3653d0c2 | 158 | OSSL_CORE_MAKE_FUNC(int, OP_digest_digest, |
a39eb840 RL |
159 | (void *provctx, const unsigned char *in, size_t inl, |
160 | unsigned char *out, size_t *out_l, size_t outsz)) | |
df05f2ce | 161 | |
a39eb840 RL |
162 | OSSL_CORE_MAKE_FUNC(void, OP_digest_cleanctx, (void *dctx)) |
163 | OSSL_CORE_MAKE_FUNC(void, OP_digest_freectx, (void *dctx)) | |
164 | OSSL_CORE_MAKE_FUNC(void *, OP_digest_dupctx, (void *dctx)) | |
d5e5e2ff | 165 | |
8c8cf0d9 | 166 | OSSL_CORE_MAKE_FUNC(size_t, OP_digest_size, (void)) |
7556b9df | 167 | OSSL_CORE_MAKE_FUNC(size_t, OP_digest_block_size, (void)) |
d5e5e2ff SL |
168 | OSSL_CORE_MAKE_FUNC(int, OP_digest_set_params, |
169 | (void *vctx, const OSSL_PARAM params[])) | |
170 | OSSL_CORE_MAKE_FUNC(int, OP_digest_get_params, | |
4e7991b4 | 171 | (void *vctx, OSSL_PARAM params[])) |
459b15d4 | 172 | OSSL_CORE_MAKE_FUNC(unsigned long, OP_cipher_get_flags, (void)) |
df05f2ce MC |
173 | |
174 | /* Symmetric Ciphers */ | |
175 | ||
176 | # define OSSL_OP_CIPHER 2 | |
177 | ||
178 | # define OSSL_FUNC_CIPHER_NEWCTX 1 | |
179 | # define OSSL_FUNC_CIPHER_ENCRYPT_INIT 2 | |
180 | # define OSSL_FUNC_CIPHER_DECRYPT_INIT 3 | |
181 | # define OSSL_FUNC_CIPHER_UPDATE 4 | |
182 | # define OSSL_FUNC_CIPHER_FINAL 5 | |
718b133a MC |
183 | # define OSSL_FUNC_CIPHER_CIPHER 6 |
184 | # define OSSL_FUNC_CIPHER_FREECTX 7 | |
185 | # define OSSL_FUNC_CIPHER_DUPCTX 8 | |
80942379 RL |
186 | # define OSSL_FUNC_CIPHER_GET_PARAMS 9 |
187 | # define OSSL_FUNC_CIPHER_CTX_GET_PARAMS 10 | |
188 | # define OSSL_FUNC_CIPHER_CTX_SET_PARAMS 11 | |
df05f2ce | 189 | |
a39eb840 RL |
190 | OSSL_CORE_MAKE_FUNC(void *, OP_cipher_newctx, (void *provctx)) |
191 | OSSL_CORE_MAKE_FUNC(int, OP_cipher_encrypt_init, (void *cctx, | |
df05f2ce | 192 | const unsigned char *key, |
344cfa34 MC |
193 | size_t keylen, |
194 | const unsigned char *iv, | |
195 | size_t ivlen)) | |
a39eb840 | 196 | OSSL_CORE_MAKE_FUNC(int, OP_cipher_decrypt_init, (void *cctx, |
df05f2ce | 197 | const unsigned char *key, |
344cfa34 MC |
198 | size_t keylen, |
199 | const unsigned char *iv, | |
200 | size_t ivlen)) | |
df05f2ce | 201 | OSSL_CORE_MAKE_FUNC(int, OP_cipher_update, |
a39eb840 RL |
202 | (void *cctx, |
203 | unsigned char *out, size_t *outl, size_t outsize, | |
df05f2ce MC |
204 | const unsigned char *in, size_t inl)) |
205 | OSSL_CORE_MAKE_FUNC(int, OP_cipher_final, | |
a39eb840 RL |
206 | (void *cctx, |
207 | unsigned char *out, size_t *outl, size_t outsize)) | |
df05f2ce | 208 | OSSL_CORE_MAKE_FUNC(int, OP_cipher_cipher, |
a39eb840 | 209 | (void *cctx, |
f79858ac RL |
210 | unsigned char *out, size_t *outl, size_t outsize, |
211 | const unsigned char *in, size_t inl)) | |
a39eb840 RL |
212 | OSSL_CORE_MAKE_FUNC(void, OP_cipher_freectx, (void *cctx)) |
213 | OSSL_CORE_MAKE_FUNC(void *, OP_cipher_dupctx, (void *cctx)) | |
4e7991b4 | 214 | OSSL_CORE_MAKE_FUNC(int, OP_cipher_get_params, (OSSL_PARAM params[])) |
a39eb840 | 215 | OSSL_CORE_MAKE_FUNC(int, OP_cipher_ctx_get_params, (void *cctx, |
4e7991b4 | 216 | OSSL_PARAM params[])) |
a39eb840 | 217 | OSSL_CORE_MAKE_FUNC(int, OP_cipher_ctx_set_params, (void *cctx, |
718b133a | 218 | const OSSL_PARAM params[])) |
df05f2ce | 219 | |
a94a3e0d RL |
220 | /*- |
221 | * Key management | |
222 | * | |
223 | * Key domain parameter references can be created in several manners: | |
224 | * - by importing the domain parameter material via an OSSL_PARAM array. | |
225 | * - by generating key domain parameters, given input via an OSSL_PARAM | |
226 | * array. | |
227 | * | |
228 | * Key references can be created in several manners: | |
229 | * - by importing the key material via an OSSL_PARAM array. | |
230 | * - by generating a key, given optional domain parameters and | |
231 | * additional keygen parameters. | |
232 | * If domain parameters are given, they must have been generated using | |
233 | * the domain parameter generator functions. | |
234 | * If the domain parameters comes from a different provider, results | |
235 | * are undefined. | |
236 | * THE CALLER MUST ENSURE THAT CORRECT DOMAIN PARAMETERS ARE USED. | |
237 | * - by loading an internal key, given a binary blob that forms an identity. | |
238 | * THE CALLER MUST ENSURE THAT A CORRECT IDENTITY IS USED. | |
239 | */ | |
240 | ||
241 | # define OSSL_OP_KEYMGMT 10 | |
242 | ||
243 | /* Key domain parameter creation and destruction */ | |
244 | # define OSSL_FUNC_KEYMGMT_IMPORTDOMPARAMS 1 | |
245 | # define OSSL_FUNC_KEYMGMT_GENDOMPARAMS 2 | |
246 | # define OSSL_FUNC_KEYMGMT_FREEDOMPARAMS 3 | |
247 | OSSL_CORE_MAKE_FUNC(void *, OP_keymgmt_importdomparams, | |
248 | (void *provctx, const OSSL_PARAM params[])) | |
249 | OSSL_CORE_MAKE_FUNC(void *, OP_keymgmt_gendomparams, | |
250 | (void *provctx, const OSSL_PARAM params[])) | |
251 | OSSL_CORE_MAKE_FUNC(void, OP_keymgmt_freedomparams, (void *domparams)) | |
252 | ||
253 | /* Key domain parameter export */ | |
254 | # define OSSL_FUNC_KEYMGMT_EXPORTDOMPARAMS 4 | |
255 | OSSL_CORE_MAKE_FUNC(int, OP_keymgmt_exportdomparams, | |
256 | (void *domparams, OSSL_PARAM params[])) | |
257 | ||
258 | /* Key domain parameter discovery */ | |
259 | # define OSSL_FUNC_KEYMGMT_IMPORTDOMPARAM_TYPES 5 | |
260 | # define OSSL_FUNC_KEYMGMT_EXPORTDOMPARAM_TYPES 6 | |
261 | OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_keymgmt_importdomparam_types, | |
262 | (void)) | |
263 | OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_keymgmt_exportdomparam_types, | |
264 | (void)) | |
265 | ||
266 | /* Key creation and destruction */ | |
267 | # define OSSL_FUNC_KEYMGMT_IMPORTKEY 10 | |
268 | # define OSSL_FUNC_KEYMGMT_GENKEY 11 | |
269 | # define OSSL_FUNC_KEYMGMT_LOADKEY 12 | |
270 | # define OSSL_FUNC_KEYMGMT_FREEKEY 13 | |
271 | OSSL_CORE_MAKE_FUNC(void *, OP_keymgmt_importkey, | |
272 | (void *provctx, const OSSL_PARAM params[])) | |
273 | OSSL_CORE_MAKE_FUNC(void *, OP_keymgmt_genkey, | |
274 | (void *provctx, | |
275 | void *domparams, const OSSL_PARAM genkeyparams[])) | |
276 | OSSL_CORE_MAKE_FUNC(void *, OP_keymgmt_loadkey, | |
277 | (void *provctx, void *id, size_t idlen)) | |
278 | OSSL_CORE_MAKE_FUNC(void, OP_keymgmt_freekey, (void *key)) | |
279 | ||
280 | /* Key export */ | |
281 | # define OSSL_FUNC_KEYMGMT_EXPORTKEY 14 | |
282 | OSSL_CORE_MAKE_FUNC(int, OP_keymgmt_exportkey, | |
283 | (void *key, OSSL_PARAM params[])) | |
284 | ||
285 | /* Key discovery */ | |
286 | # define OSSL_FUNC_KEYMGMT_IMPORTKEY_TYPES 15 | |
287 | # define OSSL_FUNC_KEYMGMT_EXPORTKEY_TYPES 16 | |
288 | OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_keymgmt_importkey_types, (void)) | |
289 | OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_keymgmt_exportkey_types, (void)) | |
290 | ||
ff64702b MC |
291 | /* Key Exchange */ |
292 | ||
a94a3e0d | 293 | # define OSSL_OP_KEYEXCH 11 |
ff64702b MC |
294 | |
295 | # define OSSL_FUNC_KEYEXCH_NEWCTX 1 | |
296 | # define OSSL_FUNC_KEYEXCH_INIT 2 | |
297 | # define OSSL_FUNC_KEYEXCH_DERIVE 3 | |
298 | # define OSSL_FUNC_KEYEXCH_SET_PEER 4 | |
299 | # define OSSL_FUNC_KEYEXCH_FREECTX 5 | |
300 | # define OSSL_FUNC_KEYEXCH_DUPCTX 6 | |
35aca9ec | 301 | # define OSSL_FUNC_KEYEXCH_SET_PARAMS 7 |
ff64702b MC |
302 | |
303 | OSSL_CORE_MAKE_FUNC(void *, OP_keyexch_newctx, (void *provctx)) | |
8b84b075 | 304 | OSSL_CORE_MAKE_FUNC(int, OP_keyexch_init, (void *ctx, void *provkey)) |
ff64702b MC |
305 | OSSL_CORE_MAKE_FUNC(int, OP_keyexch_derive, (void *ctx, unsigned char *key, |
306 | size_t *keylen, size_t outlen)) | |
8b84b075 | 307 | OSSL_CORE_MAKE_FUNC(int, OP_keyexch_set_peer, (void *ctx, void *provkey)) |
ff64702b MC |
308 | OSSL_CORE_MAKE_FUNC(void, OP_keyexch_freectx, (void *ctx)) |
309 | OSSL_CORE_MAKE_FUNC(void *, OP_keyexch_dupctx, (void *ctx)) | |
35aca9ec | 310 | OSSL_CORE_MAKE_FUNC(int, OP_keyexch_set_params, (void *ctx, |
8b84b075 | 311 | const OSSL_PARAM params[])) |
ff64702b | 312 | |
a883c02f RL |
313 | /* Highest known operation number */ |
314 | # define OSSL_OP__HIGHEST 3 | |
315 | ||
4c2883a9 RL |
316 | # ifdef __cplusplus |
317 | } | |
318 | # endif | |
319 | ||
320 | #endif |