Coverage Report

Created: 2025-08-28 07:07

/src/openssl30/providers/implementations/ciphers/ciphercommon_gcm_hw.c
Line
Count
Source (jump to first uncovered line)
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
14
int ossl_gcm_setiv(PROV_GCM_CTX *ctx, const unsigned char *iv, size_t ivlen)
15
2.40M
{
16
2.40M
    CRYPTO_gcm128_setiv(&ctx->gcm, iv, ivlen);
17
2.40M
    return 1;
18
2.40M
}
19
20
int ossl_gcm_aad_update(PROV_GCM_CTX *ctx, const unsigned char *aad,
21
                        size_t aad_len)
22
2.61M
{
23
2.61M
    return CRYPTO_gcm128_aad(&ctx->gcm, aad, aad_len) == 0;
24
2.61M
}
25
26
int ossl_gcm_cipher_update(PROV_GCM_CTX *ctx, const unsigned char *in,
27
                           size_t len, unsigned char *out)
28
27.1k
{
29
27.1k
    if (ctx->enc) {
30
706
        if (CRYPTO_gcm128_encrypt(&ctx->gcm, in, out, len))
31
0
            return 0;
32
26.4k
    } else {
33
26.4k
        if (CRYPTO_gcm128_decrypt(&ctx->gcm, in, out, len))
34
0
            return 0;
35
26.4k
    }
36
27.1k
    return 1;
37
27.1k
}
38
39
int ossl_gcm_cipher_final(PROV_GCM_CTX *ctx, unsigned char *tag)
40
2.40M
{
41
2.40M
    if (ctx->enc) {
42
1.55M
        CRYPTO_gcm128_tag(&ctx->gcm, tag, GCM_TAG_MAX_SIZE);
43
1.55M
        ctx->taglen = GCM_TAG_MAX_SIZE;
44
1.55M
    } else {
45
849k
        if (CRYPTO_gcm128_finish(&ctx->gcm, tag, ctx->taglen) != 0)
46
847k
            return 0;
47
849k
    }
48
1.56M
    return 1;
49
2.40M
}
50
51
int ossl_gcm_one_shot(PROV_GCM_CTX *ctx, unsigned char *aad, size_t aad_len,
52
                      const unsigned char *in, size_t in_len,
53
                      unsigned char *out, unsigned char *tag, size_t tag_len)
54
51.7k
{
55
51.7k
    int ret = 0;
56
57
    /* Use saved AAD */
58
51.7k
    if (!ctx->hw->aadupdate(ctx, aad, aad_len))
59
0
        goto err;
60
51.7k
    if (!ctx->hw->cipherupdate(ctx, in, in_len, out))
61
0
        goto err;
62
51.7k
    ctx->taglen = GCM_TAG_MAX_SIZE;
63
51.7k
    if (!ctx->hw->cipherfinal(ctx, tag))
64
49.8k
        goto err;
65
1.85k
    ret = 1;
66
67
51.7k
err:
68
51.7k
    return ret;
69
1.85k
}