test/evp_test.c: [ciphers] Test that we get back the same IV we gave
[openssl.git] / include / openssl / core_numbers.h
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
13 # include <stdarg.h>
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
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;                                \
41     static ossl_inline \
42     OSSL_##name##_fn *OSSL_get_##name(const OSSL_DISPATCH *opf)         \
43     {                                                                   \
44         return (OSSL_##name##_fn *)opf->function;                       \
45     }
46
47 /*
48  * Core function identities, for the two OSSL_DISPATCH tables being passed
49  * in the OSSL_provider_init call.
50  *
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.
53  */
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                                          OSSL_PARAM params[]))
61 # define OSSL_FUNC_CORE_THREAD_START           3
62 OSSL_CORE_MAKE_FUNC(int,core_thread_start,(const OSSL_PROVIDER *prov,
63                                            OSSL_thread_stop_handler_fn handfn))
64 # define OSSL_FUNC_CORE_PUT_ERROR              4
65 OSSL_CORE_MAKE_FUNC(void,core_put_error,
66                     (const OSSL_PROVIDER *prov,
67                      uint32_t reason, const char *file, int line))
68 # define OSSL_FUNC_CORE_ADD_ERROR_VDATA        5
69 OSSL_CORE_MAKE_FUNC(void,core_add_error_vdata,(const OSSL_PROVIDER *prov,
70                                                int num, va_list args))
71 # define OSSL_FUNC_CORE_GET_LIBRARY_CONTEXT    6
72 OSSL_CORE_MAKE_FUNC(OPENSSL_CTX *,core_get_library_context,
73                     (const OSSL_PROVIDER *prov))
74
75
76 /* Functions provided by the provider to the Core, reserved numbers 1024-1535 */
77 # define OSSL_FUNC_PROVIDER_TEARDOWN         1024
78 OSSL_CORE_MAKE_FUNC(void,provider_teardown,(void *provctx))
79 # define OSSL_FUNC_PROVIDER_GET_PARAM_TYPES  1025
80 OSSL_CORE_MAKE_FUNC(const OSSL_ITEM *,
81                     provider_get_param_types,(void *provctx))
82 # define OSSL_FUNC_PROVIDER_GET_PARAMS       1026
83 OSSL_CORE_MAKE_FUNC(int,provider_get_params,(void *provctx,
84                                              OSSL_PARAM params[]))
85 # define OSSL_FUNC_PROVIDER_QUERY_OPERATION  1027
86 OSSL_CORE_MAKE_FUNC(const OSSL_ALGORITHM *,provider_query_operation,
87                     (void *provctx, int operation_id, const int *no_store))
88 # define OSSL_FUNC_PROVIDER_GET_REASON_STRINGS 1028
89 OSSL_CORE_MAKE_FUNC(const OSSL_ITEM *,provider_get_reason_strings,
90                     (void *provctx))
91
92 /* Digests */
93
94 # define OSSL_OP_DIGEST                     1
95
96 # define OSSL_FUNC_DIGEST_NEWCTX            1
97 # define OSSL_FUNC_DIGEST_INIT              2
98 # define OSSL_FUNC_DIGEST_UPDATE            3
99 # define OSSL_FUNC_DIGEST_FINAL             4
100 # define OSSL_FUNC_DIGEST_DIGEST            5
101 # define OSSL_FUNC_DIGEST_FREECTX           6
102 # define OSSL_FUNC_DIGEST_DUPCTX            7
103 # define OSSL_FUNC_DIGEST_SIZE              8
104 # define OSSL_FUNC_DIGEST_BLOCK_SIZE        9
105 # define OSSL_FUNC_DIGEST_SET_PARAMS        10
106 # define OSSL_FUNC_DIGEST_GET_PARAMS        11
107
108 OSSL_CORE_MAKE_FUNC(void *, OP_digest_newctx, (void *provctx))
109 OSSL_CORE_MAKE_FUNC(int, OP_digest_init, (void *dctx))
110 OSSL_CORE_MAKE_FUNC(int, OP_digest_update,
111                     (void *dctx, const unsigned char *in, size_t inl))
112 OSSL_CORE_MAKE_FUNC(int, OP_digest_final,
113                     (void *dctx,
114                      unsigned char *out, size_t *outl, size_t outsz))
115 OSSL_CORE_MAKE_FUNC(int, OP_digest_digest,
116                     (void *provctx, const unsigned char *in, size_t inl,
117                      unsigned char *out, size_t *out_l, size_t outsz))
118
119 OSSL_CORE_MAKE_FUNC(void, OP_digest_cleanctx, (void *dctx))
120 OSSL_CORE_MAKE_FUNC(void, OP_digest_freectx, (void *dctx))
121 OSSL_CORE_MAKE_FUNC(void *, OP_digest_dupctx, (void *dctx))
122
123 OSSL_CORE_MAKE_FUNC(size_t, OP_digest_size, (void))
124 OSSL_CORE_MAKE_FUNC(size_t, OP_digest_block_size, (void))
125 OSSL_CORE_MAKE_FUNC(int, OP_digest_set_params,
126                     (void *vctx, const OSSL_PARAM params[]))
127 OSSL_CORE_MAKE_FUNC(int, OP_digest_get_params,
128                     (void *vctx, OSSL_PARAM params[]))
129
130 /* Symmetric Ciphers */
131
132 # define OSSL_OP_CIPHER                              2
133
134 # define OSSL_FUNC_CIPHER_NEWCTX                     1
135 # define OSSL_FUNC_CIPHER_ENCRYPT_INIT               2
136 # define OSSL_FUNC_CIPHER_DECRYPT_INIT               3
137 # define OSSL_FUNC_CIPHER_UPDATE                     4
138 # define OSSL_FUNC_CIPHER_FINAL                      5
139 # define OSSL_FUNC_CIPHER_CIPHER                     6
140 # define OSSL_FUNC_CIPHER_FREECTX                    7
141 # define OSSL_FUNC_CIPHER_DUPCTX                     8
142 # define OSSL_FUNC_CIPHER_KEY_LENGTH                 9
143 # define OSSL_FUNC_CIPHER_IV_LENGTH                 10
144 # define OSSL_FUNC_CIPHER_BLOCK_SIZE                11
145 # define OSSL_FUNC_CIPHER_GET_PARAMS                12
146 # define OSSL_FUNC_CIPHER_CTX_GET_PARAMS            13
147 # define OSSL_FUNC_CIPHER_CTX_SET_PARAMS            14
148
149 OSSL_CORE_MAKE_FUNC(void *, OP_cipher_newctx, (void *provctx))
150 OSSL_CORE_MAKE_FUNC(int, OP_cipher_encrypt_init, (void *cctx,
151                                                   const unsigned char *key,
152                                                   size_t keylen,
153                                                   const unsigned char *iv,
154                                                   size_t ivlen))
155 OSSL_CORE_MAKE_FUNC(int, OP_cipher_decrypt_init, (void *cctx,
156                                                   const unsigned char *key,
157                                                   size_t keylen,
158                                                   const unsigned char *iv,
159                                                   size_t ivlen))
160 OSSL_CORE_MAKE_FUNC(int, OP_cipher_update,
161                     (void *cctx,
162                      unsigned char *out, size_t *outl, size_t outsize,
163                      const unsigned char *in, size_t inl))
164 OSSL_CORE_MAKE_FUNC(int, OP_cipher_final,
165                     (void *cctx,
166                      unsigned char *out, size_t *outl, size_t outsize))
167 OSSL_CORE_MAKE_FUNC(int, OP_cipher_cipher,
168                     (void *cctx,
169                      unsigned char *out, size_t *outl, size_t outsize,
170                      const unsigned char *in, size_t inl))
171 OSSL_CORE_MAKE_FUNC(void, OP_cipher_freectx, (void *cctx))
172 OSSL_CORE_MAKE_FUNC(void *, OP_cipher_dupctx, (void *cctx))
173 OSSL_CORE_MAKE_FUNC(size_t, OP_cipher_key_length, (void))
174 OSSL_CORE_MAKE_FUNC(size_t, OP_cipher_iv_length, (void))
175 OSSL_CORE_MAKE_FUNC(size_t, OP_cipher_block_size, (void))
176 OSSL_CORE_MAKE_FUNC(int, OP_cipher_get_params, (OSSL_PARAM params[]))
177 OSSL_CORE_MAKE_FUNC(int, OP_cipher_ctx_get_params, (void *cctx,
178                                                     OSSL_PARAM params[]))
179 OSSL_CORE_MAKE_FUNC(int, OP_cipher_ctx_set_params, (void *cctx,
180                                                     const OSSL_PARAM params[]))
181
182 # ifdef __cplusplus
183 }
184 # endif
185
186 #endif