Coverage Report

Created: 2026-10-28 06:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl36/providers/implementations/ciphers/cipher_aes_cts.inc
Line
Count
Source
1
/*
2
 * Copyright 2020-2026 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 <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 aes_cbc_cts_einit;
18
static OSSL_FUNC_cipher_decrypt_init_fn aes_cbc_cts_dinit;
19
static OSSL_FUNC_cipher_get_ctx_params_fn aes_cbc_cts_get_ctx_params;
20
static OSSL_FUNC_cipher_set_ctx_params_fn aes_cbc_cts_set_ctx_params;
21
static OSSL_FUNC_cipher_gettable_ctx_params_fn aes_cbc_cts_gettable_ctx_params;
22
static OSSL_FUNC_cipher_settable_ctx_params_fn aes_cbc_cts_settable_ctx_params;
23
24
CIPHER_DEFAULT_GETTABLE_CTX_PARAMS_START(aes_cbc_cts)
25
OSSL_PARAM_utf8_string(OSSL_CIPHER_PARAM_CTS_MODE, NULL, 0),
26
#ifdef FIPS_MODULE
27
OSSL_PARAM_int(OSSL_CIPHER_PARAM_FIPS_APPROVED_INDICATOR, NULL),
28
#endif
29
CIPHER_DEFAULT_GETTABLE_CTX_PARAMS_END(aes_cbc_cts)
30
31
static int aes_cbc_cts_einit(void *ctx, const unsigned char *key, size_t keylen,
32
                             const unsigned char *iv, size_t ivlen,
33
                             const OSSL_PARAM params[])
34
17
{
35
17
    if (!ossl_cipher_generic_einit(ctx, key, keylen, iv, ivlen, NULL))
36
0
        return 0;
37
17
    return aes_cbc_cts_set_ctx_params(ctx, params);
38
17
}
39
40
static int aes_cbc_cts_dinit(void *ctx, const unsigned char *key, size_t keylen,
41
                             const unsigned char *iv, size_t ivlen,
42
                             const OSSL_PARAM params[])
43
0
{
44
0
    if (!ossl_cipher_generic_dinit(ctx, key, keylen, iv, ivlen, NULL))
45
0
        return 0;
46
0
    return aes_cbc_cts_set_ctx_params(ctx, params);
47
0
}
48
49
static int aes_cbc_cts_get_ctx_params(void *vctx, OSSL_PARAM params[])
50
4
{
51
4
    PROV_CIPHER_CTX *ctx = (PROV_CIPHER_CTX *)vctx;
52
4
    OSSL_PARAM *p;
53
54
4
    p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_CTS_MODE);
55
4
    if (p != NULL) {
56
0
        const char *name = ossl_cipher_cbc_cts_mode_id2name(ctx->cts_mode);
57
58
0
        if (name == NULL || !OSSL_PARAM_set_utf8_string(p, name)) {
59
0
            ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER);
60
0
            return 0;
61
0
        }
62
0
    }
63
4
    return ossl_cipher_generic_get_ctx_params(vctx, params);
64
4
}
65
66
CIPHER_DEFAULT_SETTABLE_CTX_PARAMS_START(aes_cbc_cts)
67
OSSL_PARAM_utf8_string(OSSL_CIPHER_PARAM_CTS_MODE, NULL, 0),
68
CIPHER_DEFAULT_SETTABLE_CTX_PARAMS_END(aes_cbc_cts)
69
70
static int aes_cbc_cts_set_ctx_params(void *vctx, const OSSL_PARAM params[])
71
5
{
72
5
    PROV_CIPHER_CTX *ctx = (PROV_CIPHER_CTX *)vctx;
73
5
    const OSSL_PARAM *p;
74
5
    int id;
75
76
5
    p = OSSL_PARAM_locate_const(params, OSSL_CIPHER_PARAM_CTS_MODE);
77
5
    if (p != NULL) {
78
0
        if (p->data_type != OSSL_PARAM_UTF8_STRING)
79
0
            goto err;
80
0
        id = ossl_cipher_cbc_cts_mode_name2id(p->data);
81
0
        if (id < 0)
82
0
            goto err;
83
84
0
        ctx->cts_mode = (unsigned int)id;
85
0
    }
86
5
    return ossl_cipher_generic_set_ctx_params(vctx, params);
87
0
err:
88
    ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER);
89
0
    return 0;
90
5
}
91
92
/* ossl_aes256cbc_cts_functions */
93
IMPLEMENT_cts_cipher(aes, AES, cbc, CBC, CTS_FLAGS, 256, 128, 128, block)
94
/* ossl_aes192cbc_cts_functions */
95
IMPLEMENT_cts_cipher(aes, AES, cbc, CBC, CTS_FLAGS, 192, 128, 128, block)
96
/* ossl_aes128cbc_cts_functions */
97
IMPLEMENT_cts_cipher(aes, AES, cbc, CBC, CTS_FLAGS, 128, 128, 128, block)