Coverage Report

Created: 2026-10-16 07:07

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl/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
0
{
15
0
    CRYPTO_gcm128_setiv(&ctx->gcm, iv, ivlen);
16
0
    return 1;
17
0
}
18
19
int ossl_gcm_aad_update(PROV_GCM_CTX *ctx, const unsigned char *aad,
20
    size_t aad_len)
21
0
{
22
0
    int rv = CRYPTO_gcm128_aad(&ctx->gcm, aad, aad_len);
23
24
    /*
25
     * CRYPTO_gcm128_aad() returns:
26
     * -  0: success -> return 1
27
     * - -1: AAD length overflow -> propagate
28
     * - -2: AAD follows the payload -> propagate
29
     */
30
0
    if (rv == 0)
31
0
        return 1;
32
0
    return rv;
33
0
}
34
35
int ossl_gcm_cipher_update(PROV_GCM_CTX *ctx, const unsigned char *in,
36
    size_t len, unsigned char *out)
37
0
{
38
0
    if (ctx->enc) {
39
0
        if (CRYPTO_gcm128_encrypt(&ctx->gcm, in, out, len))
40
0
            return 0;
41
0
    } else {
42
0
        if (CRYPTO_gcm128_decrypt(&ctx->gcm, in, out, len))
43
0
            return 0;
44
0
    }
45
0
    return 1;
46
0
}
47
48
int ossl_gcm_cipher_final(PROV_GCM_CTX *ctx, unsigned char *tag)
49
0
{
50
0
    if (ctx->enc) {
51
0
        CRYPTO_gcm128_tag(&ctx->gcm, tag, GCM_TAG_MAX_SIZE);
52
0
        ctx->taglen = GCM_TAG_MAX_SIZE;
53
0
    } else {
54
0
        if (CRYPTO_gcm128_finish(&ctx->gcm, tag, ctx->taglen) != 0)
55
0
            return 0;
56
0
    }
57
0
    return 1;
58
0
}
59
60
int ossl_gcm_one_shot(PROV_GCM_CTX *ctx, unsigned char *aad, size_t aad_len,
61
    const unsigned char *in, size_t in_len,
62
    unsigned char *out, unsigned char *tag, size_t tag_len)
63
0
{
64
0
    int ret = 0;
65
66
    /* Use saved AAD */
67
0
    if (ctx->hw->aadupdate(ctx, aad, aad_len) <= 0)
68
0
        goto err;
69
0
    if (!ctx->hw->cipherupdate(ctx, in, in_len, out))
70
0
        goto err;
71
0
    ctx->taglen = GCM_TAG_MAX_SIZE;
72
0
    if (!ctx->hw->cipherfinal(ctx, tag))
73
0
        goto err;
74
0
    ret = 1;
75
76
0
err:
77
0
    return ret;
78
0
}