Coverage Report

Created: 2025-12-31 06:58

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl30/providers/implementations/ciphers/cipher_sm4_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 "cipher_sm4.h"
11
12
static int cipher_hw_sm4_initkey(PROV_CIPHER_CTX *ctx,
13
    const unsigned char *key, size_t keylen)
14
14
{
15
14
    PROV_SM4_CTX *sctx = (PROV_SM4_CTX *)ctx;
16
14
    SM4_KEY *ks = &sctx->ks.ks;
17
18
14
    ossl_sm4_set_key(key, ks);
19
14
    ctx->ks = ks;
20
14
    if (ctx->enc
21
0
        || (ctx->mode != EVP_CIPH_ECB_MODE
22
0
            && ctx->mode != EVP_CIPH_CBC_MODE))
23
14
        ctx->block = (block128_f)ossl_sm4_encrypt;
24
0
    else
25
0
        ctx->block = (block128_f)ossl_sm4_decrypt;
26
14
    return 1;
27
14
}
28
29
IMPLEMENT_CIPHER_HW_COPYCTX(cipher_hw_sm4_copyctx, PROV_SM4_CTX)
30
31
#define PROV_CIPHER_HW_sm4_mode(mode)                                    \
32
    static const PROV_CIPHER_HW sm4_##mode = {                           \
33
        cipher_hw_sm4_initkey,                                           \
34
        ossl_cipher_hw_chunked_##mode,                                   \
35
        cipher_hw_sm4_copyctx                                            \
36
    };                                                                   \
37
    const PROV_CIPHER_HW *ossl_prov_cipher_hw_sm4_##mode(size_t keybits) \
38
17
    {                                                                    \
39
17
        return &sm4_##mode;                                              \
40
17
    }
ossl_prov_cipher_hw_sm4_cbc
Line
Count
Source
38
13
    {                                                                    \
39
13
        return &sm4_##mode;                                              \
40
13
    }
ossl_prov_cipher_hw_sm4_ecb
Line
Count
Source
38
1
    {                                                                    \
39
1
        return &sm4_##mode;                                              \
40
1
    }
ossl_prov_cipher_hw_sm4_ofb128
Line
Count
Source
38
1
    {                                                                    \
39
1
        return &sm4_##mode;                                              \
40
1
    }
ossl_prov_cipher_hw_sm4_cfb128
Line
Count
Source
38
1
    {                                                                    \
39
1
        return &sm4_##mode;                                              \
40
1
    }
ossl_prov_cipher_hw_sm4_ctr
Line
Count
Source
38
1
    {                                                                    \
39
1
        return &sm4_##mode;                                              \
40
1
    }
41
42
PROV_CIPHER_HW_sm4_mode(cbc)
43
    PROV_CIPHER_HW_sm4_mode(ecb)
44
        PROV_CIPHER_HW_sm4_mode(ofb128)
45
            PROV_CIPHER_HW_sm4_mode(cfb128)
46
                PROV_CIPHER_HW_sm4_mode(ctr)