Coverage Report

Created: 2026-10-28 06:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl41/providers/implementations/ciphers/cipher_aes.c
Line
Count
Source
1
/*
2
 * Copyright 2019-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
/*
11
 * AES low level APIs are deprecated for public use, but still ok for internal
12
 * use where we're using them to implement the higher level EVP interface, as is
13
 * the case here.
14
 */
15
#include "internal/deprecated.h"
16
17
/* Dispatch functions for AES cipher modes ecb, cbc, cts, ofb, cfb, ctr */
18
19
#include "cipher_cts.h"
20
#include "cipher_aes.h"
21
#include "prov/implementations.h"
22
#include "prov/providercommon.h"
23
24
static OSSL_FUNC_cipher_freectx_fn aes_freectx;
25
static OSSL_FUNC_cipher_dupctx_fn aes_dupctx;
26
static OSSL_FUNC_cipher_encrypt_init_fn aes_cbc_cts_einit;
27
static OSSL_FUNC_cipher_decrypt_init_fn aes_cbc_cts_dinit;
28
29
static void aes_freectx(void *vctx)
30
249k
{
31
249k
    PROV_AES_CTX *ctx = (PROV_AES_CTX *)vctx;
32
33
249k
    ossl_cipher_generic_reset_ctx((PROV_CIPHER_CTX *)vctx);
34
249k
    OPENSSL_clear_free(ctx, sizeof(*ctx));
35
249k
}
36
37
static void *aes_dupctx(void *ctx)
38
30
{
39
30
    PROV_AES_CTX *in = (PROV_AES_CTX *)ctx;
40
30
    PROV_AES_CTX *ret;
41
42
30
    if (!ossl_prov_is_running())
43
0
        return NULL;
44
45
30
    ret = OPENSSL_malloc(sizeof(*ret));
46
30
    if (ret == NULL)
47
0
        return NULL;
48
30
    in->base.hw->copyctx(&ret->base, &in->base);
49
30
    if (!ossl_cipher_generic_dupctx_tlsmac(&ret->base, &in->base)) {
50
0
        OPENSSL_clear_free(ret, sizeof(*ret));
51
0
        return NULL;
52
0
    }
53
30
    return ret;
54
30
}
55
56
static int aes_cbc_cts_einit(void *ctx, const unsigned char *key, size_t keylen,
57
    const unsigned char *iv, size_t ivlen,
58
    const OSSL_PARAM params[])
59
17
{
60
17
    if (!ossl_cipher_generic_einit(ctx, key, keylen, iv, ivlen, NULL))
61
0
        return 0;
62
17
    return ossl_cipher_cbc_cts_set_ctx_params(ctx, params);
63
17
}
64
65
static int aes_cbc_cts_dinit(void *ctx, const unsigned char *key, size_t keylen,
66
    const unsigned char *iv, size_t ivlen,
67
    const OSSL_PARAM params[])
68
0
{
69
0
    if (!ossl_cipher_generic_dinit(ctx, key, keylen, iv, ivlen, NULL))
70
0
        return 0;
71
0
    return ossl_cipher_cbc_cts_set_ctx_params(ctx, params);
72
0
}
73
74
/* ossl_aes256ecb_functions */
75
33.2k
IMPLEMENT_generic_cipher(aes, AES, ecb, ECB, 0, 256, 128, 0, block)
76
33.2k
/* ossl_aes192ecb_functions */
77
33.2k
IMPLEMENT_generic_cipher(aes, AES, ecb, ECB, 0, 192, 128, 0, block)
78
27
/* ossl_aes128ecb_functions */
79
79.6k
IMPLEMENT_generic_cipher(aes, AES, ecb, ECB, 0, 128, 128, 0, block)
80
79.6k
/* ossl_aes256cbc_functions */
81
79.6k
IMPLEMENT_generic_cipher(aes, AES, cbc, CBC, 0, 256, 128, 128, block)
82
1.58k
/* ossl_aes192cbc_functions */
83
1.58k
IMPLEMENT_generic_cipher(aes, AES, cbc, CBC, 0, 192, 128, 128, block)
84
25
/* ossl_aes128cbc_functions */
85
247
IMPLEMENT_generic_cipher(aes, AES, cbc, CBC, 0, 128, 128, 128, block)
86
247
/* ossl_aes256ofb_functions */
87
247
IMPLEMENT_generic_cipher(aes, AES, ofb, OFB, 0, 256, 8, 128, stream)
88
14
/* ossl_aes192ofb_functions */
89
20
IMPLEMENT_generic_cipher(aes, AES, ofb, OFB, 0, 192, 8, 128, stream)
90
20
/* ossl_aes128ofb_functions */
91
20
IMPLEMENT_generic_cipher(aes, AES, ofb, OFB, 0, 128, 8, 128, stream)
92
14
/* ossl_aes256cfb_functions */
93
26
IMPLEMENT_generic_cipher(aes, AES, cfb, CFB, 0, 256, 8, 128, stream)
94
26
/* ossl_aes192cfb_functions */
95
26
IMPLEMENT_generic_cipher(aes, AES, cfb, CFB, 0, 192, 8, 128, stream)
96
19
/* ossl_aes128cfb_functions */
97
19
IMPLEMENT_generic_cipher(aes, AES, cfb, CFB, 0, 128, 8, 128, stream)
98
13
/* ossl_aes256cfb1_functions */
99
13
IMPLEMENT_generic_cipher(aes, AES, cfb1, CFB, 0, 256, 8, 128, stream)
100
2
/* ossl_aes192cfb1_functions */
101
2
IMPLEMENT_generic_cipher(aes, AES, cfb1, CFB, 0, 192, 8, 128, stream)
102
2
/* ossl_aes128cfb1_functions */
103
3
IMPLEMENT_generic_cipher(aes, AES, cfb1, CFB, 0, 128, 8, 128, stream)
104
3
/* ossl_aes256cfb8_functions */
105
3
IMPLEMENT_generic_cipher(aes, AES, cfb8, CFB, 0, 256, 8, 128, stream)
106
3
/* ossl_aes192cfb8_functions */
107
3
IMPLEMENT_generic_cipher(aes, AES, cfb8, CFB, 0, 192, 8, 128, stream)
108
3
/* ossl_aes128cfb8_functions */
109
3
IMPLEMENT_generic_cipher(aes, AES, cfb8, CFB, 0, 128, 8, 128, stream)
110
3
/* ossl_aes256ctr_functions */
111
50
IMPLEMENT_generic_cipher(aes, AES, ctr, CTR, 0, 256, 8, 128, stream)
112
50
/* ossl_aes192ctr_functions */
113
50
IMPLEMENT_generic_cipher(aes, AES, ctr, CTR, 0, 192, 8, 128, stream)
114
6
/* ossl_aes128ctr_functions */
115
IMPLEMENT_generic_cipher(aes, AES, ctr, CTR, 0, 128, 8, 128, stream)
116
117
/* ossl_aes256cbc_cts_functions */
118
IMPLEMENT_cts_cipher(aes, AES, cbc, CBC, PROV_CIPHER_FLAG_CTS, 256, 128, 128, block)
119
/* ossl_aes192cbc_cts_functions */
120
IMPLEMENT_cts_cipher(aes, AES, cbc, CBC, PROV_CIPHER_FLAG_CTS, 192, 128, 128, block)
121
/* ossl_aes128cbc_cts_functions */
122
IMPLEMENT_cts_cipher(aes, AES, cbc, CBC, PROV_CIPHER_FLAG_CTS, 128, 128, 128, block)