/src/openssl32/providers/implementations/ciphers/cipher_camellia_cts.inc
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 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 | | /* Dispatch functions for CAMELLIA CBC CTS ciphers */ |
11 | | |
12 | | #include <openssl/proverr.h> |
13 | | #include "cipher_cts.h" |
14 | | |
15 | | #define CTS_FLAGS PROV_CIPHER_FLAG_CTS |
16 | | |
17 | | static OSSL_FUNC_cipher_encrypt_init_fn camellia_cbc_cts_einit; |
18 | | static OSSL_FUNC_cipher_decrypt_init_fn camellia_cbc_cts_dinit; |
19 | | static OSSL_FUNC_cipher_get_ctx_params_fn camellia_cbc_cts_get_ctx_params; |
20 | | static OSSL_FUNC_cipher_set_ctx_params_fn camellia_cbc_cts_set_ctx_params; |
21 | | static OSSL_FUNC_cipher_gettable_ctx_params_fn camellia_cbc_cts_gettable_ctx_params; |
22 | | static OSSL_FUNC_cipher_settable_ctx_params_fn camellia_cbc_cts_settable_ctx_params; |
23 | | |
24 | | CIPHER_DEFAULT_GETTABLE_CTX_PARAMS_START(camellia_cbc_cts) |
25 | | OSSL_PARAM_utf8_string(OSSL_CIPHER_PARAM_CTS_MODE, NULL, 0), |
26 | | CIPHER_DEFAULT_GETTABLE_CTX_PARAMS_END(camellia_cbc_cts) |
27 | | |
28 | | static int camellia_cbc_cts_einit(void *ctx, const unsigned char *key, size_t keylen, |
29 | | const unsigned char *iv, size_t ivlen, |
30 | | const OSSL_PARAM params[]) |
31 | 0 | { |
32 | 0 | if (!ossl_cipher_generic_einit(ctx, key, keylen, iv, ivlen, NULL)) |
33 | 0 | return 0; |
34 | 0 | return camellia_cbc_cts_set_ctx_params(ctx, params); |
35 | 0 | } |
36 | | |
37 | | static int camellia_cbc_cts_dinit(void *ctx, const unsigned char *key, size_t keylen, |
38 | | const unsigned char *iv, size_t ivlen, |
39 | | const OSSL_PARAM params[]) |
40 | 0 | { |
41 | 0 | if (!ossl_cipher_generic_dinit(ctx, key, keylen, iv, ivlen, NULL)) |
42 | 0 | return 0; |
43 | 0 | return camellia_cbc_cts_set_ctx_params(ctx, params); |
44 | 0 | } |
45 | | |
46 | | static int camellia_cbc_cts_get_ctx_params(void *vctx, OSSL_PARAM params[]) |
47 | 0 | { |
48 | 0 | PROV_CIPHER_CTX *ctx = (PROV_CIPHER_CTX *)vctx; |
49 | 0 | OSSL_PARAM *p; |
50 | |
|
51 | 0 | p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_CTS_MODE); |
52 | 0 | if (p != NULL) { |
53 | 0 | const char *name = ossl_cipher_cbc_cts_mode_id2name(ctx->cts_mode); |
54 | |
|
55 | 0 | if (name == NULL || !OSSL_PARAM_set_utf8_string(p, name)) { |
56 | 0 | ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER); |
57 | 0 | return 0; |
58 | 0 | } |
59 | 0 | } |
60 | 0 | return ossl_cipher_generic_get_ctx_params(vctx, params); |
61 | 0 | } |
62 | | |
63 | | CIPHER_DEFAULT_SETTABLE_CTX_PARAMS_START(camellia_cbc_cts) |
64 | | OSSL_PARAM_utf8_string(OSSL_CIPHER_PARAM_CTS_MODE, NULL, 0), |
65 | | CIPHER_DEFAULT_SETTABLE_CTX_PARAMS_END(camellia_cbc_cts) |
66 | | |
67 | | static int camellia_cbc_cts_set_ctx_params(void *vctx, const OSSL_PARAM params[]) |
68 | 0 | { |
69 | 0 | PROV_CIPHER_CTX *ctx = (PROV_CIPHER_CTX *)vctx; |
70 | 0 | const OSSL_PARAM *p; |
71 | 0 | int id; |
72 | |
|
73 | 0 | p = OSSL_PARAM_locate_const(params, OSSL_CIPHER_PARAM_CTS_MODE); |
74 | 0 | if (p != NULL) { |
75 | 0 | if (p->data_type != OSSL_PARAM_UTF8_STRING) |
76 | 0 | goto err; |
77 | 0 | id = ossl_cipher_cbc_cts_mode_name2id(p->data); |
78 | 0 | if (id < 0) |
79 | 0 | goto err; |
80 | | |
81 | 0 | ctx->cts_mode = (unsigned int)id; |
82 | 0 | } |
83 | 0 | return ossl_cipher_generic_set_ctx_params(vctx, params); |
84 | 0 | err: |
85 | 0 | ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER); |
86 | 0 | return 0; |
87 | 0 | } |
88 | | |
89 | | /* ossl_camellia256cbc_cts_functions */ |
90 | | IMPLEMENT_cts_cipher(camellia, CAMELLIA, cbc, CBC, CTS_FLAGS, 256, 128, 128, block) |
91 | | /* ossl_camellia192cbc_cts_functions */ |
92 | | IMPLEMENT_cts_cipher(camellia, CAMELLIA, cbc, CBC, CTS_FLAGS, 192, 128, 128, block) |
93 | | /* ossl_camellia128cbc_cts_functions */ |
94 | | IMPLEMENT_cts_cipher(camellia, CAMELLIA, cbc, CBC, CTS_FLAGS, 128, 128, 128, block) |