Coverage Report

Created: 2026-02-14 07:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl/providers/implementations/ciphers/cipher_aes_ccm.c
Line
Count
Source
1
/*
2
 * Copyright 2019-2023 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 CCM mode */
18
19
#include "cipher_aes_ccm.h"
20
#include "prov/implementations.h"
21
#include "prov/providercommon.h"
22
23
static void *aes_ccm_newctx(void *provctx, size_t keybits)
24
1.96k
{
25
1.96k
    PROV_AES_CCM_CTX *ctx;
26
27
1.96k
    CIPHER_PROV_CHECK(provctx, AES_128_CCM);
28
1.96k
    ctx = OPENSSL_zalloc(sizeof(*ctx));
29
1.96k
    if (ctx != NULL)
30
1.96k
        ossl_ccm_initctx(&ctx->base, keybits, ossl_prov_aes_hw_ccm(keybits));
31
1.96k
    return ctx;
32
1.96k
}
33
34
static void *aes_ccm_dupctx(void *provctx)
35
0
{
36
0
    PROV_AES_CCM_CTX *ctx = provctx;
37
0
    PROV_AES_CCM_CTX *dupctx = NULL;
38
39
0
    if (!ossl_prov_is_running())
40
0
        return NULL;
41
42
0
    if (ctx == NULL)
43
0
        return NULL;
44
0
    dupctx = OPENSSL_memdup(provctx, sizeof(*ctx));
45
0
    if (dupctx == NULL)
46
0
        return NULL;
47
    /*
48
     * ossl_cm_initctx, via the ossl_prov_aes_hw_ccm functions assign a
49
     * provctx->ccm.ks.ks to the ccm context key so we need to point it to
50
     * the memduped copy
51
     */
52
0
    dupctx->base.ccm_ctx.key = &dupctx->ccm.ks.ks;
53
54
0
    return dupctx;
55
0
}
56
57
static OSSL_FUNC_cipher_freectx_fn aes_ccm_freectx;
58
static void aes_ccm_freectx(void *vctx)
59
1.96k
{
60
1.96k
    PROV_AES_CCM_CTX *ctx = (PROV_AES_CCM_CTX *)vctx;
61
62
1.96k
    OPENSSL_clear_free(ctx, sizeof(*ctx));
63
1.96k
}
64
65
/* ossl_aes128ccm_functions */
66
IMPLEMENT_aead_cipher(aes, ccm, CCM, AEAD_FLAGS, 128, 8, 96);
67
/* ossl_aes192ccm_functions */
68
IMPLEMENT_aead_cipher(aes, ccm, CCM, AEAD_FLAGS, 192, 8, 96);
69
/* ossl_aes256ccm_functions */
70
IMPLEMENT_aead_cipher(aes, ccm, CCM, AEAD_FLAGS, 256, 8, 96);