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