Coverage Report

Created: 2026-02-14 07:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl35/providers/implementations/ciphers/ciphercommon_gcm_hw.c
Line
Count
Source
1
/*
2
 * Copyright 2001-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_gcm.h"
12
13
int ossl_gcm_setiv(PROV_GCM_CTX *ctx, const unsigned char *iv, size_t ivlen)
14
3.72M
{
15
3.72M
    CRYPTO_gcm128_setiv(&ctx->gcm, iv, ivlen);
16
3.72M
    return 1;
17
3.72M
}
18
19
int ossl_gcm_aad_update(PROV_GCM_CTX *ctx, const unsigned char *aad,
20
    size_t aad_len)
21
4.16M
{
22
4.16M
    return CRYPTO_gcm128_aad(&ctx->gcm, aad, aad_len) == 0;
23
4.16M
}
24
25
int ossl_gcm_cipher_update(PROV_GCM_CTX *ctx, const unsigned char *in,
26
    size_t len, unsigned char *out)
27
45.0k
{
28
45.0k
    if (ctx->enc) {
29
1.00k
        if (CRYPTO_gcm128_encrypt(&ctx->gcm, in, out, len))
30
0
            return 0;
31
44.0k
    } else {
32
44.0k
        if (CRYPTO_gcm128_decrypt(&ctx->gcm, in, out, len))
33
0
            return 0;
34
44.0k
    }
35
45.0k
    return 1;
36
45.0k
}
37
38
int ossl_gcm_cipher_final(PROV_GCM_CTX *ctx, unsigned char *tag)
39
3.72M
{
40
3.72M
    if (ctx->enc) {
41
2.39M
        CRYPTO_gcm128_tag(&ctx->gcm, tag, GCM_TAG_MAX_SIZE);
42
2.39M
        ctx->taglen = GCM_TAG_MAX_SIZE;
43
2.39M
    } else {
44
1.33M
        if (CRYPTO_gcm128_finish(&ctx->gcm, tag, ctx->taglen) != 0)
45
1.33M
            return 0;
46
1.33M
    }
47
2.39M
    return 1;
48
3.72M
}
49
50
int ossl_gcm_one_shot(PROV_GCM_CTX *ctx, unsigned char *aad, size_t aad_len,
51
    const unsigned char *in, size_t in_len,
52
    unsigned char *out, unsigned char *tag, size_t tag_len)
53
82.0k
{
54
82.0k
    int ret = 0;
55
56
    /* Use saved AAD */
57
82.0k
    if (!ctx->hw->aadupdate(ctx, aad, aad_len))
58
0
        goto err;
59
82.0k
    if (!ctx->hw->cipherupdate(ctx, in, in_len, out))
60
0
        goto err;
61
82.0k
    ctx->taglen = GCM_TAG_MAX_SIZE;
62
82.0k
    if (!ctx->hw->cipherfinal(ctx, tag))
63
79.9k
        goto err;
64
2.12k
    ret = 1;
65
66
82.0k
err:
67
82.0k
    return ret;
68
2.12k
}