]> git.ipfire.org Git - thirdparty/openssl.git/blame - include/openssl/core_numbers.h
Maintain strict type discipline between the core and providers
[thirdparty/openssl.git] / include / openssl / core_numbers.h
CommitLineData
4c2883a9 1/*
33388b44 2 * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
4c2883a9
RL
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
ae4186b0
DMSP
10#ifndef OPENSSL_CORE_NUMBERS_H
11# define OPENSSL_CORE_NUMBERS_H
4c2883a9 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:
79c44b4e 32 * - a macro for the identity with the name OSSL_FUNC_'FOO' or derivatives
4c2883a9
RL
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 *,
d40b42ab 62 core_gettable_params,(const OSSL_CORE_HANDLE *prov))
4c2883a9 63# define OSSL_FUNC_CORE_GET_PARAMS 2
d40b42ab 64OSSL_CORE_MAKE_FUNC(int,core_get_params,(const OSSL_CORE_HANDLE *prov,
4e7991b4 65 OSSL_PARAM params[]))
da747958 66# define OSSL_FUNC_CORE_THREAD_START 3
d40b42ab 67OSSL_CORE_MAKE_FUNC(int,core_thread_start,(const OSSL_CORE_HANDLE *prov,
da747958 68 OSSL_thread_stop_handler_fn handfn))
49c64346 69# define OSSL_FUNC_CORE_GET_LIBRARY_CONTEXT 4
d40b42ab
MC
70OSSL_CORE_MAKE_FUNC(OPENSSL_CORE_CTX *,core_get_library_context,
71 (const OSSL_CORE_HANDLE *prov))
49c64346 72# define OSSL_FUNC_CORE_NEW_ERROR 5
d40b42ab 73OSSL_CORE_MAKE_FUNC(void,core_new_error,(const OSSL_CORE_HANDLE *prov))
49c64346
RL
74# define OSSL_FUNC_CORE_SET_ERROR_DEBUG 6
75OSSL_CORE_MAKE_FUNC(void,core_set_error_debug,
d40b42ab 76 (const OSSL_CORE_HANDLE *prov,
49c64346
RL
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,
d40b42ab 80 (const OSSL_CORE_HANDLE *prov,
49c64346 81 uint32_t reason, const char *fmt, va_list args))
7b131de2 82# define OSSL_FUNC_CORE_SET_ERROR_MARK 8
d40b42ab 83OSSL_CORE_MAKE_FUNC(int, core_set_error_mark, (const OSSL_CORE_HANDLE *prov))
7b131de2
RL
84# define OSSL_FUNC_CORE_CLEAR_LAST_ERROR_MARK 9
85OSSL_CORE_MAKE_FUNC(int, core_clear_last_error_mark,
d40b42ab 86 (const OSSL_CORE_HANDLE *prov))
d16d0b71 87# define OSSL_FUNC_CORE_POP_ERROR_TO_MARK 10
d40b42ab 88OSSL_CORE_MAKE_FUNC(int, core_pop_error_to_mark, (const OSSL_CORE_HANDLE *prov))
4c2883a9 89
b60cba3c 90/* Memory allocation, freeing, clearing. */
7b131de2 91#define OSSL_FUNC_CRYPTO_MALLOC 20
b60cba3c
RS
92OSSL_CORE_MAKE_FUNC(void *,
93 CRYPTO_malloc, (size_t num, const char *file, int line))
7b131de2 94#define OSSL_FUNC_CRYPTO_ZALLOC 21
b60cba3c
RS
95OSSL_CORE_MAKE_FUNC(void *,
96 CRYPTO_zalloc, (size_t num, const char *file, int line))
7b131de2 97#define OSSL_FUNC_CRYPTO_FREE 22
b60cba3c
RS
98OSSL_CORE_MAKE_FUNC(void,
99 CRYPTO_free, (void *ptr, const char *file, int line))
7b131de2 100#define OSSL_FUNC_CRYPTO_CLEAR_FREE 23
b60cba3c
RS
101OSSL_CORE_MAKE_FUNC(void,
102 CRYPTO_clear_free, (void *ptr, size_t num, const char *file, int line))
7b131de2 103#define OSSL_FUNC_CRYPTO_REALLOC 24
b60cba3c
RS
104OSSL_CORE_MAKE_FUNC(void *,
105 CRYPTO_realloc, (void *addr, size_t num, const char *file, int line))
7b131de2 106#define OSSL_FUNC_CRYPTO_CLEAR_REALLOC 25
b60cba3c 107OSSL_CORE_MAKE_FUNC(void *,
784883fc
SL
108 CRYPTO_clear_realloc, (void *addr, size_t old_num, size_t num,
109 const char *file, int line))
7b131de2 110#define OSSL_FUNC_CRYPTO_SECURE_MALLOC 26
b60cba3c
RS
111OSSL_CORE_MAKE_FUNC(void *,
112 CRYPTO_secure_malloc, (size_t num, const char *file, int line))
7b131de2 113#define OSSL_FUNC_CRYPTO_SECURE_ZALLOC 27
b60cba3c
RS
114OSSL_CORE_MAKE_FUNC(void *,
115 CRYPTO_secure_zalloc, (size_t num, const char *file, int line))
7b131de2 116#define OSSL_FUNC_CRYPTO_SECURE_FREE 28
b60cba3c
RS
117OSSL_CORE_MAKE_FUNC(void,
118 CRYPTO_secure_free, (void *ptr, const char *file, int line))
7b131de2 119#define OSSL_FUNC_CRYPTO_SECURE_CLEAR_FREE 29
b60cba3c 120OSSL_CORE_MAKE_FUNC(void,
784883fc
SL
121 CRYPTO_secure_clear_free, (void *ptr, size_t num, const char *file,
122 int line))
7b131de2 123#define OSSL_FUNC_CRYPTO_SECURE_ALLOCATED 30
b60cba3c
RS
124OSSL_CORE_MAKE_FUNC(int,
125 CRYPTO_secure_allocated, (const void *ptr))
7b131de2 126#define OSSL_FUNC_OPENSSL_CLEANSE 31
b60cba3c
RS
127OSSL_CORE_MAKE_FUNC(void,
128 OPENSSL_cleanse, (void *ptr, size_t len))
b60cba3c 129
25e60144 130/* Bio functions provided by the core */
7b131de2
RL
131#define OSSL_FUNC_BIO_NEW_FILE 40
132#define OSSL_FUNC_BIO_NEW_MEMBUF 41
133#define OSSL_FUNC_BIO_READ_EX 42
d40b42ab
MC
134#define OSSL_FUNC_BIO_WRITE_EX 43
135#define OSSL_FUNC_BIO_FREE 44
136#define OSSL_FUNC_BIO_VPRINTF 45
137#define OSSL_FUNC_BIO_VSNPRINTF 46
138
139OSSL_CORE_MAKE_FUNC(OSSL_CORE_BIO *, BIO_new_file, (const char *filename,
140 const char *mode))
141OSSL_CORE_MAKE_FUNC(OSSL_CORE_BIO *, BIO_new_membuf, (const void *buf, int len))
142OSSL_CORE_MAKE_FUNC(int, BIO_read_ex, (OSSL_CORE_BIO *bio, void *data,
143 size_t data_len, size_t *bytes_read))
144OSSL_CORE_MAKE_FUNC(int, BIO_write_ex, (OSSL_CORE_BIO *bio, const void *data,
145 size_t data_len, size_t *written))
146OSSL_CORE_MAKE_FUNC(int, BIO_free, (OSSL_CORE_BIO *bio))
147OSSL_CORE_MAKE_FUNC(int, BIO_vprintf, (OSSL_CORE_BIO *bio, const char *format,
63665fff 148 va_list args))
d16d0b71
SL
149OSSL_CORE_MAKE_FUNC(int, BIO_vsnprintf,
150 (char *buf, size_t n, const char *fmt, va_list args))
25e60144 151
7b131de2 152#define OSSL_FUNC_SELF_TEST_CB 100
d40b42ab 153OSSL_CORE_MAKE_FUNC(void, self_test_cb, (OPENSSL_CORE_CTX *ctx, OSSL_CALLBACK **cb,
36fc5fc6
SL
154 void **cbarg))
155
4c2883a9
RL
156/* Functions provided by the provider to the Core, reserved numbers 1024-1535 */
157# define OSSL_FUNC_PROVIDER_TEARDOWN 1024
a39eb840 158OSSL_CORE_MAKE_FUNC(void,provider_teardown,(void *provctx))
dca97d00 159# define OSSL_FUNC_PROVIDER_GETTABLE_PARAMS 1025
26175013 160OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *,
dca97d00 161 provider_gettable_params,(void *provctx))
4c2883a9 162# define OSSL_FUNC_PROVIDER_GET_PARAMS 1026
a39eb840 163OSSL_CORE_MAKE_FUNC(int,provider_get_params,(void *provctx,
4e7991b4 164 OSSL_PARAM params[]))
099bd339
RL
165# define OSSL_FUNC_PROVIDER_QUERY_OPERATION 1027
166OSSL_CORE_MAKE_FUNC(const OSSL_ALGORITHM *,provider_query_operation,
b0f3c594 167 (void *provctx, int operation_id, int *no_store))
6ebc2f56
RL
168# define OSSL_FUNC_PROVIDER_GET_REASON_STRINGS 1028
169OSSL_CORE_MAKE_FUNC(const OSSL_ITEM *,provider_get_reason_strings,
170 (void *provctx))
4c2883a9 171
784883fc 172/* Operations */
3653d0c2 173
2893111f 174# define OSSL_OP_DIGEST 1
784883fc
SL
175# define OSSL_OP_CIPHER 2 /* Symmetric Ciphers */
176# define OSSL_OP_MAC 3
ad1700c7 177# define OSSL_OP_KDF 4
784883fc
SL
178# define OSSL_OP_KEYMGMT 10
179# define OSSL_OP_KEYEXCH 11
dfcb5d29 180# define OSSL_OP_SIGNATURE 12
2c938e2e 181# define OSSL_OP_ASYM_CIPHER 13
0d003c52
RL
182/* New section for non-EVP operations */
183# define OSSL_OP_SERIALIZER 20
784883fc 184/* Highest known operation number */
0d003c52 185# define OSSL_OP__HIGHEST 20
784883fc
SL
186
187/* Digests */
2893111f
RL
188
189# define OSSL_FUNC_DIGEST_NEWCTX 1
190# define OSSL_FUNC_DIGEST_INIT 2
191# define OSSL_FUNC_DIGEST_UPDATE 3
192# define OSSL_FUNC_DIGEST_FINAL 4
193# define OSSL_FUNC_DIGEST_DIGEST 5
194# define OSSL_FUNC_DIGEST_FREECTX 6
195# define OSSL_FUNC_DIGEST_DUPCTX 7
196# define OSSL_FUNC_DIGEST_GET_PARAMS 8
92d9d0ae
RL
197# define OSSL_FUNC_DIGEST_SET_CTX_PARAMS 9
198# define OSSL_FUNC_DIGEST_GET_CTX_PARAMS 10
ae3ff60e
RL
199# define OSSL_FUNC_DIGEST_GETTABLE_PARAMS 11
200# define OSSL_FUNC_DIGEST_SETTABLE_CTX_PARAMS 12
201# define OSSL_FUNC_DIGEST_GETTABLE_CTX_PARAMS 13
df05f2ce 202
a39eb840
RL
203OSSL_CORE_MAKE_FUNC(void *, OP_digest_newctx, (void *provctx))
204OSSL_CORE_MAKE_FUNC(int, OP_digest_init, (void *dctx))
3653d0c2 205OSSL_CORE_MAKE_FUNC(int, OP_digest_update,
a39eb840 206 (void *dctx, const unsigned char *in, size_t inl))
3653d0c2 207OSSL_CORE_MAKE_FUNC(int, OP_digest_final,
a39eb840
RL
208 (void *dctx,
209 unsigned char *out, size_t *outl, size_t outsz))
3653d0c2 210OSSL_CORE_MAKE_FUNC(int, OP_digest_digest,
a39eb840 211 (void *provctx, const unsigned char *in, size_t inl,
8ccf2ffb 212 unsigned char *out, size_t *outl, size_t outsz))
df05f2ce 213
a39eb840
RL
214OSSL_CORE_MAKE_FUNC(void, OP_digest_freectx, (void *dctx))
215OSSL_CORE_MAKE_FUNC(void *, OP_digest_dupctx, (void *dctx))
d5e5e2ff 216
2893111f 217OSSL_CORE_MAKE_FUNC(int, OP_digest_get_params, (OSSL_PARAM params[]))
92d9d0ae 218OSSL_CORE_MAKE_FUNC(int, OP_digest_set_ctx_params,
2893111f 219 (void *vctx, const OSSL_PARAM params[]))
92d9d0ae 220OSSL_CORE_MAKE_FUNC(int, OP_digest_get_ctx_params,
2893111f 221 (void *vctx, OSSL_PARAM params[]))
ae3ff60e
RL
222OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_digest_gettable_params, (void))
223OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_digest_settable_ctx_params, (void))
224OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_digest_gettable_ctx_params, (void))
df05f2ce
MC
225
226/* Symmetric Ciphers */
227
df05f2ce
MC
228# define OSSL_FUNC_CIPHER_NEWCTX 1
229# define OSSL_FUNC_CIPHER_ENCRYPT_INIT 2
230# define OSSL_FUNC_CIPHER_DECRYPT_INIT 3
231# define OSSL_FUNC_CIPHER_UPDATE 4
232# define OSSL_FUNC_CIPHER_FINAL 5
718b133a
MC
233# define OSSL_FUNC_CIPHER_CIPHER 6
234# define OSSL_FUNC_CIPHER_FREECTX 7
235# define OSSL_FUNC_CIPHER_DUPCTX 8
80942379 236# define OSSL_FUNC_CIPHER_GET_PARAMS 9
92d9d0ae
RL
237# define OSSL_FUNC_CIPHER_GET_CTX_PARAMS 10
238# define OSSL_FUNC_CIPHER_SET_CTX_PARAMS 11
ae3ff60e
RL
239# define OSSL_FUNC_CIPHER_GETTABLE_PARAMS 12
240# define OSSL_FUNC_CIPHER_GETTABLE_CTX_PARAMS 13
241# define OSSL_FUNC_CIPHER_SETTABLE_CTX_PARAMS 14
df05f2ce 242
a39eb840
RL
243OSSL_CORE_MAKE_FUNC(void *, OP_cipher_newctx, (void *provctx))
244OSSL_CORE_MAKE_FUNC(int, OP_cipher_encrypt_init, (void *cctx,
df05f2ce 245 const unsigned char *key,
344cfa34
MC
246 size_t keylen,
247 const unsigned char *iv,
248 size_t ivlen))
a39eb840 249OSSL_CORE_MAKE_FUNC(int, OP_cipher_decrypt_init, (void *cctx,
df05f2ce 250 const unsigned char *key,
344cfa34
MC
251 size_t keylen,
252 const unsigned char *iv,
253 size_t ivlen))
df05f2ce 254OSSL_CORE_MAKE_FUNC(int, OP_cipher_update,
a39eb840
RL
255 (void *cctx,
256 unsigned char *out, size_t *outl, size_t outsize,
df05f2ce
MC
257 const unsigned char *in, size_t inl))
258OSSL_CORE_MAKE_FUNC(int, OP_cipher_final,
a39eb840
RL
259 (void *cctx,
260 unsigned char *out, size_t *outl, size_t outsize))
df05f2ce 261OSSL_CORE_MAKE_FUNC(int, OP_cipher_cipher,
a39eb840 262 (void *cctx,
f79858ac
RL
263 unsigned char *out, size_t *outl, size_t outsize,
264 const unsigned char *in, size_t inl))
a39eb840
RL
265OSSL_CORE_MAKE_FUNC(void, OP_cipher_freectx, (void *cctx))
266OSSL_CORE_MAKE_FUNC(void *, OP_cipher_dupctx, (void *cctx))
4e7991b4 267OSSL_CORE_MAKE_FUNC(int, OP_cipher_get_params, (OSSL_PARAM params[]))
92d9d0ae 268OSSL_CORE_MAKE_FUNC(int, OP_cipher_get_ctx_params, (void *cctx,
4e7991b4 269 OSSL_PARAM params[]))
92d9d0ae 270OSSL_CORE_MAKE_FUNC(int, OP_cipher_set_ctx_params, (void *cctx,
718b133a 271 const OSSL_PARAM params[]))
784883fc
SL
272OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_cipher_gettable_params, (void))
273OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_cipher_settable_ctx_params, (void))
274OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_cipher_gettable_ctx_params, (void))
df05f2ce 275
e74bd290
RL
276/* MACs */
277
e74bd290
RL
278# define OSSL_FUNC_MAC_NEWCTX 1
279# define OSSL_FUNC_MAC_DUPCTX 2
280# define OSSL_FUNC_MAC_FREECTX 3
281# define OSSL_FUNC_MAC_INIT 4
282# define OSSL_FUNC_MAC_UPDATE 5
283# define OSSL_FUNC_MAC_FINAL 6
784883fc
SL
284# define OSSL_FUNC_MAC_GET_PARAMS 7
285# define OSSL_FUNC_MAC_GET_CTX_PARAMS 8
286# define OSSL_FUNC_MAC_SET_CTX_PARAMS 9
287# define OSSL_FUNC_MAC_GETTABLE_PARAMS 10
288# define OSSL_FUNC_MAC_GETTABLE_CTX_PARAMS 11
289# define OSSL_FUNC_MAC_SETTABLE_CTX_PARAMS 12
e74bd290
RL
290
291OSSL_CORE_MAKE_FUNC(void *, OP_mac_newctx, (void *provctx))
292OSSL_CORE_MAKE_FUNC(void *, OP_mac_dupctx, (void *src))
293OSSL_CORE_MAKE_FUNC(void, OP_mac_freectx, (void *mctx))
294OSSL_CORE_MAKE_FUNC(size_t, OP_mac_size, (void *mctx))
295OSSL_CORE_MAKE_FUNC(int, OP_mac_init, (void *mctx))
296OSSL_CORE_MAKE_FUNC(int, OP_mac_update,
297 (void *mctx, const unsigned char *in, size_t inl))
298OSSL_CORE_MAKE_FUNC(int, OP_mac_final,
299 (void *mctx,
300 unsigned char *out, size_t *outl, size_t outsize))
301OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_mac_gettable_params, (void))
302OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_mac_gettable_ctx_params, (void))
303OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_mac_settable_ctx_params, (void))
304OSSL_CORE_MAKE_FUNC(int, OP_mac_get_params, (OSSL_PARAM params[]))
92d9d0ae 305OSSL_CORE_MAKE_FUNC(int, OP_mac_get_ctx_params,
e74bd290 306 (void *mctx, OSSL_PARAM params[]))
92d9d0ae 307OSSL_CORE_MAKE_FUNC(int, OP_mac_set_ctx_params,
e74bd290
RL
308 (void *mctx, const OSSL_PARAM params[]))
309
2f755701 310/* KDFs and PRFs */
2f755701
P
311
312# define OSSL_FUNC_KDF_NEWCTX 1
313# define OSSL_FUNC_KDF_DUPCTX 2
314# define OSSL_FUNC_KDF_FREECTX 3
315# define OSSL_FUNC_KDF_RESET 4
316# define OSSL_FUNC_KDF_DERIVE 5
317# define OSSL_FUNC_KDF_GETTABLE_PARAMS 6
318# define OSSL_FUNC_KDF_GETTABLE_CTX_PARAMS 7
319# define OSSL_FUNC_KDF_SETTABLE_CTX_PARAMS 8
320# define OSSL_FUNC_KDF_GET_PARAMS 9
321# define OSSL_FUNC_KDF_GET_CTX_PARAMS 10
322# define OSSL_FUNC_KDF_SET_CTX_PARAMS 11
323
324OSSL_CORE_MAKE_FUNC(void *, OP_kdf_newctx, (void *provctx))
325OSSL_CORE_MAKE_FUNC(void *, OP_kdf_dupctx, (void *src))
326OSSL_CORE_MAKE_FUNC(void, OP_kdf_freectx, (void *kctx))
327OSSL_CORE_MAKE_FUNC(void, OP_kdf_reset, (void *kctx))
328OSSL_CORE_MAKE_FUNC(int, OP_kdf_derive, (void *kctx, unsigned char *key,
329 size_t keylen))
330OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_kdf_gettable_params, (void))
331OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_kdf_gettable_ctx_params, (void))
332OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_kdf_settable_ctx_params, (void))
333OSSL_CORE_MAKE_FUNC(int, OP_kdf_get_params, (OSSL_PARAM params[]))
334OSSL_CORE_MAKE_FUNC(int, OP_kdf_get_ctx_params,
335 (void *kctx, OSSL_PARAM params[]))
336OSSL_CORE_MAKE_FUNC(int, OP_kdf_set_ctx_params,
337 (void *kctx, const OSSL_PARAM params[]))
338
a94a3e0d
RL
339/*-
340 * Key management
341 *
b305452f
RL
342 * The Key Management takes care of provider side key objects, and includes
343 * all current functionality to create them, destroy them, set parameters
344 * and key material, etc, essentially everything that manipulates the keys
345 * themselves and their parameters.
a94a3e0d 346 *
b305452f
RL
347 * The key objects are commonly refered to as |keydata|, and it MUST be able
348 * to contain parameters if the key has any, the public key and the private
349 * key. All parts are optional, but their presence determines what can be
350 * done with the key object in terms of encryption, signature, and so on.
351 * The assumption from libcrypto is that the key object contains any of the
352 * following data combinations:
353 *
354 * - parameters only
355 * - public key only
356 * - public key + private key
357 * - parameters + public key
358 * - parameters + public key + private key
359 *
360 * What "parameters", "public key" and "private key" means in detail is left
361 * to the implementation. In the case of DH and DSA, they would typically
362 * include domain parameters, while for certain variants of RSA, they would
363 * typically include PSS or OAEP parameters.
364 *
365 * Key objects are created with OP_keymgmt_new() and destroyed with
366 * Op_keymgmt_free(). Key objects can have data filled in with
367 * OP_keymgmt_import().
368 *
369 * Three functions are made available to check what selection of data is
370 * present in a key object: OP_keymgmt_has_parameters(),
371 * OP_keymgmt_has_public_key(), and OP_keymgmt_has_private_key(),
a94a3e0d
RL
372 */
373
b305452f
RL
374/* Key data subset selection - individual bits */
375# define OSSL_KEYMGMT_SELECT_PRIVATE_KEY 0x01
376# define OSSL_KEYMGMT_SELECT_PUBLIC_KEY 0x02
377# define OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS 0x04
378# define OSSL_KEYMGMT_SELECT_OTHER_PARAMETERS 0x80
379
380/* Key data subset selection - combinations */
381# define OSSL_KEYMGMT_SELECT_ALL_PARAMETERS \
382 ( OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS \
383 | OSSL_KEYMGMT_SELECT_OTHER_PARAMETERS)
384# define OSSL_KEYMGMT_SELECT_KEYPAIR \
385 ( OSSL_KEYMGMT_SELECT_PRIVATE_KEY | OSSL_KEYMGMT_SELECT_PUBLIC_KEY )
386# define OSSL_KEYMGMT_SELECT_ALL \
387 ( OSSL_KEYMGMT_SELECT_KEYPAIR | OSSL_KEYMGMT_SELECT_ALL_PARAMETERS )
388
1a5632e0 389/* Basic key object creation */
b305452f 390# define OSSL_FUNC_KEYMGMT_NEW 1
b305452f 391OSSL_CORE_MAKE_FUNC(void *, OP_keymgmt_new, (void *provctx))
1a5632e0
RL
392
393/* Generation, a more complex constructor */
2b9add69
RL
394# define OSSL_FUNC_KEYMGMT_GEN_INIT 2
395# define OSSL_FUNC_KEYMGMT_GEN_SET_TEMPLATE 3
396# define OSSL_FUNC_KEYMGMT_GEN_SET_PARAMS 4
397# define OSSL_FUNC_KEYMGMT_GEN_SETTABLE_PARAMS 5
5e77b79a
SL
398# define OSSL_FUNC_KEYMGMT_GEN 6
399# define OSSL_FUNC_KEYMGMT_GEN_CLEANUP 7
1a5632e0
RL
400OSSL_CORE_MAKE_FUNC(void *, OP_keymgmt_gen_init,
401 (void *provctx, int selection))
402OSSL_CORE_MAKE_FUNC(int, OP_keymgmt_gen_set_template,
403 (void *genctx, void *templ))
404OSSL_CORE_MAKE_FUNC(int, OP_keymgmt_gen_set_params,
405 (void *genctx, const OSSL_PARAM params[]))
406OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *,
407 OP_keymgmt_gen_settable_params, (void *provctx))
2b9add69
RL
408OSSL_CORE_MAKE_FUNC(int, OP_keymgmt_gen_get_params,
409 (void *genctx, OSSL_PARAM params[]))
410OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *,
411 OP_keymgmt_gen_gettable_params, (void *provctx))
1a5632e0
RL
412OSSL_CORE_MAKE_FUNC(void *, OP_keymgmt_gen,
413 (void *genctx, OSSL_CALLBACK *cb, void *cbarg))
414OSSL_CORE_MAKE_FUNC(void, OP_keymgmt_gen_cleanup, (void *genctx))
415
416/* Basic key object destruction */
2b9add69 417# define OSSL_FUNC_KEYMGMT_FREE 10
b305452f
RL
418OSSL_CORE_MAKE_FUNC(void, OP_keymgmt_free, (void *keydata))
419
420/* Key object information, with discovery */
2b9add69
RL
421#define OSSL_FUNC_KEYMGMT_GET_PARAMS 11
422#define OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS 12
b305452f
RL
423OSSL_CORE_MAKE_FUNC(int, OP_keymgmt_get_params,
424 (void *keydata, OSSL_PARAM params[]))
425OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_keymgmt_gettable_params, (void))
426
2b9add69
RL
427#define OSSL_FUNC_KEYMGMT_SET_PARAMS 13
428#define OSSL_FUNC_KEYMGMT_SETTABLE_PARAMS 14
4fe54d67
NT
429OSSL_CORE_MAKE_FUNC(int, OP_keymgmt_set_params,
430 (void *keydata, const OSSL_PARAM params[]))
431OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_keymgmt_settable_params, (void))
432
b305452f
RL
433/* Key checks - discovery of supported operations */
434# define OSSL_FUNC_KEYMGMT_QUERY_OPERATION_NAME 20
435OSSL_CORE_MAKE_FUNC(const char *, OP_keymgmt_query_operation_name,
e62a45b6
RL
436 (int operation_id))
437
b305452f
RL
438/* Key checks - key data content checks */
439# define OSSL_FUNC_KEYMGMT_HAS 21
440OSSL_CORE_MAKE_FUNC(int, OP_keymgmt_has, (void *keydata, int selection))
441
442/* Key checks - validation */
443# define OSSL_FUNC_KEYMGMT_VALIDATE 22
444OSSL_CORE_MAKE_FUNC(int, OP_keymgmt_validate, (void *keydata, int selection))
445
bee5d6cd
RL
446/* Key checks - matching */
447# define OSSL_FUNC_KEYMGMT_MATCH 23
448OSSL_CORE_MAKE_FUNC(int, OP_keymgmt_match,
449 (const void *keydata1, const void *keydata2,
450 int selection))
451
13697f1c 452/* Import and export functions, with discovery */
b305452f
RL
453# define OSSL_FUNC_KEYMGMT_IMPORT 40
454# define OSSL_FUNC_KEYMGMT_IMPORT_TYPES 41
455# define OSSL_FUNC_KEYMGMT_EXPORT 42
456# define OSSL_FUNC_KEYMGMT_EXPORT_TYPES 43
457OSSL_CORE_MAKE_FUNC(int, OP_keymgmt_import,
458 (void *keydata, int selection, const OSSL_PARAM params[]))
459OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_keymgmt_import_types,
460 (int selection))
461OSSL_CORE_MAKE_FUNC(int, OP_keymgmt_export,
462 (void *keydata, int selection,
463 OSSL_CALLBACK *param_cb, void *cbarg))
464OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_keymgmt_export_types,
465 (int selection))
12603de6 466
13697f1c
RL
467/* Copy function, only works for matching keymgmt */
468# define OSSL_FUNC_KEYMGMT_COPY 44
469OSSL_CORE_MAKE_FUNC(int, OP_keymgmt_copy,
470 ( void *keydata_to, const void *keydata_from,
471 int selection))
472
ff64702b
MC
473/* Key Exchange */
474
ff64702b
MC
475# define OSSL_FUNC_KEYEXCH_NEWCTX 1
476# define OSSL_FUNC_KEYEXCH_INIT 2
477# define OSSL_FUNC_KEYEXCH_DERIVE 3
478# define OSSL_FUNC_KEYEXCH_SET_PEER 4
479# define OSSL_FUNC_KEYEXCH_FREECTX 5
480# define OSSL_FUNC_KEYEXCH_DUPCTX 6
9c45222d
MC
481# define OSSL_FUNC_KEYEXCH_SET_CTX_PARAMS 7
482# define OSSL_FUNC_KEYEXCH_SETTABLE_CTX_PARAMS 8
4fe54d67
NT
483# define OSSL_FUNC_KEYEXCH_GET_CTX_PARAMS 9
484# define OSSL_FUNC_KEYEXCH_GETTABLE_CTX_PARAMS 10
ff64702b
MC
485
486OSSL_CORE_MAKE_FUNC(void *, OP_keyexch_newctx, (void *provctx))
8b84b075 487OSSL_CORE_MAKE_FUNC(int, OP_keyexch_init, (void *ctx, void *provkey))
59972370
MC
488OSSL_CORE_MAKE_FUNC(int, OP_keyexch_derive, (void *ctx, unsigned char *secret,
489 size_t *secretlen, size_t outlen))
8b84b075 490OSSL_CORE_MAKE_FUNC(int, OP_keyexch_set_peer, (void *ctx, void *provkey))
ff64702b
MC
491OSSL_CORE_MAKE_FUNC(void, OP_keyexch_freectx, (void *ctx))
492OSSL_CORE_MAKE_FUNC(void *, OP_keyexch_dupctx, (void *ctx))
9c45222d
MC
493OSSL_CORE_MAKE_FUNC(int, OP_keyexch_set_ctx_params, (void *ctx,
494 const OSSL_PARAM params[]))
495OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_keyexch_settable_ctx_params,
496 (void))
4fe54d67
NT
497OSSL_CORE_MAKE_FUNC(int, OP_keyexch_get_ctx_params, (void *ctx,
498 OSSL_PARAM params[]))
499OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_keyexch_gettable_ctx_params,
500 (void))
ff64702b 501
dfcb5d29
MC
502/* Signature */
503
504# define OSSL_FUNC_SIGNATURE_NEWCTX 1
505# define OSSL_FUNC_SIGNATURE_SIGN_INIT 2
506# define OSSL_FUNC_SIGNATURE_SIGN 3
390acbeb
MC
507# define OSSL_FUNC_SIGNATURE_VERIFY_INIT 4
508# define OSSL_FUNC_SIGNATURE_VERIFY 5
509# define OSSL_FUNC_SIGNATURE_VERIFY_RECOVER_INIT 6
510# define OSSL_FUNC_SIGNATURE_VERIFY_RECOVER 7
d8c98d79
MC
511# define OSSL_FUNC_SIGNATURE_DIGEST_SIGN_INIT 8
512# define OSSL_FUNC_SIGNATURE_DIGEST_SIGN_UPDATE 9
513# define OSSL_FUNC_SIGNATURE_DIGEST_SIGN_FINAL 10
eea1e780
MC
514# define OSSL_FUNC_SIGNATURE_DIGEST_SIGN 11
515# define OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_INIT 12
516# define OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_UPDATE 13
517# define OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_FINAL 14
518# define OSSL_FUNC_SIGNATURE_DIGEST_VERIFY 15
519# define OSSL_FUNC_SIGNATURE_FREECTX 16
520# define OSSL_FUNC_SIGNATURE_DUPCTX 17
521# define OSSL_FUNC_SIGNATURE_GET_CTX_PARAMS 18
522# define OSSL_FUNC_SIGNATURE_GETTABLE_CTX_PARAMS 19
523# define OSSL_FUNC_SIGNATURE_SET_CTX_PARAMS 20
524# define OSSL_FUNC_SIGNATURE_SETTABLE_CTX_PARAMS 21
525# define OSSL_FUNC_SIGNATURE_GET_CTX_MD_PARAMS 22
526# define OSSL_FUNC_SIGNATURE_GETTABLE_CTX_MD_PARAMS 23
527# define OSSL_FUNC_SIGNATURE_SET_CTX_MD_PARAMS 24
528# define OSSL_FUNC_SIGNATURE_SETTABLE_CTX_MD_PARAMS 25
dfcb5d29 529
2c6094ba
RL
530OSSL_CORE_MAKE_FUNC(void *, OP_signature_newctx, (void *provctx,
531 const char *propq))
dfcb5d29
MC
532OSSL_CORE_MAKE_FUNC(int, OP_signature_sign_init, (void *ctx, void *provkey))
533OSSL_CORE_MAKE_FUNC(int, OP_signature_sign, (void *ctx, unsigned char *sig,
534 size_t *siglen, size_t sigsize,
535 const unsigned char *tbs,
536 size_t tbslen))
390acbeb
MC
537OSSL_CORE_MAKE_FUNC(int, OP_signature_verify_init, (void *ctx, void *provkey))
538OSSL_CORE_MAKE_FUNC(int, OP_signature_verify, (void *ctx,
539 const unsigned char *sig,
540 size_t siglen,
541 const unsigned char *tbs,
542 size_t tbslen))
543OSSL_CORE_MAKE_FUNC(int, OP_signature_verify_recover_init, (void *ctx,
544 void *provkey))
545OSSL_CORE_MAKE_FUNC(int, OP_signature_verify_recover, (void *ctx,
546 unsigned char *rout,
547 size_t *routlen,
548 size_t routsize,
549 const unsigned char *sig,
550 size_t siglen))
d8c98d79 551OSSL_CORE_MAKE_FUNC(int, OP_signature_digest_sign_init,
2c6094ba 552 (void *ctx, const char *mdname, void *provkey))
d8c98d79
MC
553OSSL_CORE_MAKE_FUNC(int, OP_signature_digest_sign_update,
554 (void *ctx, const unsigned char *data, size_t datalen))
555OSSL_CORE_MAKE_FUNC(int, OP_signature_digest_sign_final,
556 (void *ctx, unsigned char *sig, size_t *siglen,
557 size_t sigsize))
eea1e780
MC
558OSSL_CORE_MAKE_FUNC(int, OP_signature_digest_sign,
559 (void *ctx, unsigned char *sigret, size_t *siglen,
560 size_t sigsize, const unsigned char *tbs, size_t tbslen))
d8c98d79 561OSSL_CORE_MAKE_FUNC(int, OP_signature_digest_verify_init,
2c6094ba 562 (void *ctx, const char *mdname, void *provkey))
d8c98d79
MC
563OSSL_CORE_MAKE_FUNC(int, OP_signature_digest_verify_update,
564 (void *ctx, const unsigned char *data, size_t datalen))
565OSSL_CORE_MAKE_FUNC(int, OP_signature_digest_verify_final,
566 (void *ctx, const unsigned char *sig, size_t siglen))
eea1e780
MC
567OSSL_CORE_MAKE_FUNC(int, OP_signature_digest_verify,
568 (void *ctx, const unsigned char *sig, size_t siglen,
569 const unsigned char *tbs, size_t tbslen))
dfcb5d29
MC
570OSSL_CORE_MAKE_FUNC(void, OP_signature_freectx, (void *ctx))
571OSSL_CORE_MAKE_FUNC(void *, OP_signature_dupctx, (void *ctx))
9c45222d
MC
572OSSL_CORE_MAKE_FUNC(int, OP_signature_get_ctx_params,
573 (void *ctx, OSSL_PARAM params[]))
574OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_signature_gettable_ctx_params,
575 (void))
576OSSL_CORE_MAKE_FUNC(int, OP_signature_set_ctx_params,
577 (void *ctx, const OSSL_PARAM params[]))
578OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_signature_settable_ctx_params,
579 (void))
d8c98d79
MC
580OSSL_CORE_MAKE_FUNC(int, OP_signature_get_ctx_md_params,
581 (void *ctx, OSSL_PARAM params[]))
582OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_signature_gettable_ctx_md_params,
583 (void *ctx))
584OSSL_CORE_MAKE_FUNC(int, OP_signature_set_ctx_md_params,
585 (void *ctx, const OSSL_PARAM params[]))
586OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_signature_settable_ctx_md_params,
587 (void *ctx))
dfcb5d29 588
2c938e2e
MC
589
590/* Asymmetric Ciphers */
591
592# define OSSL_FUNC_ASYM_CIPHER_NEWCTX 1
593# define OSSL_FUNC_ASYM_CIPHER_ENCRYPT_INIT 2
594# define OSSL_FUNC_ASYM_CIPHER_ENCRYPT 3
595# define OSSL_FUNC_ASYM_CIPHER_DECRYPT_INIT 4
596# define OSSL_FUNC_ASYM_CIPHER_DECRYPT 5
597# define OSSL_FUNC_ASYM_CIPHER_FREECTX 6
598# define OSSL_FUNC_ASYM_CIPHER_DUPCTX 7
599# define OSSL_FUNC_ASYM_CIPHER_GET_CTX_PARAMS 8
600# define OSSL_FUNC_ASYM_CIPHER_GETTABLE_CTX_PARAMS 9
601# define OSSL_FUNC_ASYM_CIPHER_SET_CTX_PARAMS 10
602# define OSSL_FUNC_ASYM_CIPHER_SETTABLE_CTX_PARAMS 11
603
604OSSL_CORE_MAKE_FUNC(void *, OP_asym_cipher_newctx, (void *provctx))
605OSSL_CORE_MAKE_FUNC(int, OP_asym_cipher_encrypt_init, (void *ctx, void *provkey))
606OSSL_CORE_MAKE_FUNC(int, OP_asym_cipher_encrypt, (void *ctx, unsigned char *out,
607 size_t *outlen,
608 size_t outsize,
609 const unsigned char *in,
610 size_t inlen))
611OSSL_CORE_MAKE_FUNC(int, OP_asym_cipher_decrypt_init, (void *ctx, void *provkey))
612OSSL_CORE_MAKE_FUNC(int, OP_asym_cipher_decrypt, (void *ctx, unsigned char *out,
613 size_t *outlen,
614 size_t outsize,
615 const unsigned char *in,
616 size_t inlen))
617OSSL_CORE_MAKE_FUNC(void, OP_asym_cipher_freectx, (void *ctx))
618OSSL_CORE_MAKE_FUNC(void *, OP_asym_cipher_dupctx, (void *ctx))
619OSSL_CORE_MAKE_FUNC(int, OP_asym_cipher_get_ctx_params,
620 (void *ctx, OSSL_PARAM params[]))
621OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_asym_cipher_gettable_ctx_params,
622 (void))
623OSSL_CORE_MAKE_FUNC(int, OP_asym_cipher_set_ctx_params,
624 (void *ctx, const OSSL_PARAM params[]))
625OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_asym_cipher_settable_ctx_params,
626 (void))
627
0d003c52
RL
628/* Serializers */
629# define OSSL_FUNC_SERIALIZER_NEWCTX 1
630# define OSSL_FUNC_SERIALIZER_FREECTX 2
631# define OSSL_FUNC_SERIALIZER_SET_CTX_PARAMS 3
632# define OSSL_FUNC_SERIALIZER_SETTABLE_CTX_PARAMS 4
633# define OSSL_FUNC_SERIALIZER_SERIALIZE_DATA 10
634# define OSSL_FUNC_SERIALIZER_SERIALIZE_OBJECT 11
635OSSL_CORE_MAKE_FUNC(void *, OP_serializer_newctx, (void *provctx))
636OSSL_CORE_MAKE_FUNC(void, OP_serializer_freectx, (void *ctx))
637OSSL_CORE_MAKE_FUNC(int, OP_serializer_set_ctx_params,
638 (void *ctx, const OSSL_PARAM params[]))
639OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_serializer_settable_ctx_params,
640 (void))
641
642OSSL_CORE_MAKE_FUNC(int, OP_serializer_serialize_data,
d40b42ab 643 (void *ctx, const OSSL_PARAM[], OSSL_CORE_BIO *out,
0d003c52
RL
644 OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg))
645OSSL_CORE_MAKE_FUNC(int, OP_serializer_serialize_object,
d40b42ab 646 (void *ctx, void *obj, OSSL_CORE_BIO *out,
0d003c52
RL
647 OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg))
648
4c2883a9
RL
649# ifdef __cplusplus
650}
651# endif
652
653#endif