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_GETTABLE_PARAMS 1
61 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM
*,
62 core_gettable_params
,(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_GET_LIBRARY_CONTEXT 4
70 OSSL_CORE_MAKE_FUNC(OPENSSL_CTX
*,core_get_library_context
,
71 (const OSSL_PROVIDER
*prov
))
72 # define OSSL_FUNC_CORE_NEW_ERROR 5
73 OSSL_CORE_MAKE_FUNC(void,core_new_error
,(const OSSL_PROVIDER
*prov
))
74 # define OSSL_FUNC_CORE_SET_ERROR_DEBUG 6
75 OSSL_CORE_MAKE_FUNC(void,core_set_error_debug
,
76 (const OSSL_PROVIDER
*prov
,
77 const char *file
, int line
, const char *func
))
78 # define OSSL_FUNC_CORE_VSET_ERROR 7
79 OSSL_CORE_MAKE_FUNC(void,core_vset_error
,
80 (const OSSL_PROVIDER
*prov
,
81 uint32_t reason
, const char *fmt
, va_list args
))
83 /* Memory allocation, freeing, clearing. */
84 #define OSSL_FUNC_CRYPTO_MALLOC 10
85 OSSL_CORE_MAKE_FUNC(void *,
86 CRYPTO_malloc
, (size_t num
, const char *file
, int line
))
87 #define OSSL_FUNC_CRYPTO_ZALLOC 11
88 OSSL_CORE_MAKE_FUNC(void *,
89 CRYPTO_zalloc
, (size_t num
, const char *file
, int line
))
90 #define OSSL_FUNC_CRYPTO_FREE 12
91 OSSL_CORE_MAKE_FUNC(void,
92 CRYPTO_free
, (void *ptr
, const char *file
, int line
))
93 #define OSSL_FUNC_CRYPTO_CLEAR_FREE 13
94 OSSL_CORE_MAKE_FUNC(void,
95 CRYPTO_clear_free
, (void *ptr
, size_t num
, const char *file
, int line
))
96 #define OSSL_FUNC_CRYPTO_REALLOC 14
97 OSSL_CORE_MAKE_FUNC(void *,
98 CRYPTO_realloc
, (void *addr
, size_t num
, const char *file
, int line
))
99 #define OSSL_FUNC_CRYPTO_CLEAR_REALLOC 15
100 OSSL_CORE_MAKE_FUNC(void *,
101 CRYPTO_clear_realloc
, (void *addr
, size_t old_num
, size_t num
,
102 const char *file
, int line
))
103 #define OSSL_FUNC_CRYPTO_SECURE_MALLOC 16
104 OSSL_CORE_MAKE_FUNC(void *,
105 CRYPTO_secure_malloc
, (size_t num
, const char *file
, int line
))
106 #define OSSL_FUNC_CRYPTO_SECURE_ZALLOC 17
107 OSSL_CORE_MAKE_FUNC(void *,
108 CRYPTO_secure_zalloc
, (size_t num
, const char *file
, int line
))
109 #define OSSL_FUNC_CRYPTO_SECURE_FREE 18
110 OSSL_CORE_MAKE_FUNC(void,
111 CRYPTO_secure_free
, (void *ptr
, const char *file
, int line
))
112 #define OSSL_FUNC_CRYPTO_SECURE_CLEAR_FREE 19
113 OSSL_CORE_MAKE_FUNC(void,
114 CRYPTO_secure_clear_free
, (void *ptr
, size_t num
, const char *file
,
116 #define OSSL_FUNC_CRYPTO_SECURE_ALLOCATED 20
117 OSSL_CORE_MAKE_FUNC(int,
118 CRYPTO_secure_allocated
, (const void *ptr
))
119 #define OSSL_FUNC_OPENSSL_CLEANSE 21
120 OSSL_CORE_MAKE_FUNC(void,
121 OPENSSL_cleanse
, (void *ptr
, size_t len
))
123 /* Bio functions provided by the core */
124 #define OSSL_FUNC_BIO_NEW_FILE 22
125 #define OSSL_FUNC_BIO_NEW_MEMBUF 23
126 #define OSSL_FUNC_BIO_READ 24
127 #define OSSL_FUNC_BIO_FREE 25
129 OSSL_CORE_MAKE_FUNC(BIO
*, BIO_new_file
, (const char *filename
, const char *mode
))
130 OSSL_CORE_MAKE_FUNC(BIO
*, BIO_new_membuf
, (const void *buf
, int len
))
131 OSSL_CORE_MAKE_FUNC(int, BIO_read
, (BIO
*bio
, void *data
, size_t data_len
,
133 OSSL_CORE_MAKE_FUNC(int, BIO_free
, (BIO
*bio
))
135 /* Functions provided by the provider to the Core, reserved numbers 1024-1535 */
136 # define OSSL_FUNC_PROVIDER_TEARDOWN 1024
137 OSSL_CORE_MAKE_FUNC(void,provider_teardown
,(void *provctx
))
138 # define OSSL_FUNC_PROVIDER_GETTABLE_PARAMS 1025
139 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM
*,
140 provider_gettable_params
,(void *provctx
))
141 # define OSSL_FUNC_PROVIDER_GET_PARAMS 1026
142 OSSL_CORE_MAKE_FUNC(int,provider_get_params
,(void *provctx
,
143 OSSL_PARAM params
[]))
144 # define OSSL_FUNC_PROVIDER_QUERY_OPERATION 1027
145 OSSL_CORE_MAKE_FUNC(const OSSL_ALGORITHM
*,provider_query_operation
,
146 (void *provctx
, int operation_id
, const int *no_store
))
147 # define OSSL_FUNC_PROVIDER_GET_REASON_STRINGS 1028
148 OSSL_CORE_MAKE_FUNC(const OSSL_ITEM
*,provider_get_reason_strings
,
153 # define OSSL_OP_DIGEST 1
154 # define OSSL_OP_CIPHER 2 /* Symmetric Ciphers */
155 # define OSSL_OP_MAC 3
156 # define OSSL_OP_KEYMGMT 10
157 # define OSSL_OP_KEYEXCH 11
158 /* Highest known operation number */
159 # define OSSL_OP__HIGHEST 11
163 # define OSSL_FUNC_DIGEST_NEWCTX 1
164 # define OSSL_FUNC_DIGEST_INIT 2
165 # define OSSL_FUNC_DIGEST_UPDATE 3
166 # define OSSL_FUNC_DIGEST_FINAL 4
167 # define OSSL_FUNC_DIGEST_DIGEST 5
168 # define OSSL_FUNC_DIGEST_FREECTX 6
169 # define OSSL_FUNC_DIGEST_DUPCTX 7
170 # define OSSL_FUNC_DIGEST_GET_PARAMS 8
171 # define OSSL_FUNC_DIGEST_SET_CTX_PARAMS 9
172 # define OSSL_FUNC_DIGEST_GET_CTX_PARAMS 10
173 # define OSSL_FUNC_DIGEST_GETTABLE_PARAMS 11
174 # define OSSL_FUNC_DIGEST_SETTABLE_CTX_PARAMS 12
175 # define OSSL_FUNC_DIGEST_GETTABLE_CTX_PARAMS 13
177 OSSL_CORE_MAKE_FUNC(void *, OP_digest_newctx
, (void *provctx
))
178 OSSL_CORE_MAKE_FUNC(int, OP_digest_init
, (void *dctx
))
179 OSSL_CORE_MAKE_FUNC(int, OP_digest_update
,
180 (void *dctx
, const unsigned char *in
, size_t inl
))
181 OSSL_CORE_MAKE_FUNC(int, OP_digest_final
,
183 unsigned char *out
, size_t *outl
, size_t outsz
))
184 OSSL_CORE_MAKE_FUNC(int, OP_digest_digest
,
185 (void *provctx
, const unsigned char *in
, size_t inl
,
186 unsigned char *out
, size_t *outl
, size_t outsz
))
188 OSSL_CORE_MAKE_FUNC(void, OP_digest_freectx
, (void *dctx
))
189 OSSL_CORE_MAKE_FUNC(void *, OP_digest_dupctx
, (void *dctx
))
191 OSSL_CORE_MAKE_FUNC(int, OP_digest_get_params
, (OSSL_PARAM params
[]))
192 OSSL_CORE_MAKE_FUNC(int, OP_digest_set_ctx_params
,
193 (void *vctx
, const OSSL_PARAM params
[]))
194 OSSL_CORE_MAKE_FUNC(int, OP_digest_get_ctx_params
,
195 (void *vctx
, OSSL_PARAM params
[]))
196 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM
*, OP_digest_gettable_params
, (void))
197 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM
*, OP_digest_settable_ctx_params
, (void))
198 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM
*, OP_digest_gettable_ctx_params
, (void))
200 /* Symmetric Ciphers */
202 # define OSSL_FUNC_CIPHER_NEWCTX 1
203 # define OSSL_FUNC_CIPHER_ENCRYPT_INIT 2
204 # define OSSL_FUNC_CIPHER_DECRYPT_INIT 3
205 # define OSSL_FUNC_CIPHER_UPDATE 4
206 # define OSSL_FUNC_CIPHER_FINAL 5
207 # define OSSL_FUNC_CIPHER_CIPHER 6
208 # define OSSL_FUNC_CIPHER_FREECTX 7
209 # define OSSL_FUNC_CIPHER_DUPCTX 8
210 # define OSSL_FUNC_CIPHER_GET_PARAMS 9
211 # define OSSL_FUNC_CIPHER_GET_CTX_PARAMS 10
212 # define OSSL_FUNC_CIPHER_SET_CTX_PARAMS 11
213 # define OSSL_FUNC_CIPHER_GETTABLE_PARAMS 12
214 # define OSSL_FUNC_CIPHER_GETTABLE_CTX_PARAMS 13
215 # define OSSL_FUNC_CIPHER_SETTABLE_CTX_PARAMS 14
217 OSSL_CORE_MAKE_FUNC(void *, OP_cipher_newctx
, (void *provctx
))
218 OSSL_CORE_MAKE_FUNC(int, OP_cipher_encrypt_init
, (void *cctx
,
219 const unsigned char *key
,
221 const unsigned char *iv
,
223 OSSL_CORE_MAKE_FUNC(int, OP_cipher_decrypt_init
, (void *cctx
,
224 const unsigned char *key
,
226 const unsigned char *iv
,
228 OSSL_CORE_MAKE_FUNC(int, OP_cipher_update
,
230 unsigned char *out
, size_t *outl
, size_t outsize
,
231 const unsigned char *in
, size_t inl
))
232 OSSL_CORE_MAKE_FUNC(int, OP_cipher_final
,
234 unsigned char *out
, size_t *outl
, size_t outsize
))
235 OSSL_CORE_MAKE_FUNC(int, OP_cipher_cipher
,
237 unsigned char *out
, size_t *outl
, size_t outsize
,
238 const unsigned char *in
, size_t inl
))
239 OSSL_CORE_MAKE_FUNC(void, OP_cipher_freectx
, (void *cctx
))
240 OSSL_CORE_MAKE_FUNC(void *, OP_cipher_dupctx
, (void *cctx
))
241 OSSL_CORE_MAKE_FUNC(int, OP_cipher_get_params
, (OSSL_PARAM params
[]))
242 OSSL_CORE_MAKE_FUNC(int, OP_cipher_get_ctx_params
, (void *cctx
,
243 OSSL_PARAM params
[]))
244 OSSL_CORE_MAKE_FUNC(int, OP_cipher_set_ctx_params
, (void *cctx
,
245 const OSSL_PARAM params
[]))
246 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM
*, OP_cipher_gettable_params
, (void))
247 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM
*, OP_cipher_settable_ctx_params
, (void))
248 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM
*, OP_cipher_gettable_ctx_params
, (void))
252 # define OSSL_FUNC_MAC_NEWCTX 1
253 # define OSSL_FUNC_MAC_DUPCTX 2
254 # define OSSL_FUNC_MAC_FREECTX 3
255 # define OSSL_FUNC_MAC_INIT 4
256 # define OSSL_FUNC_MAC_UPDATE 5
257 # define OSSL_FUNC_MAC_FINAL 6
258 # define OSSL_FUNC_MAC_GET_PARAMS 7
259 # define OSSL_FUNC_MAC_GET_CTX_PARAMS 8
260 # define OSSL_FUNC_MAC_SET_CTX_PARAMS 9
261 # define OSSL_FUNC_MAC_GETTABLE_PARAMS 10
262 # define OSSL_FUNC_MAC_GETTABLE_CTX_PARAMS 11
263 # define OSSL_FUNC_MAC_SETTABLE_CTX_PARAMS 12
265 OSSL_CORE_MAKE_FUNC(void *, OP_mac_newctx
, (void *provctx
))
266 OSSL_CORE_MAKE_FUNC(void *, OP_mac_dupctx
, (void *src
))
267 OSSL_CORE_MAKE_FUNC(void, OP_mac_freectx
, (void *mctx
))
268 OSSL_CORE_MAKE_FUNC(size_t, OP_mac_size
, (void *mctx
))
269 OSSL_CORE_MAKE_FUNC(int, OP_mac_init
, (void *mctx
))
270 OSSL_CORE_MAKE_FUNC(int, OP_mac_update
,
271 (void *mctx
, const unsigned char *in
, size_t inl
))
272 OSSL_CORE_MAKE_FUNC(int, OP_mac_final
,
274 unsigned char *out
, size_t *outl
, size_t outsize
))
275 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM
*, OP_mac_gettable_params
, (void))
276 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM
*, OP_mac_gettable_ctx_params
, (void))
277 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM
*, OP_mac_settable_ctx_params
, (void))
278 OSSL_CORE_MAKE_FUNC(int, OP_mac_get_params
, (OSSL_PARAM params
[]))
279 OSSL_CORE_MAKE_FUNC(int, OP_mac_get_ctx_params
,
280 (void *mctx
, OSSL_PARAM params
[]))
281 OSSL_CORE_MAKE_FUNC(int, OP_mac_set_ctx_params
,
282 (void *mctx
, const OSSL_PARAM params
[]))
285 # define OSSL_OP_KDF 4
287 # define OSSL_FUNC_KDF_NEWCTX 1
288 # define OSSL_FUNC_KDF_DUPCTX 2
289 # define OSSL_FUNC_KDF_FREECTX 3
290 # define OSSL_FUNC_KDF_RESET 4
291 # define OSSL_FUNC_KDF_DERIVE 5
292 # define OSSL_FUNC_KDF_GETTABLE_PARAMS 6
293 # define OSSL_FUNC_KDF_GETTABLE_CTX_PARAMS 7
294 # define OSSL_FUNC_KDF_SETTABLE_CTX_PARAMS 8
295 # define OSSL_FUNC_KDF_GET_PARAMS 9
296 # define OSSL_FUNC_KDF_GET_CTX_PARAMS 10
297 # define OSSL_FUNC_KDF_SET_CTX_PARAMS 11
299 OSSL_CORE_MAKE_FUNC(void *, OP_kdf_newctx
, (void *provctx
))
300 OSSL_CORE_MAKE_FUNC(void *, OP_kdf_dupctx
, (void *src
))
301 OSSL_CORE_MAKE_FUNC(void, OP_kdf_freectx
, (void *kctx
))
302 OSSL_CORE_MAKE_FUNC(void, OP_kdf_reset
, (void *kctx
))
303 OSSL_CORE_MAKE_FUNC(int, OP_kdf_derive
, (void *kctx
, unsigned char *key
,
305 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM
*, OP_kdf_gettable_params
, (void))
306 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM
*, OP_kdf_gettable_ctx_params
, (void))
307 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM
*, OP_kdf_settable_ctx_params
, (void))
308 OSSL_CORE_MAKE_FUNC(int, OP_kdf_get_params
, (OSSL_PARAM params
[]))
309 OSSL_CORE_MAKE_FUNC(int, OP_kdf_get_ctx_params
,
310 (void *kctx
, OSSL_PARAM params
[]))
311 OSSL_CORE_MAKE_FUNC(int, OP_kdf_set_ctx_params
,
312 (void *kctx
, const OSSL_PARAM params
[]))
317 * Key domain parameter references can be created in several manners:
318 * - by importing the domain parameter material via an OSSL_PARAM array.
319 * - by generating key domain parameters, given input via an OSSL_PARAM
322 * Key references can be created in several manners:
323 * - by importing the key material via an OSSL_PARAM array.
324 * - by generating a key, given optional domain parameters and
325 * additional keygen parameters.
326 * If domain parameters are given, they must have been generated using
327 * the domain parameter generator functions.
328 * If the domain parameters comes from a different provider, results
330 * THE CALLER MUST ENSURE THAT CORRECT DOMAIN PARAMETERS ARE USED.
331 * - by loading an internal key, given a binary blob that forms an identity.
332 * THE CALLER MUST ENSURE THAT A CORRECT IDENTITY IS USED.
335 /* Key domain parameter creation and destruction */
336 # define OSSL_FUNC_KEYMGMT_IMPORTDOMPARAMS 1
337 # define OSSL_FUNC_KEYMGMT_GENDOMPARAMS 2
338 # define OSSL_FUNC_KEYMGMT_FREEDOMPARAMS 3
339 OSSL_CORE_MAKE_FUNC(void *, OP_keymgmt_importdomparams
,
340 (void *provctx
, const OSSL_PARAM params
[]))
341 OSSL_CORE_MAKE_FUNC(void *, OP_keymgmt_gendomparams
,
342 (void *provctx
, const OSSL_PARAM params
[]))
343 OSSL_CORE_MAKE_FUNC(void, OP_keymgmt_freedomparams
, (void *domparams
))
345 /* Key domain parameter export */
346 # define OSSL_FUNC_KEYMGMT_EXPORTDOMPARAMS 4
347 OSSL_CORE_MAKE_FUNC(int, OP_keymgmt_exportdomparams
,
348 (void *domparams
, OSSL_PARAM params
[]))
350 /* Key domain parameter discovery */
351 # define OSSL_FUNC_KEYMGMT_IMPORTDOMPARAM_TYPES 5
352 # define OSSL_FUNC_KEYMGMT_EXPORTDOMPARAM_TYPES 6
353 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM
*, OP_keymgmt_importdomparam_types
,
355 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM
*, OP_keymgmt_exportdomparam_types
,
358 /* Key creation and destruction */
359 # define OSSL_FUNC_KEYMGMT_IMPORTKEY 10
360 # define OSSL_FUNC_KEYMGMT_GENKEY 11
361 # define OSSL_FUNC_KEYMGMT_LOADKEY 12
362 # define OSSL_FUNC_KEYMGMT_FREEKEY 13
363 OSSL_CORE_MAKE_FUNC(void *, OP_keymgmt_importkey
,
364 (void *provctx
, const OSSL_PARAM params
[]))
365 OSSL_CORE_MAKE_FUNC(void *, OP_keymgmt_genkey
,
367 void *domparams
, const OSSL_PARAM genkeyparams
[]))
368 OSSL_CORE_MAKE_FUNC(void *, OP_keymgmt_loadkey
,
369 (void *provctx
, void *id
, size_t idlen
))
370 OSSL_CORE_MAKE_FUNC(void, OP_keymgmt_freekey
, (void *key
))
373 # define OSSL_FUNC_KEYMGMT_EXPORTKEY 14
374 OSSL_CORE_MAKE_FUNC(int, OP_keymgmt_exportkey
,
375 (void *key
, OSSL_PARAM params
[]))
378 # define OSSL_FUNC_KEYMGMT_IMPORTKEY_TYPES 15
379 # define OSSL_FUNC_KEYMGMT_EXPORTKEY_TYPES 16
380 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM
*, OP_keymgmt_importkey_types
, (void))
381 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM
*, OP_keymgmt_exportkey_types
, (void))
385 # define OSSL_FUNC_KEYEXCH_NEWCTX 1
386 # define OSSL_FUNC_KEYEXCH_INIT 2
387 # define OSSL_FUNC_KEYEXCH_DERIVE 3
388 # define OSSL_FUNC_KEYEXCH_SET_PEER 4
389 # define OSSL_FUNC_KEYEXCH_FREECTX 5
390 # define OSSL_FUNC_KEYEXCH_DUPCTX 6
391 # define OSSL_FUNC_KEYEXCH_SET_PARAMS 7
393 OSSL_CORE_MAKE_FUNC(void *, OP_keyexch_newctx
, (void *provctx
))
394 OSSL_CORE_MAKE_FUNC(int, OP_keyexch_init
, (void *ctx
, void *provkey
))
395 OSSL_CORE_MAKE_FUNC(int, OP_keyexch_derive
, (void *ctx
, unsigned char *secret
,
396 size_t *secretlen
, size_t outlen
))
397 OSSL_CORE_MAKE_FUNC(int, OP_keyexch_set_peer
, (void *ctx
, void *provkey
))
398 OSSL_CORE_MAKE_FUNC(void, OP_keyexch_freectx
, (void *ctx
))
399 OSSL_CORE_MAKE_FUNC(void *, OP_keyexch_dupctx
, (void *ctx
))
400 OSSL_CORE_MAKE_FUNC(int, OP_keyexch_set_params
, (void *ctx
,
401 const OSSL_PARAM params
[]))