Coverage Report

Created: 2026-09-13 06:13

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