]> git.ipfire.org Git - thirdparty/openssl.git/blame - include/openssl/core_numbers.h
Prepare EVP_MAC infrastructure for moving all MACs to providers
[thirdparty/openssl.git] / include / openssl / core_numbers.h
CommitLineData
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
17extern "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 */
dca97d00 60# define OSSL_FUNC_CORE_GETTABLE_PARAMS 1
26175013 61OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *,
dca97d00 62 core_gettable_params,(const OSSL_PROVIDER *prov))
4c2883a9
RL
63# define OSSL_FUNC_CORE_GET_PARAMS 2
64OSSL_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
67OSSL_CORE_MAKE_FUNC(int,core_thread_start,(const OSSL_PROVIDER *prov,
68 OSSL_thread_stop_handler_fn handfn))
49c64346 69# define OSSL_FUNC_CORE_GET_LIBRARY_CONTEXT 4
e7706e63
RL
70OSSL_CORE_MAKE_FUNC(OPENSSL_CTX *,core_get_library_context,
71 (const OSSL_PROVIDER *prov))
49c64346
RL
72# define OSSL_FUNC_CORE_NEW_ERROR 5
73OSSL_CORE_MAKE_FUNC(void,core_new_error,(const OSSL_PROVIDER *prov))
74# define OSSL_FUNC_CORE_SET_ERROR_DEBUG 6
75OSSL_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
79OSSL_CORE_MAKE_FUNC(void,core_vset_error,
80 (const OSSL_PROVIDER *prov,
81 uint32_t reason, const char *fmt, va_list args))
4c2883a9 82
b60cba3c
RS
83/* Memory allocation, freeing, clearing. */
84#define OSSL_FUNC_CRYPTO_MALLOC 10
85OSSL_CORE_MAKE_FUNC(void *,
86 CRYPTO_malloc, (size_t num, const char *file, int line))
87#define OSSL_FUNC_CRYPTO_ZALLOC 11
88OSSL_CORE_MAKE_FUNC(void *,
89 CRYPTO_zalloc, (size_t num, const char *file, int line))
037439c4 90#define OSSL_FUNC_CRYPTO_FREE 12
b60cba3c
RS
91OSSL_CORE_MAKE_FUNC(void,
92 CRYPTO_free, (void *ptr, const char *file, int line))
037439c4 93#define OSSL_FUNC_CRYPTO_CLEAR_FREE 13
b60cba3c
RS
94OSSL_CORE_MAKE_FUNC(void,
95 CRYPTO_clear_free, (void *ptr, size_t num, const char *file, int line))
037439c4 96#define OSSL_FUNC_CRYPTO_REALLOC 14
b60cba3c
RS
97OSSL_CORE_MAKE_FUNC(void *,
98 CRYPTO_realloc, (void *addr, size_t num, const char *file, int line))
037439c4 99#define OSSL_FUNC_CRYPTO_CLEAR_REALLOC 15
b60cba3c
RS
100OSSL_CORE_MAKE_FUNC(void *,
101 CRYPTO_clear_realloc, (void *addr, size_t old_num, size_t num, const char *file, int line))
037439c4 102#define OSSL_FUNC_CRYPTO_SECURE_MALLOC 16
b60cba3c
RS
103OSSL_CORE_MAKE_FUNC(void *,
104 CRYPTO_secure_malloc, (size_t num, const char *file, int line))
037439c4 105#define OSSL_FUNC_CRYPTO_SECURE_ZALLOC 17
b60cba3c
RS
106OSSL_CORE_MAKE_FUNC(void *,
107 CRYPTO_secure_zalloc, (size_t num, const char *file, int line))
037439c4 108#define OSSL_FUNC_CRYPTO_SECURE_FREE 18
b60cba3c
RS
109OSSL_CORE_MAKE_FUNC(void,
110 CRYPTO_secure_free, (void *ptr, const char *file, int line))
037439c4 111#define OSSL_FUNC_CRYPTO_SECURE_CLEAR_FREE 19
b60cba3c
RS
112OSSL_CORE_MAKE_FUNC(void,
113 CRYPTO_secure_clear_free, (void *ptr, size_t num, const char *file, int line))
037439c4 114#define OSSL_FUNC_CRYPTO_SECURE_ALLOCATED 20
b60cba3c
RS
115OSSL_CORE_MAKE_FUNC(int,
116 CRYPTO_secure_allocated, (const void *ptr))
037439c4 117#define OSSL_FUNC_OPENSSL_CLEANSE 21
b60cba3c
RS
118OSSL_CORE_MAKE_FUNC(void,
119 OPENSSL_cleanse, (void *ptr, size_t len))
b60cba3c 120
4c2883a9
RL
121/* Functions provided by the provider to the Core, reserved numbers 1024-1535 */
122# define OSSL_FUNC_PROVIDER_TEARDOWN 1024
a39eb840 123OSSL_CORE_MAKE_FUNC(void,provider_teardown,(void *provctx))
dca97d00 124# define OSSL_FUNC_PROVIDER_GETTABLE_PARAMS 1025
26175013 125OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *,
dca97d00 126 provider_gettable_params,(void *provctx))
4c2883a9 127# define OSSL_FUNC_PROVIDER_GET_PARAMS 1026
a39eb840 128OSSL_CORE_MAKE_FUNC(int,provider_get_params,(void *provctx,
4e7991b4 129 OSSL_PARAM params[]))
099bd339
RL
130# define OSSL_FUNC_PROVIDER_QUERY_OPERATION 1027
131OSSL_CORE_MAKE_FUNC(const OSSL_ALGORITHM *,provider_query_operation,
a39eb840 132 (void *provctx, int operation_id, const int *no_store))
6ebc2f56
RL
133# define OSSL_FUNC_PROVIDER_GET_REASON_STRINGS 1028
134OSSL_CORE_MAKE_FUNC(const OSSL_ITEM *,provider_get_reason_strings,
135 (void *provctx))
4c2883a9 136
3653d0c2
MC
137/* Digests */
138
2893111f
RL
139# define OSSL_OP_DIGEST 1
140
141# define OSSL_FUNC_DIGEST_NEWCTX 1
142# define OSSL_FUNC_DIGEST_INIT 2
143# define OSSL_FUNC_DIGEST_UPDATE 3
144# define OSSL_FUNC_DIGEST_FINAL 4
145# define OSSL_FUNC_DIGEST_DIGEST 5
146# define OSSL_FUNC_DIGEST_FREECTX 6
147# define OSSL_FUNC_DIGEST_DUPCTX 7
148# define OSSL_FUNC_DIGEST_GET_PARAMS 8
149# define OSSL_FUNC_DIGEST_CTX_SET_PARAMS 9
150# define OSSL_FUNC_DIGEST_CTX_GET_PARAMS 10
ae3ff60e
RL
151# define OSSL_FUNC_DIGEST_GETTABLE_PARAMS 11
152# define OSSL_FUNC_DIGEST_SETTABLE_CTX_PARAMS 12
153# define OSSL_FUNC_DIGEST_GETTABLE_CTX_PARAMS 13
df05f2ce 154
a39eb840
RL
155OSSL_CORE_MAKE_FUNC(void *, OP_digest_newctx, (void *provctx))
156OSSL_CORE_MAKE_FUNC(int, OP_digest_init, (void *dctx))
3653d0c2 157OSSL_CORE_MAKE_FUNC(int, OP_digest_update,
a39eb840 158 (void *dctx, const unsigned char *in, size_t inl))
3653d0c2 159OSSL_CORE_MAKE_FUNC(int, OP_digest_final,
a39eb840
RL
160 (void *dctx,
161 unsigned char *out, size_t *outl, size_t outsz))
3653d0c2 162OSSL_CORE_MAKE_FUNC(int, OP_digest_digest,
a39eb840 163 (void *provctx, const unsigned char *in, size_t inl,
8ccf2ffb 164 unsigned char *out, size_t *outl, size_t outsz))
df05f2ce 165
a39eb840
RL
166OSSL_CORE_MAKE_FUNC(void, OP_digest_freectx, (void *dctx))
167OSSL_CORE_MAKE_FUNC(void *, OP_digest_dupctx, (void *dctx))
d5e5e2ff 168
2893111f
RL
169OSSL_CORE_MAKE_FUNC(int, OP_digest_get_params, (OSSL_PARAM params[]))
170OSSL_CORE_MAKE_FUNC(int, OP_digest_ctx_set_params,
171 (void *vctx, const OSSL_PARAM params[]))
172OSSL_CORE_MAKE_FUNC(int, OP_digest_ctx_get_params,
173 (void *vctx, OSSL_PARAM params[]))
ae3ff60e
RL
174OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_digest_gettable_params, (void))
175OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_digest_settable_ctx_params, (void))
176OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_digest_gettable_ctx_params, (void))
df05f2ce
MC
177
178/* Symmetric Ciphers */
179
180# define OSSL_OP_CIPHER 2
181
182# define OSSL_FUNC_CIPHER_NEWCTX 1
183# define OSSL_FUNC_CIPHER_ENCRYPT_INIT 2
184# define OSSL_FUNC_CIPHER_DECRYPT_INIT 3
185# define OSSL_FUNC_CIPHER_UPDATE 4
186# define OSSL_FUNC_CIPHER_FINAL 5
718b133a
MC
187# define OSSL_FUNC_CIPHER_CIPHER 6
188# define OSSL_FUNC_CIPHER_FREECTX 7
189# define OSSL_FUNC_CIPHER_DUPCTX 8
80942379
RL
190# define OSSL_FUNC_CIPHER_GET_PARAMS 9
191# define OSSL_FUNC_CIPHER_CTX_GET_PARAMS 10
192# define OSSL_FUNC_CIPHER_CTX_SET_PARAMS 11
ae3ff60e
RL
193# define OSSL_FUNC_CIPHER_GETTABLE_PARAMS 12
194# define OSSL_FUNC_CIPHER_GETTABLE_CTX_PARAMS 13
195# define OSSL_FUNC_CIPHER_SETTABLE_CTX_PARAMS 14
df05f2ce 196
a39eb840
RL
197OSSL_CORE_MAKE_FUNC(void *, OP_cipher_newctx, (void *provctx))
198OSSL_CORE_MAKE_FUNC(int, OP_cipher_encrypt_init, (void *cctx,
df05f2ce 199 const unsigned char *key,
344cfa34
MC
200 size_t keylen,
201 const unsigned char *iv,
202 size_t ivlen))
a39eb840 203OSSL_CORE_MAKE_FUNC(int, OP_cipher_decrypt_init, (void *cctx,
df05f2ce 204 const unsigned char *key,
344cfa34
MC
205 size_t keylen,
206 const unsigned char *iv,
207 size_t ivlen))
df05f2ce 208OSSL_CORE_MAKE_FUNC(int, OP_cipher_update,
a39eb840
RL
209 (void *cctx,
210 unsigned char *out, size_t *outl, size_t outsize,
df05f2ce
MC
211 const unsigned char *in, size_t inl))
212OSSL_CORE_MAKE_FUNC(int, OP_cipher_final,
a39eb840
RL
213 (void *cctx,
214 unsigned char *out, size_t *outl, size_t outsize))
df05f2ce 215OSSL_CORE_MAKE_FUNC(int, OP_cipher_cipher,
a39eb840 216 (void *cctx,
f79858ac
RL
217 unsigned char *out, size_t *outl, size_t outsize,
218 const unsigned char *in, size_t inl))
a39eb840
RL
219OSSL_CORE_MAKE_FUNC(void, OP_cipher_freectx, (void *cctx))
220OSSL_CORE_MAKE_FUNC(void *, OP_cipher_dupctx, (void *cctx))
4e7991b4 221OSSL_CORE_MAKE_FUNC(int, OP_cipher_get_params, (OSSL_PARAM params[]))
a39eb840 222OSSL_CORE_MAKE_FUNC(int, OP_cipher_ctx_get_params, (void *cctx,
4e7991b4 223 OSSL_PARAM params[]))
a39eb840 224OSSL_CORE_MAKE_FUNC(int, OP_cipher_ctx_set_params, (void *cctx,
718b133a 225 const OSSL_PARAM params[]))
ae3ff60e
RL
226OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_cipher_gettable_params,
227 (void))
228OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_cipher_settable_ctx_params,
229 (void))
230OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_cipher_gettable_ctx_params,
231 (void))
df05f2ce 232
e74bd290
RL
233/* MACs */
234
235# define OSSL_OP_MAC 3
236
237# define OSSL_FUNC_MAC_NEWCTX 1
238# define OSSL_FUNC_MAC_DUPCTX 2
239# define OSSL_FUNC_MAC_FREECTX 3
240# define OSSL_FUNC_MAC_INIT 4
241# define OSSL_FUNC_MAC_UPDATE 5
242# define OSSL_FUNC_MAC_FINAL 6
243# define OSSL_FUNC_MAC_GETTABLE_PARAMS 7
244# define OSSL_FUNC_MAC_GETTABLE_CTX_PARAMS 8
245# define OSSL_FUNC_MAC_SETTABLE_CTX_PARAMS 9
246# define OSSL_FUNC_MAC_GET_PARAMS 10
247# define OSSL_FUNC_MAC_CTX_GET_PARAMS 11
248# define OSSL_FUNC_MAC_CTX_SET_PARAMS 12
249
250OSSL_CORE_MAKE_FUNC(void *, OP_mac_newctx, (void *provctx))
251OSSL_CORE_MAKE_FUNC(void *, OP_mac_dupctx, (void *src))
252OSSL_CORE_MAKE_FUNC(void, OP_mac_freectx, (void *mctx))
253OSSL_CORE_MAKE_FUNC(size_t, OP_mac_size, (void *mctx))
254OSSL_CORE_MAKE_FUNC(int, OP_mac_init, (void *mctx))
255OSSL_CORE_MAKE_FUNC(int, OP_mac_update,
256 (void *mctx, const unsigned char *in, size_t inl))
257OSSL_CORE_MAKE_FUNC(int, OP_mac_final,
258 (void *mctx,
259 unsigned char *out, size_t *outl, size_t outsize))
260OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_mac_gettable_params, (void))
261OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_mac_gettable_ctx_params, (void))
262OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_mac_settable_ctx_params, (void))
263OSSL_CORE_MAKE_FUNC(int, OP_mac_get_params, (OSSL_PARAM params[]))
264OSSL_CORE_MAKE_FUNC(int, OP_mac_ctx_get_params,
265 (void *mctx, OSSL_PARAM params[]))
266OSSL_CORE_MAKE_FUNC(int, OP_mac_ctx_set_params,
267 (void *mctx, const OSSL_PARAM params[]))
268
a94a3e0d
RL
269/*-
270 * Key management
271 *
272 * Key domain parameter references can be created in several manners:
273 * - by importing the domain parameter material via an OSSL_PARAM array.
274 * - by generating key domain parameters, given input via an OSSL_PARAM
275 * array.
276 *
277 * Key references can be created in several manners:
278 * - by importing the key material via an OSSL_PARAM array.
279 * - by generating a key, given optional domain parameters and
280 * additional keygen parameters.
281 * If domain parameters are given, they must have been generated using
282 * the domain parameter generator functions.
283 * If the domain parameters comes from a different provider, results
284 * are undefined.
285 * THE CALLER MUST ENSURE THAT CORRECT DOMAIN PARAMETERS ARE USED.
286 * - by loading an internal key, given a binary blob that forms an identity.
287 * THE CALLER MUST ENSURE THAT A CORRECT IDENTITY IS USED.
288 */
289
290# define OSSL_OP_KEYMGMT 10
291
292/* Key domain parameter creation and destruction */
293# define OSSL_FUNC_KEYMGMT_IMPORTDOMPARAMS 1
294# define OSSL_FUNC_KEYMGMT_GENDOMPARAMS 2
295# define OSSL_FUNC_KEYMGMT_FREEDOMPARAMS 3
296OSSL_CORE_MAKE_FUNC(void *, OP_keymgmt_importdomparams,
297 (void *provctx, const OSSL_PARAM params[]))
298OSSL_CORE_MAKE_FUNC(void *, OP_keymgmt_gendomparams,
299 (void *provctx, const OSSL_PARAM params[]))
300OSSL_CORE_MAKE_FUNC(void, OP_keymgmt_freedomparams, (void *domparams))
301
302/* Key domain parameter export */
303# define OSSL_FUNC_KEYMGMT_EXPORTDOMPARAMS 4
304OSSL_CORE_MAKE_FUNC(int, OP_keymgmt_exportdomparams,
305 (void *domparams, OSSL_PARAM params[]))
306
307/* Key domain parameter discovery */
308# define OSSL_FUNC_KEYMGMT_IMPORTDOMPARAM_TYPES 5
309# define OSSL_FUNC_KEYMGMT_EXPORTDOMPARAM_TYPES 6
310OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_keymgmt_importdomparam_types,
311 (void))
312OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_keymgmt_exportdomparam_types,
313 (void))
314
315/* Key creation and destruction */
316# define OSSL_FUNC_KEYMGMT_IMPORTKEY 10
317# define OSSL_FUNC_KEYMGMT_GENKEY 11
318# define OSSL_FUNC_KEYMGMT_LOADKEY 12
319# define OSSL_FUNC_KEYMGMT_FREEKEY 13
320OSSL_CORE_MAKE_FUNC(void *, OP_keymgmt_importkey,
321 (void *provctx, const OSSL_PARAM params[]))
322OSSL_CORE_MAKE_FUNC(void *, OP_keymgmt_genkey,
323 (void *provctx,
324 void *domparams, const OSSL_PARAM genkeyparams[]))
325OSSL_CORE_MAKE_FUNC(void *, OP_keymgmt_loadkey,
326 (void *provctx, void *id, size_t idlen))
327OSSL_CORE_MAKE_FUNC(void, OP_keymgmt_freekey, (void *key))
328
329/* Key export */
330# define OSSL_FUNC_KEYMGMT_EXPORTKEY 14
331OSSL_CORE_MAKE_FUNC(int, OP_keymgmt_exportkey,
332 (void *key, OSSL_PARAM params[]))
333
334/* Key discovery */
335# define OSSL_FUNC_KEYMGMT_IMPORTKEY_TYPES 15
336# define OSSL_FUNC_KEYMGMT_EXPORTKEY_TYPES 16
337OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_keymgmt_importkey_types, (void))
338OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_keymgmt_exportkey_types, (void))
339
ff64702b
MC
340/* Key Exchange */
341
a94a3e0d 342# define OSSL_OP_KEYEXCH 11
ff64702b
MC
343
344# define OSSL_FUNC_KEYEXCH_NEWCTX 1
345# define OSSL_FUNC_KEYEXCH_INIT 2
346# define OSSL_FUNC_KEYEXCH_DERIVE 3
347# define OSSL_FUNC_KEYEXCH_SET_PEER 4
348# define OSSL_FUNC_KEYEXCH_FREECTX 5
349# define OSSL_FUNC_KEYEXCH_DUPCTX 6
35aca9ec 350# define OSSL_FUNC_KEYEXCH_SET_PARAMS 7
ff64702b
MC
351
352OSSL_CORE_MAKE_FUNC(void *, OP_keyexch_newctx, (void *provctx))
8b84b075 353OSSL_CORE_MAKE_FUNC(int, OP_keyexch_init, (void *ctx, void *provkey))
59972370
MC
354OSSL_CORE_MAKE_FUNC(int, OP_keyexch_derive, (void *ctx, unsigned char *secret,
355 size_t *secretlen, size_t outlen))
8b84b075 356OSSL_CORE_MAKE_FUNC(int, OP_keyexch_set_peer, (void *ctx, void *provkey))
ff64702b
MC
357OSSL_CORE_MAKE_FUNC(void, OP_keyexch_freectx, (void *ctx))
358OSSL_CORE_MAKE_FUNC(void *, OP_keyexch_dupctx, (void *ctx))
35aca9ec 359OSSL_CORE_MAKE_FUNC(int, OP_keyexch_set_params, (void *ctx,
8b84b075 360 const OSSL_PARAM params[]))
ff64702b 361
a883c02f
RL
362/* Highest known operation number */
363# define OSSL_OP__HIGHEST 3
364
4c2883a9
RL
365# ifdef __cplusplus
366}
367# endif
368
369#endif