OpenCoverage

cmac.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/cmac/cmac.c
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3struct CMAC_CTX_st {-
4-
5 EVP_CIPHER_CTX *cctx;-
6-
7 unsigned char k1[32];-
8 unsigned char k2[32];-
9-
10 unsigned char tbl[32];-
11-
12 unsigned char last_block[32];-
13-
14 int nlast_block;-
15};-
16-
17-
18-
19static void make_kn(unsigned char *k1, const unsigned char *l, int bl)-
20{-
21 int i;-
22 unsigned char c = l[0], carry = c >> 7, cnext;-
23-
24-
25 for (i = 0; i < bl - 1
i < bl - 1Description
TRUEevaluated 104 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 8 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
; i++, c = cnext)
8-104
26 k1[i] = (c << 1) | ((cnext = l[i + 1]) >> 7);
executed 104 times by 1 test: k1[i] = (c << 1) | ((cnext = l[i + 1]) >> 7);
Executed by:
  • libcrypto.so.1.1
104
27-
28-
29 k1[i] = (c << 1) ^ ((0 - carry) & (bl == 16 ? 0x87 : 0x1b));-
30}
executed 8 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
8
31-
32CMAC_CTX *CMAC_CTX_new(void)-
33{-
34 CMAC_CTX *ctx;-
35-
36 if ((
(ctx = CRYPTO_...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
ctx = CRYPTO_malloc(sizeof(*ctx), __FILE__, 50)) ==
(ctx = CRYPTO_...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-12
37 ((void *)0)
(ctx = CRYPTO_...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-12
38 ) {-
39 ERR_put_error(15,(120),((1|64)),__FILE__,51);-
40 return
never executed: return ((void *)0) ;
never executed: return ((void *)0) ;
0
41 ((void *)0)
never executed: return ((void *)0) ;
0
42 ;
never executed: return ((void *)0) ;
0
43 }-
44 ctx->cctx = EVP_CIPHER_CTX_new();-
45 if (ctx->cctx ==
ctx->cctx == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-12
46 ((void *)0)
ctx->cctx == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-12
47 ) {-
48 CRYPTO_free(ctx, __FILE__, 56);-
49 return
never executed: return ((void *)0) ;
never executed: return ((void *)0) ;
0
50 ((void *)0)
never executed: return ((void *)0) ;
0
51 ;
never executed: return ((void *)0) ;
0
52 }-
53 ctx->nlast_block = -1;-
54 return
executed 12 times by 1 test: return ctx;
Executed by:
  • libcrypto.so.1.1
ctx;
executed 12 times by 1 test: return ctx;
Executed by:
  • libcrypto.so.1.1
12
55}-
56-
57void CMAC_CTX_cleanup(CMAC_CTX *ctx)-
58{-
59 EVP_CIPHER_CTX_reset(ctx->cctx);-
60 OPENSSL_cleanse(ctx->tbl, 32);-
61 OPENSSL_cleanse(ctx->k1, 32);-
62 OPENSSL_cleanse(ctx->k2, 32);-
63 OPENSSL_cleanse(ctx->last_block, 32);-
64 ctx->nlast_block = -1;-
65}
executed 12 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
12
66-
67EVP_CIPHER_CTX *CMAC_CTX_get0_cipher_ctx(CMAC_CTX *ctx)-
68{-
69 return
never executed: return ctx->cctx;
ctx->cctx;
never executed: return ctx->cctx;
0
70}-
71-
72void CMAC_CTX_free(CMAC_CTX *ctx)-
73{-
74 if (!ctx
!ctxDescription
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-12
75 return;
never executed: return;
0
76 CMAC_CTX_cleanup(ctx);-
77 EVP_CIPHER_CTX_free(ctx->cctx);-
78 CRYPTO_free(ctx, __FILE__, 84);-
79}
executed 12 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
12
80-
81int CMAC_CTX_copy(CMAC_CTX *out, const CMAC_CTX *in)-
82{-
83 int bl;-
84 if (in->nlast_block == -1
in->nlast_block == -1Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-8
85 return
never executed: return 0;
0;
never executed: return 0;
0
86 if (!EVP_CIPHER_CTX_copy(out->cctx, in->cctx)
!EVP_CIPHER_CT...ctx, in->cctx)Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-8
87 return
never executed: return 0;
0;
never executed: return 0;
0
88 bl = EVP_CIPHER_CTX_block_size(in->cctx);-
89 memcpy(out->k1, in->k1, bl);-
90 memcpy(out->k2, in->k2, bl);-
91 memcpy(out->tbl, in->tbl, bl);-
92 memcpy(out->last_block, in->last_block, bl);-
93 out->nlast_block = in->nlast_block;-
94 return
executed 8 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1;
executed 8 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
8
95}-
96-
97int CMAC_Init(CMAC_CTX *ctx, const void *key, size_t keylen,-
98 const EVP_CIPHER *cipher, ENGINE *impl)-
99{-
100 static const unsigned char zero_iv[32] = { 0 };-
101-
102 if (!key
!keyDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
&& !cipher
!cipherDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
&& !impl
!implDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
&& keylen == 0
keylen == 0Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
) {
0-4
103-
104 if (ctx->nlast_block == -1
ctx->nlast_block == -1Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-4
105 return
never executed: return 0;
0;
never executed: return 0;
0
106 if (!EVP_EncryptInit_ex(ctx->cctx,
!EVP_EncryptIn...)0) , zero_iv)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
107 ((void *)0)
!EVP_EncryptIn...)0) , zero_iv)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
108 ,
!EVP_EncryptIn...)0) , zero_iv)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
109 ((void *)0)
!EVP_EncryptIn...)0) , zero_iv)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
110 ,
!EVP_EncryptIn...)0) , zero_iv)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
111 ((void *)0)
!EVP_EncryptIn...)0) , zero_iv)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
112 , zero_iv)
!EVP_EncryptIn...)0) , zero_iv)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-4
113 return
never executed: return 0;
0;
never executed: return 0;
0
114 memset(ctx->tbl, 0, EVP_CIPHER_CTX_block_size(ctx->cctx));-
115 ctx->nlast_block = 0;-
116 return
executed 4 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1;
executed 4 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
4
117 }-
118-
119 if (cipher
cipherDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
&& !EVP_EncryptInit_ex(ctx->cctx, cipher, impl,
!EVP_EncryptIn... ((void *)0) )Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
120 ((void *)0)
!EVP_EncryptIn... ((void *)0) )Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
121 ,
!EVP_EncryptIn... ((void *)0) )Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
122 ((void *)0)
!EVP_EncryptIn... ((void *)0) )Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
123 )
!EVP_EncryptIn... ((void *)0) )Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-4
124 return
never executed: return 0;
0;
never executed: return 0;
0
125-
126 if (key
keyDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
) {
0-4
127 int bl;-
128 if (!EVP_CIPHER_CTX_cipher(ctx->cctx)
!EVP_CIPHER_CT...her(ctx->cctx)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-4
129 return
never executed: return 0;
0;
never executed: return 0;
0
130 if (!EVP_CIPHER_CTX_set_key_length(ctx->cctx, keylen)
!EVP_CIPHER_CT...>cctx, keylen)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-4
131 return
never executed: return 0;
0;
never executed: return 0;
0
132 if (!EVP_EncryptInit_ex(ctx->cctx,
!EVP_EncryptIn... key, zero_iv)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
133 ((void *)0)
!EVP_EncryptIn... key, zero_iv)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
134 ,
!EVP_EncryptIn... key, zero_iv)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
135 ((void *)0)
!EVP_EncryptIn... key, zero_iv)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
136 , key, zero_iv)
!EVP_EncryptIn... key, zero_iv)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-4
137 return
never executed: return 0;
0;
never executed: return 0;
0
138 bl = EVP_CIPHER_CTX_block_size(ctx->cctx);-
139 if (!EVP_Cipher(ctx->cctx, ctx->tbl, zero_iv, bl)
!EVP_Cipher(ct..., zero_iv, bl)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-4
140 return
never executed: return 0;
0;
never executed: return 0;
0
141 make_kn(ctx->k1, ctx->tbl, bl);-
142 make_kn(ctx->k2, ctx->k1, bl);-
143 OPENSSL_cleanse(ctx->tbl, bl);-
144-
145 if (!EVP_EncryptInit_ex(ctx->cctx,
!EVP_EncryptIn...)0) , zero_iv)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
146 ((void *)0)
!EVP_EncryptIn...)0) , zero_iv)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
147 ,
!EVP_EncryptIn...)0) , zero_iv)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
148 ((void *)0)
!EVP_EncryptIn...)0) , zero_iv)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
149 ,
!EVP_EncryptIn...)0) , zero_iv)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
150 ((void *)0)
!EVP_EncryptIn...)0) , zero_iv)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
151 , zero_iv)
!EVP_EncryptIn...)0) , zero_iv)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-4
152 return
never executed: return 0;
0;
never executed: return 0;
0
153-
154 memset(ctx->tbl, 0, bl);-
155 ctx->nlast_block = 0;-
156 }
executed 4 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
4
157 return
executed 4 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1;
executed 4 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
4
158}-
159-
160int CMAC_Update(CMAC_CTX *ctx, const void *in, size_t dlen)-
161{-
162 const unsigned char *data = in;-
163 size_t bl;-
164 if (ctx->nlast_block == -1
ctx->nlast_block == -1Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-4
165 return
never executed: return 0;
0;
never executed: return 0;
0
166 if (dlen == 0
dlen == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
1-3
167 return
executed 1 time by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1;
executed 1 time by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1
168 bl = EVP_CIPHER_CTX_block_size(ctx->cctx);-
169-
170 if (ctx->nlast_block > 0
ctx->nlast_block > 0Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
0-3
171 size_t nleft;-
172 nleft = bl - ctx->nlast_block;-
173 if (dlen < nleft
dlen < nleftDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
174 nleft = dlen;
never executed: nleft = dlen;
0
175 memcpy(ctx->last_block + ctx->nlast_block, data, nleft);-
176 dlen -= nleft;-
177 ctx->nlast_block += nleft;-
178-
179 if (dlen == 0
dlen == 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
180 return
never executed: return 1;
1;
never executed: return 1;
0
181 data += nleft;-
182-
183 if (!EVP_Cipher(ctx->cctx, ctx->tbl, ctx->last_block, bl)
!EVP_Cipher(ct...ast_block, bl)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
184 return
never executed: return 0;
0;
never executed: return 0;
0
185 }
never executed: end of block
0
186-
187 while (dlen > bl
dlen > blDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
3-6
188 if (!EVP_Cipher(ctx->cctx, ctx->tbl, data, bl)
!EVP_Cipher(ct...tbl, data, bl)Description
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-6
189 return
never executed: return 0;
0;
never executed: return 0;
0
190 dlen -= bl;-
191 data += bl;-
192 }
executed 6 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
6
193-
194 memcpy(ctx->last_block, data, dlen);-
195 ctx->nlast_block = dlen;-
196 return
executed 3 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1;
executed 3 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
3
197-
198}-
199-
200int CMAC_Final(CMAC_CTX *ctx, unsigned char *out, size_t *poutlen)-
201{-
202 int i, bl, lb;-
203 if (ctx->nlast_block == -1
ctx->nlast_block == -1Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-8
204 return
never executed: return 0;
0;
never executed: return 0;
0
205 bl = EVP_CIPHER_CTX_block_size(ctx->cctx);-
206 *poutlen = (size_t)bl;-
207 if (!out
!outDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
4
208 return
executed 4 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1;
executed 4 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
4
209 lb = ctx->nlast_block;-
210-
211 if (lb == bl
lb == blDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
1-3
212 for (i = 0; i < bl
i < blDescription
TRUEevaluated 40 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
; i++)
3-40
213 out[i] = ctx->last_block[i] ^ ctx->k1[i];
executed 40 times by 1 test: out[i] = ctx->last_block[i] ^ ctx->k1[i];
Executed by:
  • libcrypto.so.1.1
40
214 }
executed 3 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
else {
3
215 ctx->last_block[lb] = 0x80;-
216 if (bl - lb > 1
bl - lb > 1Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
)
0-1
217 memset(ctx->last_block + lb + 1, 0, bl - lb - 1);
executed 1 time by 1 test: memset(ctx->last_block + lb + 1, 0, bl - lb - 1);
Executed by:
  • libcrypto.so.1.1
1
218 for (i = 0; i < bl
i < blDescription
TRUEevaluated 16 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
; i++)
1-16
219 out[i] = ctx->last_block[i] ^ ctx->k2[i];
executed 16 times by 1 test: out[i] = ctx->last_block[i] ^ ctx->k2[i];
Executed by:
  • libcrypto.so.1.1
16
220 }
executed 1 time by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
1
221 if (!EVP_Cipher(ctx->cctx, out, out, bl)
!EVP_Cipher(ct... out, out, bl)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
0-4
222 OPENSSL_cleanse(out, bl);-
223 return
never executed: return 0;
0;
never executed: return 0;
0
224 }-
225 return
executed 4 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1;
executed 4 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
4
226}-
227-
228int CMAC_resume(CMAC_CTX *ctx)-
229{-
230 if (ctx->nlast_block == -1
ctx->nlast_block == -1Description
TRUEnever evaluated
FALSEnever evaluated
)
0
231 return
never executed: return 0;
0;
never executed: return 0;
0
232-
233-
234-
235-
236-
237-
238-
239 return
never executed: return EVP_EncryptInit_ex(ctx->cctx, ((void *)0) , ((void *)0) , ((void *)0) , ctx->tbl);
EVP_EncryptInit_ex(ctx->cctx,
never executed: return EVP_EncryptInit_ex(ctx->cctx, ((void *)0) , ((void *)0) , ((void *)0) , ctx->tbl);
0
240 ((void *)0)
never executed: return EVP_EncryptInit_ex(ctx->cctx, ((void *)0) , ((void *)0) , ((void *)0) , ctx->tbl);
0
241 ,
never executed: return EVP_EncryptInit_ex(ctx->cctx, ((void *)0) , ((void *)0) , ((void *)0) , ctx->tbl);
0
242 ((void *)0)
never executed: return EVP_EncryptInit_ex(ctx->cctx, ((void *)0) , ((void *)0) , ((void *)0) , ctx->tbl);
0
243 ,
never executed: return EVP_EncryptInit_ex(ctx->cctx, ((void *)0) , ((void *)0) , ((void *)0) , ctx->tbl);
0
244 ((void *)0)
never executed: return EVP_EncryptInit_ex(ctx->cctx, ((void *)0) , ((void *)0) , ((void *)0) , ctx->tbl);
0
245 , ctx->tbl);
never executed: return EVP_EncryptInit_ex(ctx->cctx, ((void *)0) , ((void *)0) , ((void *)0) , ctx->tbl);
0
246}-
Switch to Source codePreprocessed file

Generated by Squish Coco 4.2.2