1 /*
2  * Copyright 2020-2021 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 #include "crypto/evp.h"
11 
12 /* NOTE: The underlying block cipher is CBC so we reuse most of the code */
13 #define IMPLEMENT_cts_cipher(alg, UCALG, lcmode, UCMODE, flags, kbits,         \
14                              blkbits, ivbits, typ)                             \
15 static OSSL_FUNC_cipher_get_params_fn alg##_##kbits##_##lcmode##_get_params;   \
16 static int alg##_cts_##kbits##_##lcmode##_get_params(OSSL_PARAM params[])      \
17 {                                                                              \
18     return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,    \
19                                           flags, kbits, blkbits, ivbits);      \
20 }                                                                              \
21 const OSSL_DISPATCH ossl_##alg##kbits##lcmode##_cts_functions[] = {            \
22     { OSSL_FUNC_CIPHER_NEWCTX,                                                 \
23       (void (*)(void)) alg##_##kbits##_##lcmode##_newctx },                    \
24     { OSSL_FUNC_CIPHER_FREECTX, (void (*)(void)) alg##_freectx },              \
25     { OSSL_FUNC_CIPHER_DUPCTX, (void (*)(void)) alg##_dupctx },                \
26     { OSSL_FUNC_CIPHER_ENCRYPT_INIT, (void (*)(void)) alg##_cbc_cts_einit },   \
27     { OSSL_FUNC_CIPHER_DECRYPT_INIT, (void (*)(void)) alg##_cbc_cts_dinit },   \
28     { OSSL_FUNC_CIPHER_UPDATE,                                                 \
29       (void (*)(void)) ossl_cipher_cbc_cts_block_update },                     \
30     { OSSL_FUNC_CIPHER_FINAL,                                                  \
31       (void (*)(void)) ossl_cipher_cbc_cts_block_final },                      \
32     { OSSL_FUNC_CIPHER_CIPHER, (void (*)(void))ossl_cipher_generic_cipher },   \
33     { OSSL_FUNC_CIPHER_GET_PARAMS,                                             \
34       (void (*)(void)) alg##_cts_##kbits##_##lcmode##_get_params },            \
35     { OSSL_FUNC_CIPHER_GETTABLE_PARAMS,                                        \
36       (void (*)(void))ossl_cipher_generic_gettable_params },                   \
37     { OSSL_FUNC_CIPHER_GET_CTX_PARAMS,                                         \
38       (void (*)(void)) alg##_cbc_cts_get_ctx_params },                         \
39     { OSSL_FUNC_CIPHER_SET_CTX_PARAMS,                                         \
40       (void (*)(void)) alg##_cbc_cts_set_ctx_params },                         \
41     { OSSL_FUNC_CIPHER_GETTABLE_CTX_PARAMS,                                    \
42       (void (*)(void)) alg##_cbc_cts_gettable_ctx_params },                    \
43     { OSSL_FUNC_CIPHER_SETTABLE_CTX_PARAMS,                                    \
44      (void (*)(void)) alg##_cbc_cts_settable_ctx_params },                     \
45     { 0, NULL }                                                                \
46 };
47 
48 OSSL_FUNC_cipher_update_fn ossl_cipher_cbc_cts_block_update;
49 OSSL_FUNC_cipher_final_fn ossl_cipher_cbc_cts_block_final;
50 
51 const char *ossl_cipher_cbc_cts_mode_id2name(unsigned int id);
52 int ossl_cipher_cbc_cts_mode_name2id(const char *name);
53