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