xref: /freebsd-src/crypto/openssl/providers/implementations/include/prov/ciphercommon_aead.h (revision e0c4386e7e71d93b0edc0c8fa156263fc4a8b0b6)
1b077aed3SPierre Pronchery /*
2*e0c4386eSCy Schubert  * Copyright 2019-2024 The OpenSSL Project Authors. All Rights Reserved.
3b077aed3SPierre Pronchery  *
4b077aed3SPierre Pronchery  * Licensed under the Apache License 2.0 (the "License").  You may not use
5b077aed3SPierre Pronchery  * this file except in compliance with the License.  You can obtain a copy
6b077aed3SPierre Pronchery  * in the file LICENSE in the source distribution or at
7b077aed3SPierre Pronchery  * https://www.openssl.org/source/license.html
8b077aed3SPierre Pronchery  */
9b077aed3SPierre Pronchery 
10b077aed3SPierre Pronchery #define UNINITIALISED_SIZET ((size_t)-1)
11b077aed3SPierre Pronchery 
12b077aed3SPierre Pronchery #define AEAD_FLAGS (PROV_CIPHER_FLAG_AEAD | PROV_CIPHER_FLAG_CUSTOM_IV)
13b077aed3SPierre Pronchery 
14b077aed3SPierre Pronchery #define IMPLEMENT_aead_cipher(alg, lc, UCMODE, flags, kbits, blkbits, ivbits)  \
15b077aed3SPierre Pronchery static OSSL_FUNC_cipher_get_params_fn alg##_##kbits##_##lc##_get_params;       \
16b077aed3SPierre Pronchery static int alg##_##kbits##_##lc##_get_params(OSSL_PARAM params[])              \
17b077aed3SPierre Pronchery {                                                                              \
18b077aed3SPierre Pronchery     return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,    \
19b077aed3SPierre Pronchery                                           flags, kbits, blkbits, ivbits);      \
20b077aed3SPierre Pronchery }                                                                              \
21b077aed3SPierre Pronchery static OSSL_FUNC_cipher_newctx_fn alg##kbits##lc##_newctx;                     \
22b077aed3SPierre Pronchery static void * alg##kbits##lc##_newctx(void *provctx)                           \
23b077aed3SPierre Pronchery {                                                                              \
24b077aed3SPierre Pronchery     return alg##_##lc##_newctx(provctx, kbits);                                \
25b077aed3SPierre Pronchery }                                                                              \
26*e0c4386eSCy Schubert static void * alg##kbits##lc##_dupctx(void *src)                               \
27*e0c4386eSCy Schubert {                                                                              \
28*e0c4386eSCy Schubert     return alg##_##lc##_dupctx(src);                                           \
29*e0c4386eSCy Schubert }                                                                              \
30b077aed3SPierre Pronchery const OSSL_DISPATCH ossl_##alg##kbits##lc##_functions[] = {                    \
31b077aed3SPierre Pronchery     { OSSL_FUNC_CIPHER_NEWCTX, (void (*)(void))alg##kbits##lc##_newctx },      \
32b077aed3SPierre Pronchery     { OSSL_FUNC_CIPHER_FREECTX, (void (*)(void))alg##_##lc##_freectx },        \
33*e0c4386eSCy Schubert     { OSSL_FUNC_CIPHER_DUPCTX, (void (*)(void))alg##kbits##lc##_dupctx },      \
34b077aed3SPierre Pronchery     { OSSL_FUNC_CIPHER_ENCRYPT_INIT, (void (*)(void))ossl_##lc##_einit },      \
35b077aed3SPierre Pronchery     { OSSL_FUNC_CIPHER_DECRYPT_INIT, (void (*)(void))ossl_##lc##_dinit },      \
36b077aed3SPierre Pronchery     { OSSL_FUNC_CIPHER_UPDATE, (void (*)(void))ossl_##lc##_stream_update },    \
37b077aed3SPierre Pronchery     { OSSL_FUNC_CIPHER_FINAL, (void (*)(void))ossl_##lc##_stream_final },      \
38b077aed3SPierre Pronchery     { OSSL_FUNC_CIPHER_CIPHER, (void (*)(void))ossl_##lc##_cipher },           \
39b077aed3SPierre Pronchery     { OSSL_FUNC_CIPHER_GET_PARAMS,                                             \
40b077aed3SPierre Pronchery       (void (*)(void)) alg##_##kbits##_##lc##_get_params },                    \
41b077aed3SPierre Pronchery     { OSSL_FUNC_CIPHER_GET_CTX_PARAMS,                                         \
42b077aed3SPierre Pronchery       (void (*)(void)) ossl_##lc##_get_ctx_params },                           \
43b077aed3SPierre Pronchery     { OSSL_FUNC_CIPHER_SET_CTX_PARAMS,                                         \
44b077aed3SPierre Pronchery       (void (*)(void)) ossl_##lc##_set_ctx_params },                           \
45b077aed3SPierre Pronchery     { OSSL_FUNC_CIPHER_GETTABLE_PARAMS,                                        \
46b077aed3SPierre Pronchery       (void (*)(void))ossl_cipher_generic_gettable_params },                   \
47b077aed3SPierre Pronchery     { OSSL_FUNC_CIPHER_GETTABLE_CTX_PARAMS,                                    \
48b077aed3SPierre Pronchery       (void (*)(void))ossl_cipher_aead_gettable_ctx_params },                  \
49b077aed3SPierre Pronchery     { OSSL_FUNC_CIPHER_SETTABLE_CTX_PARAMS,                                    \
50b077aed3SPierre Pronchery       (void (*)(void))ossl_cipher_aead_settable_ctx_params },                  \
51b077aed3SPierre Pronchery     { 0, NULL }                                                                \
52b077aed3SPierre Pronchery }
53