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'
38 /* Helper macro to create the function signature typedef and the extractor */
39 #define OSSL_CORE_MAKE_FUNC(type,name,args) \
40 typedef type (OSSL_##name##_fn)args; \
42 OSSL_##name##_fn *OSSL_get_##name(const OSSL_DISPATCH *opf) \
44 return (OSSL_##name##_fn *)opf->function; \
48 * Core function identities, for the two OSSL_DISPATCH tables being passed
49 * in the OSSL_provider_init call.
51 * 0 serves as a marker for the end of the OSSL_DISPATCH array, and must
52 * therefore NEVER be used as a function identity.
54 /* Functions provided by the Core to the provider, reserved numbers 1-1023 */
55 # define OSSL_FUNC_CORE_GET_PARAM_TYPES 1
56 OSSL_CORE_MAKE_FUNC(const OSSL_ITEM *,
57 core_get_param_types,(const OSSL_PROVIDER *prov))
58 # define OSSL_FUNC_CORE_GET_PARAMS 2
59 OSSL_CORE_MAKE_FUNC(int,core_get_params,(const OSSL_PROVIDER *prov,
60 const OSSL_PARAM params[]))
61 # define OSSL_FUNC_CORE_PUT_ERROR 3
62 OSSL_CORE_MAKE_FUNC(void,core_put_error,(int lib, int func, int reason,
63 const char *file, int line))
64 # define OSSL_FUNC_CORE_ADD_ERROR_VDATA 4
65 OSSL_CORE_MAKE_FUNC(void,core_add_error_vdata,(int num, va_list args))
68 /* Functions provided by the provider to the Core, reserved numbers 1024-1535 */
69 # define OSSL_FUNC_PROVIDER_TEARDOWN 1024
70 OSSL_CORE_MAKE_FUNC(void,provider_teardown,(void *provctx))
71 # define OSSL_FUNC_PROVIDER_GET_PARAM_TYPES 1025
72 OSSL_CORE_MAKE_FUNC(const OSSL_ITEM *,
73 provider_get_param_types,(void *provctx))
74 # define OSSL_FUNC_PROVIDER_GET_PARAMS 1026
75 OSSL_CORE_MAKE_FUNC(int,provider_get_params,(void *provctx,
76 const OSSL_PARAM params[]))
77 # define OSSL_FUNC_PROVIDER_QUERY_OPERATION 1027
78 OSSL_CORE_MAKE_FUNC(const OSSL_ALGORITHM *,provider_query_operation,
79 (void *provctx, int operation_id, const int *no_store))
83 # define OSSL_OP_DIGEST 1
85 # define OSSL_FUNC_DIGEST_NEWCTX 1
86 # define OSSL_FUNC_DIGEST_INIT 2
87 # define OSSL_FUNC_DIGEST_UPDATE 3
88 # define OSSL_FUNC_DIGEST_FINAL 4
89 # define OSSL_FUNC_DIGEST_DIGEST 5
90 # define OSSL_FUNC_DIGEST_FREECTX 6
91 # define OSSL_FUNC_DIGEST_DUPCTX 7
92 # define OSSL_FUNC_DIGEST_SIZE 8
93 # define OSSL_FUNC_DIGEST_BLOCK_SIZE 9
96 OSSL_CORE_MAKE_FUNC(void *, OP_digest_newctx, (void *provctx))
97 OSSL_CORE_MAKE_FUNC(int, OP_digest_init, (void *dctx))
98 OSSL_CORE_MAKE_FUNC(int, OP_digest_update,
99 (void *dctx, const unsigned char *in, size_t inl))
100 OSSL_CORE_MAKE_FUNC(int, OP_digest_final,
102 unsigned char *out, size_t *outl, size_t outsz))
103 OSSL_CORE_MAKE_FUNC(int, OP_digest_digest,
104 (void *provctx, const unsigned char *in, size_t inl,
105 unsigned char *out, size_t *out_l, size_t outsz))
107 OSSL_CORE_MAKE_FUNC(void, OP_digest_cleanctx, (void *dctx))
108 OSSL_CORE_MAKE_FUNC(void, OP_digest_freectx, (void *dctx))
109 OSSL_CORE_MAKE_FUNC(void *, OP_digest_dupctx, (void *dctx))
110 OSSL_CORE_MAKE_FUNC(size_t, OP_digest_size, (void))
111 OSSL_CORE_MAKE_FUNC(size_t, OP_digest_block_size, (void))
114 /* Symmetric Ciphers */
116 # define OSSL_OP_CIPHER 2
118 # define OSSL_FUNC_CIPHER_NEWCTX 1
119 # define OSSL_FUNC_CIPHER_ENCRYPT_INIT 2
120 # define OSSL_FUNC_CIPHER_DECRYPT_INIT 3
121 # define OSSL_FUNC_CIPHER_UPDATE 4
122 # define OSSL_FUNC_CIPHER_FINAL 5
123 # define OSSL_FUNC_CIPHER_CIPHER 6
124 # define OSSL_FUNC_CIPHER_FREECTX 7
125 # define OSSL_FUNC_CIPHER_DUPCTX 8
126 # define OSSL_FUNC_CIPHER_KEY_LENGTH 9
127 # define OSSL_FUNC_CIPHER_IV_LENGTH 10
128 # define OSSL_FUNC_CIPHER_BLOCK_SIZE 11
129 # define OSSL_FUNC_CIPHER_GET_PARAMS 12
130 # define OSSL_FUNC_CIPHER_CTX_GET_PARAMS 13
131 # define OSSL_FUNC_CIPHER_CTX_SET_PARAMS 14
133 OSSL_CORE_MAKE_FUNC(void *, OP_cipher_newctx, (void *provctx))
134 OSSL_CORE_MAKE_FUNC(int, OP_cipher_encrypt_init, (void *cctx,
135 const unsigned char *key,
137 const unsigned char *iv,
139 OSSL_CORE_MAKE_FUNC(int, OP_cipher_decrypt_init, (void *cctx,
140 const unsigned char *key,
142 const unsigned char *iv,
144 OSSL_CORE_MAKE_FUNC(int, OP_cipher_update,
146 unsigned char *out, size_t *outl, size_t outsize,
147 const unsigned char *in, size_t inl))
148 OSSL_CORE_MAKE_FUNC(int, OP_cipher_final,
150 unsigned char *out, size_t *outl, size_t outsize))
151 OSSL_CORE_MAKE_FUNC(int, OP_cipher_cipher,
153 unsigned char *out, size_t *outl, size_t outsize,
154 const unsigned char *in, size_t inl))
155 OSSL_CORE_MAKE_FUNC(void, OP_cipher_freectx, (void *cctx))
156 OSSL_CORE_MAKE_FUNC(void *, OP_cipher_dupctx, (void *cctx))
157 OSSL_CORE_MAKE_FUNC(size_t, OP_cipher_key_length, (void))
158 OSSL_CORE_MAKE_FUNC(size_t, OP_cipher_iv_length, (void))
159 OSSL_CORE_MAKE_FUNC(size_t, OP_cipher_block_size, (void))
160 OSSL_CORE_MAKE_FUNC(int, OP_cipher_get_params, (const OSSL_PARAM params[]))
161 OSSL_CORE_MAKE_FUNC(int, OP_cipher_ctx_get_params, (void *cctx,
162 const OSSL_PARAM params[]))
163 OSSL_CORE_MAKE_FUNC(int, OP_cipher_ctx_set_params, (void *cctx,
164 const OSSL_PARAM params[]))