1e1051a39Sopenharmony_ci/*
2e1051a39Sopenharmony_ci * Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
3e1051a39Sopenharmony_ci *
4e1051a39Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License").  You may not use
5e1051a39Sopenharmony_ci * this file except in compliance with the License.  You can obtain a copy
6e1051a39Sopenharmony_ci * in the file LICENSE in the source distribution or at
7e1051a39Sopenharmony_ci * https://www.openssl.org/source/license.html
8e1051a39Sopenharmony_ci */
9e1051a39Sopenharmony_ci
10e1051a39Sopenharmony_ci#include "crypto/evp.h"
11e1051a39Sopenharmony_ci
12e1051a39Sopenharmony_ci/* NOTE: The underlying block cipher is CBC so we reuse most of the code */
13e1051a39Sopenharmony_ci#define IMPLEMENT_cts_cipher(alg, UCALG, lcmode, UCMODE, flags, kbits,         \
14e1051a39Sopenharmony_ci                             blkbits, ivbits, typ)                             \
15e1051a39Sopenharmony_cistatic OSSL_FUNC_cipher_get_params_fn alg##_##kbits##_##lcmode##_get_params;   \
16e1051a39Sopenharmony_cistatic int alg##_cts_##kbits##_##lcmode##_get_params(OSSL_PARAM params[])      \
17e1051a39Sopenharmony_ci{                                                                              \
18e1051a39Sopenharmony_ci    return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,    \
19e1051a39Sopenharmony_ci                                          flags, kbits, blkbits, ivbits);      \
20e1051a39Sopenharmony_ci}                                                                              \
21e1051a39Sopenharmony_ciconst OSSL_DISPATCH ossl_##alg##kbits##lcmode##_cts_functions[] = {            \
22e1051a39Sopenharmony_ci    { OSSL_FUNC_CIPHER_NEWCTX,                                                 \
23e1051a39Sopenharmony_ci      (void (*)(void)) alg##_##kbits##_##lcmode##_newctx },                    \
24e1051a39Sopenharmony_ci    { OSSL_FUNC_CIPHER_FREECTX, (void (*)(void)) alg##_freectx },              \
25e1051a39Sopenharmony_ci    { OSSL_FUNC_CIPHER_DUPCTX, (void (*)(void)) alg##_dupctx },                \
26e1051a39Sopenharmony_ci    { OSSL_FUNC_CIPHER_ENCRYPT_INIT, (void (*)(void)) alg##_cbc_cts_einit },   \
27e1051a39Sopenharmony_ci    { OSSL_FUNC_CIPHER_DECRYPT_INIT, (void (*)(void)) alg##_cbc_cts_dinit },   \
28e1051a39Sopenharmony_ci    { OSSL_FUNC_CIPHER_UPDATE,                                                 \
29e1051a39Sopenharmony_ci      (void (*)(void)) ossl_cipher_cbc_cts_block_update },                     \
30e1051a39Sopenharmony_ci    { OSSL_FUNC_CIPHER_FINAL,                                                  \
31e1051a39Sopenharmony_ci      (void (*)(void)) ossl_cipher_cbc_cts_block_final },                      \
32e1051a39Sopenharmony_ci    { OSSL_FUNC_CIPHER_CIPHER, (void (*)(void))ossl_cipher_generic_cipher },   \
33e1051a39Sopenharmony_ci    { OSSL_FUNC_CIPHER_GET_PARAMS,                                             \
34e1051a39Sopenharmony_ci      (void (*)(void)) alg##_cts_##kbits##_##lcmode##_get_params },            \
35e1051a39Sopenharmony_ci    { OSSL_FUNC_CIPHER_GETTABLE_PARAMS,                                        \
36e1051a39Sopenharmony_ci      (void (*)(void))ossl_cipher_generic_gettable_params },                   \
37e1051a39Sopenharmony_ci    { OSSL_FUNC_CIPHER_GET_CTX_PARAMS,                                         \
38e1051a39Sopenharmony_ci      (void (*)(void)) alg##_cbc_cts_get_ctx_params },                         \
39e1051a39Sopenharmony_ci    { OSSL_FUNC_CIPHER_SET_CTX_PARAMS,                                         \
40e1051a39Sopenharmony_ci      (void (*)(void)) alg##_cbc_cts_set_ctx_params },                         \
41e1051a39Sopenharmony_ci    { OSSL_FUNC_CIPHER_GETTABLE_CTX_PARAMS,                                    \
42e1051a39Sopenharmony_ci      (void (*)(void)) alg##_cbc_cts_gettable_ctx_params },                    \
43e1051a39Sopenharmony_ci    { OSSL_FUNC_CIPHER_SETTABLE_CTX_PARAMS,                                    \
44e1051a39Sopenharmony_ci     (void (*)(void)) alg##_cbc_cts_settable_ctx_params },                     \
45e1051a39Sopenharmony_ci    { 0, NULL }                                                                \
46e1051a39Sopenharmony_ci};
47e1051a39Sopenharmony_ci
48e1051a39Sopenharmony_ciOSSL_FUNC_cipher_update_fn ossl_cipher_cbc_cts_block_update;
49e1051a39Sopenharmony_ciOSSL_FUNC_cipher_final_fn ossl_cipher_cbc_cts_block_final;
50e1051a39Sopenharmony_ci
51e1051a39Sopenharmony_ciconst char *ossl_cipher_cbc_cts_mode_id2name(unsigned int id);
52e1051a39Sopenharmony_ciint ossl_cipher_cbc_cts_mode_name2id(const char *name);
53