Coverage Report

Created: 2026-02-22 06:11

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl/crypto/evp/e_sm4.c
Line
Count
Source
1
/*
2
 * Copyright 2017-2022 The OpenSSL Project Authors. All Rights Reserved.
3
 * Copyright 2017 Ribose Inc. All Rights Reserved.
4
 * Ported from Ribose contributions from Botan.
5
 *
6
 * Licensed under the Apache License 2.0 (the "License").  You may not use
7
 * this file except in compliance with the License.  You can obtain a copy
8
 * in the file LICENSE in the source distribution or at
9
 * https://www.openssl.org/source/license.html
10
 */
11
12
#include <openssl/macros.h>
13
14
#ifndef OPENSSL_NO_SM4
15
#include "crypto/evp.h"
16
17
#define BLOCK_CIPHER_generic(nid, blocksize, ivlen, nmode, mode, MODE, flags) \
18
    static const EVP_CIPHER sm4_##mode = {                                    \
19
        nid##_##nmode, blocksize, 128 / 8, ivlen,                             \
20
        flags | EVP_CIPH_##MODE##_MODE,                                       \
21
        EVP_ORIG_GLOBAL                                                       \
22
    };                                                                        \
23
    const EVP_CIPHER *EVP_sm4_##mode(void)                                    \
24
15
    {                                                                         \
25
15
        return &sm4_##mode;                                                   \
26
15
    }
EVP_sm4_cbc
Line
Count
Source
24
3
    {                                                                         \
25
3
        return &sm4_##mode;                                                   \
26
3
    }
EVP_sm4_ecb
Line
Count
Source
24
3
    {                                                                         \
25
3
        return &sm4_##mode;                                                   \
26
3
    }
EVP_sm4_ofb
Line
Count
Source
24
3
    {                                                                         \
25
3
        return &sm4_##mode;                                                   \
26
3
    }
EVP_sm4_cfb128
Line
Count
Source
24
3
    {                                                                         \
25
3
        return &sm4_##mode;                                                   \
26
3
    }
EVP_sm4_ctr
Line
Count
Source
24
3
    {                                                                         \
25
3
        return &sm4_##mode;                                                   \
26
3
    }
27
28
#define DEFINE_BLOCK_CIPHERS(nid, flags)                                                   \
29
    BLOCK_CIPHER_generic(nid, 16, 16, cbc, cbc, CBC, flags | EVP_CIPH_FLAG_DEFAULT_ASN1)   \
30
    BLOCK_CIPHER_generic(nid, 16, 0, ecb, ecb, ECB, flags | EVP_CIPH_FLAG_DEFAULT_ASN1)    \
31
    BLOCK_CIPHER_generic(nid, 1, 16, ofb128, ofb, OFB, flags | EVP_CIPH_FLAG_DEFAULT_ASN1) \
32
    BLOCK_CIPHER_generic(nid, 1, 16, cfb128, cfb, CFB, flags | EVP_CIPH_FLAG_DEFAULT_ASN1) \
33
    BLOCK_CIPHER_generic(nid, 1, 16, ctr, ctr, CTR, flags)
34
35
DEFINE_BLOCK_CIPHERS(NID_sm4, 0)
36
#else
37
NON_EMPTY_TRANSLATION_UNIT
38
#endif