]> git.ipfire.org Git - thirdparty/openssl.git/blame - providers/implementations/ciphers/cipher_aes_cts.inc
prov: prefix all OSSL_DISPATCH tables names with ossl_
[thirdparty/openssl.git] / providers / implementations / ciphers / cipher_aes_cts.inc
CommitLineData
7cc355c2
SL
1/*
2 * Copyright 2020 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/* Dispatch functions for AES CBC CTS ciphers */
11
12#include "cipher_aes_cts.h"
13#include "prov/providercommonerr.h"
14
15static OSSL_FUNC_cipher_get_ctx_params_fn aes_cbc_cts_get_ctx_params;
16static OSSL_FUNC_cipher_set_ctx_params_fn aes_cbc_cts_set_ctx_params;
17static OSSL_FUNC_cipher_gettable_ctx_params_fn aes_cbc_cts_gettable_ctx_params;
18static OSSL_FUNC_cipher_settable_ctx_params_fn aes_cbc_cts_settable_ctx_params;
19
20CIPHER_DEFAULT_GETTABLE_CTX_PARAMS_START(aes_cbc_cts)
21OSSL_PARAM_utf8_string(OSSL_CIPHER_PARAM_CTS_MODE, NULL, 0),
22CIPHER_DEFAULT_GETTABLE_CTX_PARAMS_END(aes_cbc_cts)
23
24static int aes_cbc_cts_get_ctx_params(void *vctx, OSSL_PARAM params[])
25{
26 PROV_CIPHER_CTX *ctx = (PROV_CIPHER_CTX *)vctx;
27 OSSL_PARAM *p;
28
29 p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_CTS_MODE);
30 if (p != NULL) {
31 const char *name = aes_cbc_cts_mode_id2name(ctx->cts_mode);
32
33 if (name == NULL || !OSSL_PARAM_set_utf8_string(p, name)) {
34 ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER);
35 return 0;
36 }
37 }
38 return cipher_generic_get_ctx_params(vctx, params);
39}
40
41CIPHER_DEFAULT_SETTABLE_CTX_PARAMS_START(aes_cbc_cts)
42OSSL_PARAM_utf8_string(OSSL_CIPHER_PARAM_CTS_MODE, NULL, 0),
43CIPHER_DEFAULT_SETTABLE_CTX_PARAMS_END(aes_cbc_cts)
44
45static int aes_cbc_cts_set_ctx_params(void *vctx, const OSSL_PARAM params[])
46{
47 PROV_CIPHER_CTX *ctx = (PROV_CIPHER_CTX *)vctx;
48 const OSSL_PARAM *p;
49 int id;
50
51 p = OSSL_PARAM_locate_const(params, OSSL_CIPHER_PARAM_CTS_MODE);
52 if (p != NULL) {
53 if (p->data_type != OSSL_PARAM_UTF8_STRING)
54 goto err;
55 id = aes_cbc_cts_mode_name2id(p->data);
56 if (id < 0)
57 goto err;
58
59 ctx->cts_mode = (unsigned int)id;
60 }
61 return cipher_generic_set_ctx_params(vctx, params);
62err:
63 ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER);
64 return 0;
65}
66
67/* NOTE: The underlying block cipher is AES CBC so we reuse most of the code */
68#define IMPLEMENT_cts_cipher(alg, UCALG, lcmode, UCMODE, flags, kbits, \
69 blkbits, ivbits, typ) \
70static OSSL_FUNC_cipher_get_params_fn alg##_##kbits##_##lcmode##_get_params; \
71static int alg##_cts_##kbits##_##lcmode##_get_params(OSSL_PARAM params[]) \
72{ \
73 return cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE, flags, \
74 kbits, blkbits, ivbits); \
75} \
1be63951 76const OSSL_DISPATCH ossl_##alg##kbits##lcmode##_cts_functions[] = { \
7cc355c2
SL
77 { OSSL_FUNC_CIPHER_NEWCTX, \
78 (void (*)(void)) alg##_##kbits##_##lcmode##_newctx }, \
79 { OSSL_FUNC_CIPHER_FREECTX, (void (*)(void)) alg##_freectx }, \
80 { OSSL_FUNC_CIPHER_DUPCTX, (void (*)(void)) alg##_dupctx }, \
81 { OSSL_FUNC_CIPHER_ENCRYPT_INIT, (void (*)(void))cipher_generic_einit }, \
82 { OSSL_FUNC_CIPHER_DECRYPT_INIT, (void (*)(void))cipher_generic_dinit }, \
83 { OSSL_FUNC_CIPHER_UPDATE, \
84 (void (*)(void)) alg##_##lcmode##_cts_block_update }, \
85 { OSSL_FUNC_CIPHER_FINAL, \
86 (void (*)(void)) alg##_##lcmode##_cts_block_final }, \
87 { OSSL_FUNC_CIPHER_CIPHER, (void (*)(void))cipher_generic_cipher }, \
88 { OSSL_FUNC_CIPHER_GET_PARAMS, \
89 (void (*)(void)) alg##_cts_##kbits##_##lcmode##_get_params }, \
90 { OSSL_FUNC_CIPHER_GETTABLE_PARAMS, \
91 (void (*)(void))cipher_generic_gettable_params }, \
92 { OSSL_FUNC_CIPHER_GET_CTX_PARAMS, \
93 (void (*)(void))aes_cbc_cts_get_ctx_params }, \
94 { OSSL_FUNC_CIPHER_SET_CTX_PARAMS, \
95 (void (*)(void))aes_cbc_cts_set_ctx_params }, \
96 { OSSL_FUNC_CIPHER_GETTABLE_CTX_PARAMS, \
97 (void (*)(void))aes_cbc_cts_gettable_ctx_params }, \
98 { OSSL_FUNC_CIPHER_SETTABLE_CTX_PARAMS, \
99 (void (*)(void))aes_cbc_cts_settable_ctx_params }, \
100 { 0, NULL } \
101};
102
1be63951 103/* ossl_aes256cbc_cts_functions */
7cc355c2 104IMPLEMENT_cts_cipher(aes, AES, cbc, CBC, EVP_CIPH_FLAG_CTS, 256, 128, 128, block)
1be63951 105/* ossl_aes192cbc_cts_functions */
7cc355c2 106IMPLEMENT_cts_cipher(aes, AES, cbc, CBC, EVP_CIPH_FLAG_CTS, 192, 128, 128, block)
1be63951 107/* ossl_aes128cbc_cts_functions */
7cc355c2 108IMPLEMENT_cts_cipher(aes, AES, cbc, CBC, EVP_CIPH_FLAG_CTS, 128, 128, 128, block)