Coverage Report

Created: 2026-07-23 06:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl33/providers/implementations/ciphers/ciphercommon_ccm_hw.c
Line
Count
Source
1
/*
2
 * Copyright 2019-2021 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
#include "prov/ciphercommon.h"
11
#include "prov/ciphercommon_ccm.h"
12
13
int ossl_ccm_generic_setiv(PROV_CCM_CTX *ctx, const unsigned char *nonce,
14
    size_t nlen, size_t mlen)
15
79.1k
{
16
79.1k
    return CRYPTO_ccm128_setiv(&ctx->ccm_ctx, nonce, nlen, mlen) == 0;
17
79.1k
}
18
19
int ossl_ccm_generic_setaad(PROV_CCM_CTX *ctx, const unsigned char *aad,
20
    size_t alen)
21
79.1k
{
22
79.1k
    CRYPTO_ccm128_aad(&ctx->ccm_ctx, aad, alen);
23
79.1k
    return 1;
24
79.1k
}
25
26
int ossl_ccm_generic_gettag(PROV_CCM_CTX *ctx, unsigned char *tag, size_t tlen)
27
0
{
28
0
    return CRYPTO_ccm128_tag(&ctx->ccm_ctx, tag, tlen) > 0;
29
0
}
30
31
int ossl_ccm_generic_auth_encrypt(PROV_CCM_CTX *ctx, const unsigned char *in,
32
    unsigned char *out, size_t len,
33
    unsigned char *tag, size_t taglen)
34
1.26k
{
35
1.26k
    int rv;
36
37
1.26k
    if (ctx->str != NULL)
38
1.26k
        rv = CRYPTO_ccm128_encrypt_ccm64(&ctx->ccm_ctx, in,
39
1.26k
                 out, len, ctx->str)
40
1.26k
            == 0;
41
0
    else
42
0
        rv = CRYPTO_ccm128_encrypt(&ctx->ccm_ctx, in, out, len) == 0;
43
44
1.26k
    if (rv == 1 && tag != NULL)
45
1.26k
        rv = (CRYPTO_ccm128_tag(&ctx->ccm_ctx, tag, taglen) > 0);
46
1.26k
    return rv;
47
1.26k
}
48
49
int ossl_ccm_generic_auth_decrypt(PROV_CCM_CTX *ctx, const unsigned char *in,
50
    unsigned char *out, size_t len,
51
    unsigned char *expected_tag, size_t taglen)
52
77.9k
{
53
77.9k
    int rv = 0;
54
55
77.9k
    if (ctx->str != NULL)
56
77.9k
        rv = CRYPTO_ccm128_decrypt_ccm64(&ctx->ccm_ctx, in, out, len,
57
77.9k
                 ctx->str)
58
77.9k
            == 0;
59
0
    else
60
0
        rv = CRYPTO_ccm128_decrypt(&ctx->ccm_ctx, in, out, len) == 0;
61
77.9k
    if (rv) {
62
77.9k
        unsigned char tag[16];
63
64
77.9k
        if (!CRYPTO_ccm128_tag(&ctx->ccm_ctx, tag, taglen)
65
77.9k
            || CRYPTO_memcmp(tag, expected_tag, taglen) != 0)
66
77.7k
            rv = 0;
67
77.9k
    }
68
77.9k
    if (rv == 0)
69
77.7k
        OPENSSL_cleanse(out, len);
70
77.9k
    return rv;
71
77.9k
}