Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/evp/e_sm4.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3 | typedef struct { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4 | SM4_KEY ks; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5 | } EVP_SM4_KEY; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7 | static int sm4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
8 | const unsigned char *iv, int enc) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
9 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
10 | SM4_set_key(key, EVP_CIPHER_CTX_get_cipher_data(ctx)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
11 | return executed 152 times by 1 test: 1;return 1; Executed by:
executed 152 times by 1 test: return 1; Executed by:
| 152 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
12 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
13 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
14 | static void sm4_cbc_encrypt(const unsigned char *in, unsigned char *out, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
15 | size_t len, const SM4_KEY *key, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
16 | unsigned char *ivec, const int enc) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
17 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
18 | if (enc
| 74-96 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
19 | CRYPTO_cbc128_encrypt(in, out, len, key, ivec, executed 96 times by 1 test: CRYPTO_cbc128_encrypt(in, out, len, key, ivec, (block128_f)SM4_encrypt); Executed by:
| 96 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
20 | (block128_f)SM4_encrypt); executed 96 times by 1 test: CRYPTO_cbc128_encrypt(in, out, len, key, ivec, (block128_f)SM4_encrypt); Executed by:
| 96 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
21 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
22 | CRYPTO_cbc128_decrypt(in, out, len, key, ivec, executed 74 times by 1 test: CRYPTO_cbc128_decrypt(in, out, len, key, ivec, (block128_f)SM4_decrypt); Executed by:
| 74 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
23 | (block128_f)SM4_decrypt); executed 74 times by 1 test: CRYPTO_cbc128_decrypt(in, out, len, key, ivec, (block128_f)SM4_decrypt); Executed by:
| 74 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
24 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
25 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
26 | static void sm4_cfb128_encrypt(const unsigned char *in, unsigned char *out, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
27 | size_t length, const SM4_KEY *key, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
28 | unsigned char *ivec, int *num, const int enc) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
29 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
30 | CRYPTO_cfb128_encrypt(in, out, length, key, ivec, num, enc, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
31 | (block128_f)SM4_encrypt); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
32 | } executed 118 times by 1 test: end of block Executed by:
| 118 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
34 | static void sm4_ecb_encrypt(const unsigned char *in, unsigned char *out, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
35 | const SM4_KEY *key, const int enc) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
36 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
37 | if (enc
| 405 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
38 | SM4_encrypt(in, out, key); executed 405 times by 1 test: SM4_encrypt(in, out, key); Executed by:
| 405 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
39 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
40 | SM4_decrypt(in, out, key); executed 405 times by 1 test: SM4_decrypt(in, out, key); Executed by:
| 405 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
41 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
42 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
43 | static void sm4_ofb128_encrypt(const unsigned char *in, unsigned char *out, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
44 | size_t length, const SM4_KEY *key, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
45 | unsigned char *ivec, int *num) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
46 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
47 | CRYPTO_ofb128_encrypt(in, out, length, key, ivec, num, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
48 | (block128_f)SM4_encrypt); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
49 | } executed 118 times by 1 test: end of block Executed by:
| 118 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
50 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
51 | static int sm4_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) { while(inl>=((size_t)1<<(sizeof(long)*8-2))
never executed: if (inlend of block
executed 170 times by 1 test: returnsm4_cbc_encrypt(in, out, (long)inl, &((EVP_SM4_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))->ks, EVP_CIPHER_CTX_iv_noconst(ctx), EVP_CIPHER_CTX_encrypting(ctx)); Executed by:
executed 170 times by 1 test: 1;return 1; Executed by:
executed 170 times by 1 test: } static int sm4_cfb128_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) { size_t chunk = ((size_t)1<<(sizeof(long)*8-2)); if (128 == 1return 1; Executed by:
never executed: if (inl < chunkchunk >>= 3;
executed 118 times by 1 test: while (inlchunk = inl; Executed by:
executed 118 times by 1 test: }chunk = inl; Executed by:
executed 118 times by 1 test: returnend of block Executed by:
executed 118 times by 1 test: 1;return 1; Executed by:
executed 118 times by 1 test: } static int sm4_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) { size_t i, bl; bl = EVP_CIPHER_CTX_cipher(ctx)->block_size; if (inl < blreturn 1; Executed by:
never executed: 1;return 1; never executed: inl -= bl; for (i=0; i <= inlreturn 1;
executed 810 times by 1 test: returnsm4_ecb_encrypt(in + i, out + i, &((EVP_SM4_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))->ks, EVP_CIPHER_CTX_encrypting(ctx)); Executed by:
executed 155 times by 1 test: 1;return 1; Executed by:
executed 155 times by 1 test: } static int sm4_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) { while(inl>=((size_t)1<<(sizeof(long)*8-2))return 1; Executed by:
never executed: if (inlend of block
executed 118 times by 1 test: returnend of block Executed by:
executed 118 times by 1 test: 1;return 1; Executed by:
executed 118 times by 1 test: } static const EVP_CIPHER sm4_cbc = { 1134, 16, 16, 16, 0x1000 | 0x2, sm4_init_key, sm4_cbc_cipher, 0, sizeof(EVP_SM4_KEY), 0, 0, 0, return 1; Executed by:
| 0-810 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
52 | ((void *)0) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
53 | }; const EVP_CIPHER *EVP_sm4_cbc(void) { return executed 1962 times by 1 test: &sm4_cbc;return &sm4_cbc; Executed by:
executed 1962 times by 1 test: } static const EVP_CIPHER sm4_cfb128 = { 1137, 1, 16, 16, 0x1000 | 0x3, sm4_init_key, sm4_cfb128_cipher, 0, sizeof(EVP_SM4_KEY), 0, 0, 0, return &sm4_cbc; Executed by:
| 1962 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
54 | ((void *)0) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
55 | }; const EVP_CIPHER *EVP_sm4_cfb128(void) { return executed 1962 times by 1 test: &sm4_cfb128;return &sm4_cfb128; Executed by:
executed 1962 times by 1 test: } static const EVP_CIPHER sm4_ofb = { 1135, 1, 16, 16, 0x1000 | 0x4, sm4_init_key, sm4_ofb_cipher, 0, sizeof(EVP_SM4_KEY), 0, 0, 0, return &sm4_cfb128; Executed by:
| 1962 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
56 | ((void *)0) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
57 | }; const EVP_CIPHER *EVP_sm4_ofb(void) { return executed 1962 times by 1 test: &sm4_ofb;return &sm4_ofb; Executed by:
executed 1962 times by 1 test: } static const EVP_CIPHER sm4_ecb = { 1133, 16, 16, 0, 0x1000 | 0x1, sm4_init_key, sm4_ecb_cipher, 0, sizeof(EVP_SM4_KEY), 0, 0, 0, return &sm4_ofb; Executed by:
| 1962 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
58 | ((void *)0) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
59 | }; const EVP_CIPHER *EVP_sm4_ecb(void) { return executed 1962 times by 1 test: &sm4_ecb;return &sm4_ecb; Executed by:
executed 1962 times by 1 test: }return &sm4_ecb; Executed by:
| 1962 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
60 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
61 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
62 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
63 | static int sm4_ctr_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
64 | const unsigned char *in, size_t len) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
65 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
66 | unsigned int num = EVP_CIPHER_CTX_num(ctx); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
67 | EVP_SM4_KEY *dat = ((EVP_SM4_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
68 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
69 | CRYPTO_ctr128_encrypt(in, out, len, &dat->ks, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
70 | EVP_CIPHER_CTX_iv_noconst(ctx), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
71 | EVP_CIPHER_CTX_buf_noconst(ctx), &num, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
72 | (block128_f)SM4_encrypt); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
73 | EVP_CIPHER_CTX_set_num(ctx, num); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
74 | return executed 118 times by 1 test: 1;return 1; Executed by:
executed 118 times by 1 test: return 1; Executed by:
| 118 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
75 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
76 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
77 | static const EVP_CIPHER sm4_ctr_mode = { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
78 | 1139, 1, 16, 16, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
79 | 0x5, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
80 | sm4_init_key, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
81 | sm4_ctr_cipher, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
82 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
83 | ((void *)0) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
84 | , | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
85 | sizeof(EVP_SM4_KEY), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
86 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
87 | ((void *)0) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
88 | , | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
89 | ((void *)0) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
90 | , | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
91 | ((void *)0) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
92 | , | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
93 | ((void *)0) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
94 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
95 | }; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
96 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
97 | const EVP_CIPHER *EVP_sm4_ctr(void) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
98 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
99 | return executed 1962 times by 1 test: &sm4_ctr_mode;return &sm4_ctr_mode; Executed by:
executed 1962 times by 1 test: return &sm4_ctr_mode; Executed by:
| 1962 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
100 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Switch to Source code | Preprocessed file |