Coverage Report

Created: 2026-09-12 06:55

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
196k
{
31
196k
    PROV_AES_CTX *ctx = (PROV_AES_CTX *)vctx;
32
33
196k
    ossl_cipher_generic_reset_ctx((PROV_CIPHER_CTX *)vctx);
34
196k
    OPENSSL_clear_free(ctx, sizeof(*ctx));
35
196k
}
36
37
static void *aes_dupctx(void *ctx)
38
20
{
39
20
    PROV_AES_CTX *in = (PROV_AES_CTX *)ctx;
40
20
    PROV_AES_CTX *ret;
41
42
20
    if (!ossl_prov_is_running())
43
0
        return NULL;
44
45
20
    ret = OPENSSL_malloc(sizeof(*ret));
46
20
    if (ret == NULL)
47
0
        return NULL;
48
20
    in->base.hw->copyctx(&ret->base, &in->base);
49
20
    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
20
    return ret;
54
20
}
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
7
{
60
7
    if (!ossl_cipher_generic_einit(ctx, key, keylen, iv, ivlen, NULL))
61
0
        return 0;
62
7
    return ossl_cipher_cbc_cts_set_ctx_params(ctx, params);
63
7
}
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
21.8k
IMPLEMENT_generic_cipher(aes, AES, ecb, ECB, 0, 256, 128, 0, block)
76
21.8k
/* ossl_aes192ecb_functions */
77
21.8k
IMPLEMENT_generic_cipher(aes, AES, ecb, ECB, 0, 192, 128, 0, block)
78
15
/* ossl_aes128ecb_functions */
79
52.6k
IMPLEMENT_generic_cipher(aes, AES, ecb, ECB, 0, 128, 128, 0, block)
80
52.6k
/* ossl_aes256cbc_functions */
81
52.6k
IMPLEMENT_generic_cipher(aes, AES, cbc, CBC, 0, 256, 128, 128, block)
82
1.10k
/* ossl_aes192cbc_functions */
83
1.10k
IMPLEMENT_generic_cipher(aes, AES, cbc, CBC, 0, 192, 128, 128, block)
84
13
/* ossl_aes128cbc_functions */
85
144
IMPLEMENT_generic_cipher(aes, AES, cbc, CBC, 0, 128, 128, 128, block)
86
144
/* ossl_aes256ofb_functions */
87
144
IMPLEMENT_generic_cipher(aes, AES, ofb, OFB, 0, 256, 8, 128, stream)
88
53
/* ossl_aes192ofb_functions */
89
53
IMPLEMENT_generic_cipher(aes, AES, ofb, OFB, 0, 192, 8, 128, stream)
90
15
/* ossl_aes128ofb_functions */
91
15
IMPLEMENT_generic_cipher(aes, AES, ofb, OFB, 0, 128, 8, 128, stream)
92
5
/* ossl_aes256cfb_functions */
93
55
IMPLEMENT_generic_cipher(aes, AES, cfb, CFB, 0, 256, 8, 128, stream)
94
55
/* ossl_aes192cfb_functions */
95
55
IMPLEMENT_generic_cipher(aes, AES, cfb, CFB, 0, 192, 8, 128, stream)
96
10
/* ossl_aes128cfb_functions */
97
10
IMPLEMENT_generic_cipher(aes, AES, cfb, CFB, 0, 128, 8, 128, stream)
98
7
/* ossl_aes256cfb1_functions */
99
33
IMPLEMENT_generic_cipher(aes, AES, cfb1, CFB, 0, 256, 8, 128, stream)
100
33
/* ossl_aes192cfb1_functions */
101
33
IMPLEMENT_generic_cipher(aes, AES, cfb1, CFB, 0, 192, 8, 128, stream)
102
2
/* ossl_aes128cfb1_functions */
103
2
IMPLEMENT_generic_cipher(aes, AES, cfb1, CFB, 0, 128, 8, 128, stream)
104
1
/* ossl_aes256cfb8_functions */
105
33
IMPLEMENT_generic_cipher(aes, AES, cfb8, CFB, 0, 256, 8, 128, stream)
106
33
/* ossl_aes192cfb8_functions */
107
33
IMPLEMENT_generic_cipher(aes, AES, cfb8, CFB, 0, 192, 8, 128, stream)
108
1
/* ossl_aes128cfb8_functions */
109
1
IMPLEMENT_generic_cipher(aes, AES, cfb8, CFB, 0, 128, 8, 128, stream)
110
1
/* ossl_aes256ctr_functions */
111
34
IMPLEMENT_generic_cipher(aes, AES, ctr, CTR, 0, 256, 8, 128, stream)
112
34
/* ossl_aes192ctr_functions */
113
34
IMPLEMENT_generic_cipher(aes, AES, ctr, CTR, 0, 192, 8, 128, stream)
114
3
/* 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)