OpenCoverage

e_sm4.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/evp/e_sm4.c
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3typedef struct {-
4 SM4_KEY ks;-
5} EVP_SM4_KEY;-
6-
7static 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: return 1;
Executed by:
  • libcrypto.so.1.1
1;
executed 152 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
152
12}-
13-
14static 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
encDescription
TRUEevaluated 96 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 74 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
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:
  • libcrypto.so.1.1
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:
  • libcrypto.so.1.1
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:
  • libcrypto.so.1.1
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:
  • libcrypto.so.1.1
74
24}-
25-
26static 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:
  • libcrypto.so.1.1
118
33-
34static void sm4_ecb_encrypt(const unsigned char *in, unsigned char *out,-
35 const SM4_KEY *key, const int enc)-
36{-
37 if (enc
encDescription
TRUEevaluated 405 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 405 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
405
38 SM4_encrypt(in, out, key);
executed 405 times by 1 test: SM4_encrypt(in, out, key);
Executed by:
  • libcrypto.so.1.1
405
39 else-
40 SM4_decrypt(in, out, key);
executed 405 times by 1 test: SM4_decrypt(in, out, key);
Executed by:
  • libcrypto.so.1.1
405
41}-
42-
43static 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:
  • libcrypto.so.1.1
118
50-
51static 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))
inl>=((size_t)...of(long)*8-2))Description
TRUEnever evaluated
FALSEevaluated 170 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) { sm4_cbc_encrypt(in, out, (long)((size_t)1<<(sizeof(long)*8-2)), &((EVP_SM4_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))->ks, EVP_CIPHER_CTX_iv_noconst(ctx), EVP_CIPHER_CTX_encrypting(ctx)); inl-=((size_t)1<<(sizeof(long)*8-2)); in +=((size_t)1<<(sizeof(long)*8-2)); out+=((size_t)1<<(sizeof(long)*8-2)); }
never executed: end of block
if (inl
inlDescription
TRUEevaluated 170 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
) sm4_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 170 times by 1 test: sm4_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:
  • libcrypto.so.1.1
return
executed 170 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1;
executed 170 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
} 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 == 1
128 == 1Description
TRUEnever evaluated
FALSEevaluated 118 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) chunk >>= 3;
never executed: chunk >>= 3;
if (inl < chunk
inl < chunkDescription
TRUEevaluated 118 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
) chunk = inl;
executed 118 times by 1 test: chunk = inl;
Executed by:
  • libcrypto.so.1.1
while (inl
inlDescription
TRUEevaluated 118 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 118 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
&& inl >= chunk
inl >= chunkDescription
TRUEevaluated 118 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
) { int num = EVP_CIPHER_CTX_num(ctx); sm4_cfb128_encrypt(in, out, (long) ((128 == 1) && !EVP_CIPHER_CTX_test_flags(ctx, 0x2000) ? chunk*8 : chunk), &((EVP_SM4_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))->ks, EVP_CIPHER_CTX_iv_noconst(ctx), &num, EVP_CIPHER_CTX_encrypting(ctx)); EVP_CIPHER_CTX_set_num(ctx, num); inl -= chunk; in += chunk; out += chunk; if (inl < chunk
inl < chunkDescription
TRUEevaluated 118 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
) chunk = inl;
executed 118 times by 1 test: chunk = inl;
Executed by:
  • libcrypto.so.1.1
}
executed 118 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
return
executed 118 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1;
executed 118 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
} 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 < bl
inl < blDescription
TRUEnever evaluated
FALSEevaluated 155 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) return
never executed: return 1;
1;
never executed: return 1;
inl -= bl; for (i=0; i <= inl
i <= inlDescription
TRUEevaluated 810 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 155 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
; i+=bl) sm4_ecb_encrypt(in + i, out + i, &((EVP_SM4_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))->ks, EVP_CIPHER_CTX_encrypting(ctx));
executed 810 times by 1 test: sm4_ecb_encrypt(in + i, out + i, &((EVP_SM4_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))->ks, EVP_CIPHER_CTX_encrypting(ctx));
Executed by:
  • libcrypto.so.1.1
return
executed 155 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1;
executed 155 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
} 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))
inl>=((size_t)...of(long)*8-2))Description
TRUEnever evaluated
FALSEevaluated 118 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) { int num = EVP_CIPHER_CTX_num(ctx); sm4_ofb128_encrypt(in, out, (long)((size_t)1<<(sizeof(long)*8-2)), &((EVP_SM4_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))->ks, EVP_CIPHER_CTX_iv_noconst(ctx), &num); EVP_CIPHER_CTX_set_num(ctx, num); inl-=((size_t)1<<(sizeof(long)*8-2)); in +=((size_t)1<<(sizeof(long)*8-2)); out+=((size_t)1<<(sizeof(long)*8-2)); }
never executed: end of block
if (inl
inlDescription
TRUEevaluated 118 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
) { int num = EVP_CIPHER_CTX_num(ctx); sm4_ofb128_encrypt(in, out, (long)inl, &((EVP_SM4_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))->ks, EVP_CIPHER_CTX_iv_noconst(ctx), &num); EVP_CIPHER_CTX_set_num(ctx, num); }
executed 118 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
return
executed 118 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1;
executed 118 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
} 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,
0-810
52((void *)0) -
53}; const EVP_CIPHER *EVP_sm4_cbc(void) { return
executed 1962 times by 1 test: return &sm4_cbc;
Executed by:
  • libcrypto.so.1.1
&sm4_cbc;
executed 1962 times by 1 test: return &sm4_cbc;
Executed by:
  • libcrypto.so.1.1
} 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,
1962
54((void *)0) -
55}; const EVP_CIPHER *EVP_sm4_cfb128(void) { return
executed 1962 times by 1 test: return &sm4_cfb128;
Executed by:
  • libcrypto.so.1.1
&sm4_cfb128;
executed 1962 times by 1 test: return &sm4_cfb128;
Executed by:
  • libcrypto.so.1.1
} 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,
1962
56((void *)0) -
57}; const EVP_CIPHER *EVP_sm4_ofb(void) { return
executed 1962 times by 1 test: return &sm4_ofb;
Executed by:
  • libcrypto.so.1.1
&sm4_ofb;
executed 1962 times by 1 test: return &sm4_ofb;
Executed by:
  • libcrypto.so.1.1
} 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,
1962
58((void *)0) -
59}; const EVP_CIPHER *EVP_sm4_ecb(void) { return
executed 1962 times by 1 test: return &sm4_ecb;
Executed by:
  • libcrypto.so.1.1
&sm4_ecb;
executed 1962 times by 1 test: return &sm4_ecb;
Executed by:
  • libcrypto.so.1.1
}
1962
60-
61-
62-
63static 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: return 1;
Executed by:
  • libcrypto.so.1.1
1;
executed 118 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
118
75}-
76-
77static 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-
97const EVP_CIPHER *EVP_sm4_ctr(void)-
98{-
99 return
executed 1962 times by 1 test: return &sm4_ctr_mode;
Executed by:
  • libcrypto.so.1.1
&sm4_ctr_mode;
executed 1962 times by 1 test: return &sm4_ctr_mode;
Executed by:
  • libcrypto.so.1.1
1962
100}-
Switch to Source codePreprocessed file

Generated by Squish Coco 4.2.2