OpenCoverage

e_chacha20_poly1305.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/evp/e_chacha20_poly1305.c
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6typedef struct {-
7 union {-
8 double align;-
9 unsigned int d[32 / 4];-
10 } key;-
11 unsigned int counter[16 / 4];-
12 unsigned char buf[64];-
13 unsigned int partial_len;-
14} EVP_CHACHA_KEY;-
15-
16-
17-
18static int chacha_init_key(EVP_CIPHER_CTX *ctx,-
19 const unsigned char user_key[32],-
20 const unsigned char iv[16], int enc)-
21{-
22 EVP_CHACHA_KEY *key = ((EVP_CHACHA_KEY *)(ctx)->cipher_data);-
23 unsigned int i;-
24-
25 if (user_key
user_keyDescription
TRUEevaluated 13171 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 8866 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
8866-13171
26 for (i = 0; i < 32
i < 32Description
TRUEevaluated 105368 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 13171 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
; i+=4) {
13171-105368
27 key->key.d[i/4] = ( ((unsigned int)(user_key+i)[0]) | ((unsigned int)(user_key+i)[1]<<8) | ((unsigned int)(user_key+i)[2]<<16) | ((unsigned int)(user_key+i)[3]<<24) );-
28 }
executed 105368 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
105368
29-
30 if (iv
ivDescription
TRUEevaluated 15176 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 6861 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
6861-15176
31 for (i = 0; i < 16
i < 16Description
TRUEevaluated 60704 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 15176 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
; i+=4) {
15176-60704
32 key->counter[i/4] = ( ((unsigned int)(iv+i)[0]) | ((unsigned int)(iv+i)[1]<<8) | ((unsigned int)(iv+i)[2]<<16) | ((unsigned int)(iv+i)[3]<<24) );-
33 }
executed 60704 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
60704
34-
35 key->partial_len = 0;-
36-
37 return
executed 22037 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1;
executed 22037 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
22037
38}-
39-
40static int chacha_cipher(EVP_CIPHER_CTX * ctx, unsigned char *out,-
41 const unsigned char *inp, size_t len)-
42{-
43 EVP_CHACHA_KEY *key = ((EVP_CHACHA_KEY *)(ctx)->cipher_data);-
44 unsigned int n, rem, ctr32;-
45-
46 if ((
(n = key->partial_len)Description
TRUEevaluated 16632 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 29675 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
n = key->partial_len)
(n = key->partial_len)Description
TRUEevaluated 16632 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 29675 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
16632-29675
47 while (len
lenDescription
TRUEevaluated 546996 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1812 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
&& n < 64
n < 64Description
TRUEevaluated 532176 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 14820 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
1812-546996
48 *out++ = *inp++ ^ key->buf[n++];-
49 len--;-
50 }
executed 532176 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
532176
51 key->partial_len = n;-
52-
53 if (len == 0
len == 0Description
TRUEevaluated 1812 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 14820 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
1812-14820
54 return
executed 1812 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1;
executed 1812 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1812
55-
56 if (n == 64
n == 64Description
TRUEevaluated 14820 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
) {
0-14820
57 key->partial_len = 0;-
58 key->counter[0]++;-
59 if (key->counter[0] == 0
key->counter[0] == 0Description
TRUEnever evaluated
FALSEevaluated 14820 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-14820
60 key->counter[1]++;
never executed: key->counter[1]++;
0
61 }
executed 14820 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
14820
62 }
executed 14820 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
14820
63-
64 rem = (unsigned int)(len % 64);-
65 len -= rem;-
66 ctr32 = key->counter[0];-
67 while (len >= 64
len >= 64Description
TRUEevaluated 36005 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 44495 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
36005-44495
68 size_t blocks = len / 64;-
69-
70-
71-
72-
73-
74 if (sizeof(size_t)>sizeof(unsigned int)
sizeof(size_t)...(unsigned int)Description
TRUEevaluated 36005 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
&& blocks>(1U<<28)
blocks>(1U<<28)Description
TRUEnever evaluated
FALSEevaluated 36005 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-36005
75 blocks = (1U<<28);
never executed: blocks = (1U<<28);
0
76-
77-
78-
79-
80-
81-
82-
83 ctr32 += (unsigned int)blocks;-
84 if (ctr32 < blocks
ctr32 < blocksDescription
TRUEnever evaluated
FALSEevaluated 36005 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
0-36005
85 blocks -= ctr32;-
86 ctr32 = 0;-
87 }
never executed: end of block
0
88 blocks *= 64;-
89 ChaCha20_ctr32(out, inp, blocks, key->key.d, key->counter);-
90 len -= blocks;-
91 inp += blocks;-
92 out += blocks;-
93-
94 key->counter[0] = ctr32;-
95 if (ctr32 == 0
ctr32 == 0Description
TRUEnever evaluated
FALSEevaluated 36005 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) key->counter[1]++;
never executed: key->counter[1]++;
0-36005
96 }
executed 36005 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
36005
97-
98 if (rem
remDescription
TRUEevaluated 25092 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 19403 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
19403-25092
99 memset(key->buf, 0, sizeof(key->buf));-
100 ChaCha20_ctr32(key->buf, key->buf, 64,-
101 key->key.d, key->counter);-
102 for (n = 0; n < rem
n < remDescription
TRUEevaluated 661326 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 25092 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
; n++)
25092-661326
103 out[n] = inp[n] ^ key->buf[n];
executed 661326 times by 1 test: out[n] = inp[n] ^ key->buf[n];
Executed by:
  • libcrypto.so.1.1
661326
104 key->partial_len = rem;-
105 }
executed 25092 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
25092
106-
107 return
executed 44495 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1;
executed 44495 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
44495
108}-
109-
110static const EVP_CIPHER chacha20 = {-
111 1019,-
112 1,-
113 32,-
114 16,-
115 0x10 | 0x20,-
116 chacha_init_key,-
117 chacha_cipher,-
118 -
119 ((void *)0)-
120 ,-
121 sizeof(EVP_CHACHA_KEY),-
122 -
123 ((void *)0)-
124 ,-
125 -
126 ((void *)0)-
127 ,-
128 -
129 ((void *)0)-
130 ,-
131 -
132 ((void *)0)-
133-
134};-
135-
136const EVP_CIPHER *EVP_chacha20(void)-
137{-
138 return
executed 1964 times by 1 test: return &chacha20;
Executed by:
  • libcrypto.so.1.1
&chacha20;
executed 1964 times by 1 test: return &chacha20;
Executed by:
  • libcrypto.so.1.1
1964
139}-
140-
141-
142-
143typedef struct {-
144 EVP_CHACHA_KEY key;-
145 unsigned int nonce[12/4];-
146 unsigned char tag[16];-
147 unsigned char tls_aad[16];-
148 struct { uint64_t aad, text; } len;-
149 int aad, mac_inited, tag_len, nonce_len;-
150 size_t tls_payload_length;-
151} EVP_CHACHA_AEAD_CTX;-
152-
153-
154-
155-
156-
157static int chacha20_poly1305_init_key(EVP_CIPHER_CTX *ctx,-
158 const unsigned char *inkey,-
159 const unsigned char *iv, int enc)-
160{-
161 EVP_CHACHA_AEAD_CTX *actx = ((EVP_CHACHA_AEAD_CTX *)(ctx)->cipher_data);-
162-
163 if (!inkey
!inkeyDescription
TRUEevaluated 8936 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 6645 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
&& !iv
!ivDescription
TRUEevaluated 456 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 8480 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
456-8936
164 return
executed 456 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1;
executed 456 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
456
165-
166 actx->len.aad = 0;-
167 actx->len.text = 0;-
168 actx->aad = 0;-
169 actx->mac_inited = 0;-
170 actx->tls_payload_length = ((size_t)-1);-
171-
172 if (iv !=
iv != ((void *)0)Description
TRUEevaluated 11720 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3405 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
3405-11720
173 ((void *)0)
iv != ((void *)0)Description
TRUEevaluated 11720 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3405 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
3405-11720
174 ) {-
175 unsigned char temp[16] = { 0 };-
176-
177-
178 if (actx->nonce_len <= 16
actx->nonce_len <= 16Description
TRUEevaluated 11720 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
)
0-11720
179 memcpy(temp + 16 - actx->nonce_len, iv,
executed 11720 times by 1 test: memcpy(temp + 16 - actx->nonce_len, iv, actx->nonce_len);
Executed by:
  • libcrypto.so.1.1
11720
180 actx->nonce_len);
executed 11720 times by 1 test: memcpy(temp + 16 - actx->nonce_len, iv, actx->nonce_len);
Executed by:
  • libcrypto.so.1.1
11720
181-
182 chacha_init_key(ctx, inkey, temp, enc);-
183-
184 actx->nonce[0] = actx->key.counter[1];-
185 actx->nonce[1] = actx->key.counter[2];-
186 actx->nonce[2] = actx->key.counter[3];-
187 }
executed 11720 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
else {
11720
188 chacha_init_key(ctx, inkey, -
189 ((void *)0)-
190 , enc);-
191 }
executed 3405 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
3405
192-
193 return
executed 15125 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1;
executed 15125 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
15125
194}-
195-
196-
197-
198-
199-
200-
201void *xor128_encrypt_n_pad(void *out, const void *inp, void *otp, size_t len);-
202void *xor128_decrypt_n_pad(void *out, const void *inp, void *otp, size_t len);-
203static const unsigned char zero[4 * 64] = { 0 };-
204-
205-
206-
207-
208static int chacha20_poly1305_tls_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,-
209 const unsigned char *in, size_t len)-
210{-
211 EVP_CHACHA_AEAD_CTX *actx = ((EVP_CHACHA_AEAD_CTX *)(ctx)->cipher_data);-
212 size_t tail, tohash_len, buf_len, plen = actx->tls_payload_length;-
213 unsigned char *buf, *tohash, *ctr, storage[sizeof(zero) + 32];-
214-
215 if (len != plen + 16
len != plen + 16Description
TRUEnever evaluated
FALSEevaluated 110 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-110
216 return
never executed: return -1;
-1;
never executed: return -1;
0
217-
218 buf = storage + ((0 - (size_t)storage) & 15);-
219 ctr = buf + 64;-
220 tohash = buf + 64 - 16;-
221-
222-
223 if (plen <= 3 * 64
plen <= 3 * 64Description
TRUEevaluated 57 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 53 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
53-57
224 actx->key.counter[0] = 0;-
225 buf_len = (plen + 2 * 64 - 1) & (0 - 64);-
226 ChaCha20_ctr32(buf, zero, buf_len, actx->key.key.d,-
227 actx->key.counter);-
228 Poly1305_Init(((POLY1305 *)(actx + 1)), buf);-
229 actx->key.partial_len = 0;-
230 memcpy(tohash, actx->tls_aad, 16);-
231 tohash_len = 16;-
232 actx->len.aad = 13;-
233 actx->len.text = plen;-
234-
235 if (plen
plenDescription
TRUEevaluated 56 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
1-56
236 if (ctx->encrypt
ctx->encryptDescription
TRUEevaluated 25 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 31 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
25-31
237 ctr = xor128_encrypt_n_pad(out, in, ctr, plen);
executed 25 times by 1 test: ctr = xor128_encrypt_n_pad(out, in, ctr, plen);
Executed by:
  • libcrypto.so.1.1
25
238 else-
239 ctr = xor128_decrypt_n_pad(out, in, ctr, plen);
executed 31 times by 1 test: ctr = xor128_decrypt_n_pad(out, in, ctr, plen);
Executed by:
  • libcrypto.so.1.1
31
240-
241 in += plen;-
242 out += plen;-
243 tohash_len = (size_t)(ctr - tohash);-
244 }
executed 56 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
56
245 }
executed 57 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
57
246 else {-
247 actx->key.counter[0] = 0;-
248 ChaCha20_ctr32(buf, zero, (buf_len = 64),-
249 actx->key.key.d, actx->key.counter);-
250 Poly1305_Init(((POLY1305 *)(actx + 1)), buf);-
251 actx->key.counter[0] = 1;-
252 actx->key.partial_len = 0;-
253 Poly1305_Update(((POLY1305 *)(actx + 1)), actx->tls_aad, 16);-
254 tohash = ctr;-
255 tohash_len = 0;-
256 actx->len.aad = 13;-
257 actx->len.text = plen;-
258-
259 if (ctx->encrypt
ctx->encryptDescription
TRUEevaluated 40 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 13 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
13-40
260 ChaCha20_ctr32(out, in, plen, actx->key.key.d, actx->key.counter);-
261 Poly1305_Update(((POLY1305 *)(actx + 1)), out, plen);-
262 }
executed 40 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
else {
40
263 Poly1305_Update(((POLY1305 *)(actx + 1)), in, plen);-
264 ChaCha20_ctr32(out, in, plen, actx->key.key.d, actx->key.counter);-
265 }
executed 13 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
13
266-
267 in += plen;-
268 out += plen;-
269 tail = (0 - plen) & (16 - 1);-
270 Poly1305_Update(((POLY1305 *)(actx + 1)), zero, tail);-
271 }
executed 53 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
53
272-
273 {-
274 const union {-
275 long one;-
276 char little;-
277 } is_endian = { 1 };-
278-
279 if (is_endian.little
is_endian.littleDescription
TRUEevaluated 110 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
) {
0-110
280 memcpy(ctr, (unsigned char *)&actx->len, 16);-
281 }
executed 110 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
else {
110
282 ctr[0] = (unsigned char)(actx->len.aad);-
283 ctr[1] = (unsigned char)(actx->len.aad>>8);-
284 ctr[2] = (unsigned char)(actx->len.aad>>16);-
285 ctr[3] = (unsigned char)(actx->len.aad>>24);-
286 ctr[4] = (unsigned char)(actx->len.aad>>32);-
287 ctr[5] = (unsigned char)(actx->len.aad>>40);-
288 ctr[6] = (unsigned char)(actx->len.aad>>48);-
289 ctr[7] = (unsigned char)(actx->len.aad>>56);-
290-
291 ctr[8] = (unsigned char)(actx->len.text);-
292 ctr[9] = (unsigned char)(actx->len.text>>8);-
293 ctr[10] = (unsigned char)(actx->len.text>>16);-
294 ctr[11] = (unsigned char)(actx->len.text>>24);-
295 ctr[12] = (unsigned char)(actx->len.text>>32);-
296 ctr[13] = (unsigned char)(actx->len.text>>40);-
297 ctr[14] = (unsigned char)(actx->len.text>>48);-
298 ctr[15] = (unsigned char)(actx->len.text>>56);-
299 }
never executed: end of block
0
300 tohash_len += 16;-
301 }-
302-
303 Poly1305_Update(((POLY1305 *)(actx + 1)), tohash, tohash_len);-
304 OPENSSL_cleanse(buf, buf_len);-
305 Poly1305_Final(((POLY1305 *)(actx + 1)), ctx->encrypt ? actx->tag-
306 : tohash);-
307-
308 actx->tls_payload_length = ((size_t)-1);-
309-
310 if (ctx->encrypt
ctx->encryptDescription
TRUEevaluated 65 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 45 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
45-65
311 memcpy(out, actx->tag, 16);-
312 }
executed 65 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
else {
65
313 if (CRYPTO_memcmp(tohash, in, 16)
CRYPTO_memcmp(tohash, in, 16)Description
TRUEevaluated 20 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 25 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
20-25
314 memset(out - (len - 16), 0,-
315 len - 16);-
316 return
executed 20 times by 1 test: return -1;
Executed by:
  • libcrypto.so.1.1
-1;
executed 20 times by 1 test: return -1;
Executed by:
  • libcrypto.so.1.1
20
317 }-
318 }
executed 25 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
25
319-
320 return
executed 90 times by 1 test: return len;
Executed by:
  • libcrypto.so.1.1
len;
executed 90 times by 1 test: return len;
Executed by:
  • libcrypto.so.1.1
90
321}-
322-
323-
324-
325-
326static int chacha20_poly1305_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,-
327 const unsigned char *in, size_t len)-
328{-
329 EVP_CHACHA_AEAD_CTX *actx = ((EVP_CHACHA_AEAD_CTX *)(ctx)->cipher_data);-
330 size_t rem, plen = actx->tls_payload_length;-
331-
332 if (!actx->mac_inited
!actx->mac_initedDescription
TRUEevaluated 14853 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 35850 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
14853-35850
333-
334 if (plen != ((size_t)-1)
plen != ((size_t)-1)Description
TRUEevaluated 110 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 14743 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
&& out !=
out != ((void *)0)Description
TRUEevaluated 110 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-14743
335 ((void *)0)
out != ((void *)0)Description
TRUEevaluated 110 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-110
336 )-
337 return
executed 110 times by 1 test: return chacha20_poly1305_tls_cipher(ctx, out, in, len);
Executed by:
  • libcrypto.so.1.1
chacha20_poly1305_tls_cipher(ctx, out, in, len);
executed 110 times by 1 test: return chacha20_poly1305_tls_cipher(ctx, out, in, len);
Executed by:
  • libcrypto.so.1.1
110
338-
339 actx->key.counter[0] = 0;-
340 ChaCha20_ctr32(actx->key.buf, zero, 64,-
341 actx->key.key.d, actx->key.counter);-
342 Poly1305_Init(((POLY1305 *)(actx + 1)), actx->key.buf);-
343 actx->key.counter[0] = 1;-
344 actx->key.partial_len = 0;-
345 actx->len.aad = actx->len.text = 0;-
346 actx->mac_inited = 1;-
347 if (plen != ((size_t)-1)
plen != ((size_t)-1)Description
TRUEnever evaluated
FALSEevaluated 14743 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
0-14743
348 Poly1305_Update(((POLY1305 *)(actx + 1)), actx->tls_aad,-
349 13);-
350 actx->len.aad = 13;-
351 actx->aad = 1;-
352 }
never executed: end of block
0
353 }
executed 14743 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
14743
354-
355 if (in
inDescription
TRUEevaluated 35850 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 14743 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
14743-35850
356 if (out ==
out == ((void *)0)Description
TRUEevaluated 8721 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 27129 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
8721-27129
357 ((void *)0)
out == ((void *)0)Description
TRUEevaluated 8721 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 27129 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
8721-27129
358 ) {-
359 Poly1305_Update(((POLY1305 *)(actx + 1)), in, len);-
360 actx->len.aad += len;-
361 actx->aad = 1;-
362 return
executed 8721 times by 1 test: return len;
Executed by:
  • libcrypto.so.1.1
len;
executed 8721 times by 1 test: return len;
Executed by:
  • libcrypto.so.1.1
8721
363 } else {-
364 if (actx->aad
actx->aadDescription
TRUEevaluated 8601 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 18528 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
8601-18528
365 if ((
(rem = (size_t...>len.aad % 16)Description
TRUEevaluated 8601 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
rem = (size_t)actx->len.aad % 16)
(rem = (size_t...>len.aad % 16)Description
TRUEevaluated 8601 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
)
0-8601
366 Poly1305_Update(((POLY1305 *)(actx + 1)), zero,
executed 8601 times by 1 test: Poly1305_Update(((POLY1305 *)(actx + 1)), zero, 16 - rem);
Executed by:
  • libcrypto.so.1.1
8601
367 16 - rem);
executed 8601 times by 1 test: Poly1305_Update(((POLY1305 *)(actx + 1)), zero, 16 - rem);
Executed by:
  • libcrypto.so.1.1
8601
368 actx->aad = 0;-
369 }
executed 8601 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
8601
370-
371 actx->tls_payload_length = ((size_t)-1);-
372 if (plen == ((size_t)-1)
plen == ((size_t)-1)Description
TRUEevaluated 27129 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
)
0-27129
373 plen = len;
executed 27129 times by 1 test: plen = len;
Executed by:
  • libcrypto.so.1.1
27129
374 else if (len != plen + 16
len != plen + 16Description
TRUEnever evaluated
FALSEnever evaluated
)
0
375 return
never executed: return -1;
-1;
never executed: return -1;
0
376-
377 if (ctx->encrypt
ctx->encryptDescription
TRUEevaluated 9791 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 17338 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
9791-17338
378 chacha_cipher(ctx, out, in, plen);-
379 Poly1305_Update(((POLY1305 *)(actx + 1)), out, plen);-
380 in += plen;-
381 out += plen;-
382 actx->len.text += plen;-
383 }
executed 9791 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
else {
9791
384 Poly1305_Update(((POLY1305 *)(actx + 1)), in, plen);-
385 chacha_cipher(ctx, out, in, plen);-
386 in += plen;-
387 out += plen;-
388 actx->len.text += plen;-
389 }
executed 17338 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
17338
390 }-
391 }-
392 if (in ==
in == ((void *)0)Description
TRUEevaluated 14743 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 27129 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
14743-27129
393 ((void *)0)
in == ((void *)0)Description
TRUEevaluated 14743 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 27129 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
14743-27129
394 -
395 || plen != len
plen != lenDescription
TRUEnever evaluated
FALSEevaluated 27129 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
0-27129
396 const union {-
397 long one;-
398 char little;-
399 } is_endian = { 1 };-
400 unsigned char temp[16];-
401-
402 if (actx->aad
actx->aadDescription
TRUEnever evaluated
FALSEevaluated 14743 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
0-14743
403 if ((
(rem = (size_t...>len.aad % 16)Description
TRUEnever evaluated
FALSEnever evaluated
rem = (size_t)actx->len.aad % 16)
(rem = (size_t...>len.aad % 16)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
404 Poly1305_Update(((POLY1305 *)(actx + 1)), zero,
never executed: Poly1305_Update(((POLY1305 *)(actx + 1)), zero, 16 - rem);
0
405 16 - rem);
never executed: Poly1305_Update(((POLY1305 *)(actx + 1)), zero, 16 - rem);
0
406 actx->aad = 0;-
407 }
never executed: end of block
0
408-
409 if ((
(rem = (size_t...len.text % 16)Description
TRUEevaluated 8396 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 6347 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
rem = (size_t)actx->len.text % 16)
(rem = (size_t...len.text % 16)Description
TRUEevaluated 8396 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 6347 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
6347-8396
410 Poly1305_Update(((POLY1305 *)(actx + 1)), zero,
executed 8396 times by 1 test: Poly1305_Update(((POLY1305 *)(actx + 1)), zero, 16 - rem);
Executed by:
  • libcrypto.so.1.1
8396
411 16 - rem);
executed 8396 times by 1 test: Poly1305_Update(((POLY1305 *)(actx + 1)), zero, 16 - rem);
Executed by:
  • libcrypto.so.1.1
8396
412-
413 if (is_endian.little
is_endian.littleDescription
TRUEevaluated 14743 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
) {
0-14743
414 Poly1305_Update(((POLY1305 *)(actx + 1)),-
415 (unsigned char *)&actx->len, 16);-
416 }
executed 14743 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
else {
14743
417 temp[0] = (unsigned char)(actx->len.aad);-
418 temp[1] = (unsigned char)(actx->len.aad>>8);-
419 temp[2] = (unsigned char)(actx->len.aad>>16);-
420 temp[3] = (unsigned char)(actx->len.aad>>24);-
421 temp[4] = (unsigned char)(actx->len.aad>>32);-
422 temp[5] = (unsigned char)(actx->len.aad>>40);-
423 temp[6] = (unsigned char)(actx->len.aad>>48);-
424 temp[7] = (unsigned char)(actx->len.aad>>56);-
425-
426 temp[8] = (unsigned char)(actx->len.text);-
427 temp[9] = (unsigned char)(actx->len.text>>8);-
428 temp[10] = (unsigned char)(actx->len.text>>16);-
429 temp[11] = (unsigned char)(actx->len.text>>24);-
430 temp[12] = (unsigned char)(actx->len.text>>32);-
431 temp[13] = (unsigned char)(actx->len.text>>40);-
432 temp[14] = (unsigned char)(actx->len.text>>48);-
433 temp[15] = (unsigned char)(actx->len.text>>56);-
434-
435 Poly1305_Update(((POLY1305 *)(actx + 1)), temp, 16);-
436 }
never executed: end of block
0
437 Poly1305_Final(((POLY1305 *)(actx + 1)), ctx->encrypt ? actx->tag-
438 : temp);-
439 actx->mac_inited = 0;-
440-
441 if (in !=
in != ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 14743 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-14743
442 ((void *)0)
in != ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 14743 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-14743
443 && len != plen
len != plenDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
444 if (ctx->encrypt
ctx->encryptDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
445 memcpy(out, actx->tag, 16);-
446 }
never executed: end of block
else {
0
447 if (CRYPTO_memcmp(temp, in, 16)
CRYPTO_memcmp(temp, in, 16)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
448 memset(out - plen, 0, plen);-
449 return
never executed: return -1;
-1;
never executed: return -1;
0
450 }-
451 }
never executed: end of block
0
452 }-
453 else if (!ctx->encrypt
!ctx->encryptDescription
TRUEevaluated 11146 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3597 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
3597-11146
454 if (CRYPTO_memcmp(temp, actx->tag, actx->tag_len)
CRYPTO_memcmp(...actx->tag_len)Description
TRUEevaluated 7993 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3153 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
3153-7993
455 return
executed 7993 times by 1 test: return -1;
Executed by:
  • libcrypto.so.1.1
-1;
executed 7993 times by 1 test: return -1;
Executed by:
  • libcrypto.so.1.1
7993
456 }
executed 3153 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
3153
457 }
executed 6750 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
6750
458 return
executed 33879 times by 1 test: return len;
Executed by:
  • libcrypto.so.1.1
len;
executed 33879 times by 1 test: return len;
Executed by:
  • libcrypto.so.1.1
33879
459}-
460-
461static int chacha20_poly1305_cleanup(EVP_CIPHER_CTX *ctx)-
462{-
463 EVP_CHACHA_AEAD_CTX *actx = ((EVP_CHACHA_AEAD_CTX *)(ctx)->cipher_data);-
464 if (actx
actxDescription
TRUEevaluated 6645 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
)
0-6645
465 OPENSSL_cleanse(ctx->cipher_data, sizeof(*actx) + Poly1305_ctx_size());
executed 6645 times by 1 test: OPENSSL_cleanse(ctx->cipher_data, sizeof(*actx) + Poly1305_ctx_size());
Executed by:
  • libcrypto.so.1.1
6645
466 return
executed 6645 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1;
executed 6645 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
6645
467}-
468-
469static int chacha20_poly1305_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg,-
470 void *ptr)-
471{-
472 EVP_CHACHA_AEAD_CTX *actx = ((EVP_CHACHA_AEAD_CTX *)(ctx)->cipher_data);-
473-
474 switch(type) {-
475 case
executed 6645 times by 1 test: case 0x0:
Executed by:
  • libcrypto.so.1.1
0x0:
executed 6645 times by 1 test: case 0x0:
Executed by:
  • libcrypto.so.1.1
6645
476 if (actx ==
actx == ((void *)0)Description
TRUEevaluated 6645 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-6645
477 ((void *)0)
actx == ((void *)0)Description
TRUEevaluated 6645 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-6645
478 )-
479 actx = ctx->cipher_data
executed 6645 times by 1 test: actx = ctx->cipher_data = CRYPTO_zalloc(sizeof(*actx) + Poly1305_ctx_size(), __FILE__, 507);
Executed by:
  • libcrypto.so.1.1
6645
480 = CRYPTO_zalloc(sizeof(*actx) + Poly1305_ctx_size(), __FILE__, 507);
executed 6645 times by 1 test: actx = ctx->cipher_data = CRYPTO_zalloc(sizeof(*actx) + Poly1305_ctx_size(), __FILE__, 507);
Executed by:
  • libcrypto.so.1.1
6645
481 if (actx ==
actx == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 6645 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-6645
482 ((void *)0)
actx == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 6645 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-6645
483 ) {-
484 ERR_put_error(6,(182),(134),__FILE__,509);-
485 return
never executed: return 0;
0;
never executed: return 0;
0
486 }-
487 actx->len.aad = 0;-
488 actx->len.text = 0;-
489 actx->aad = 0;-
490 actx->mac_inited = 0;-
491 actx->tag_len = 0;-
492 actx->nonce_len = 12;-
493 actx->tls_payload_length = ((size_t)-1);-
494 memset(actx->tls_aad, 0, 16);-
495 return
executed 6645 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1;
executed 6645 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
6645
496-
497 case
never executed: case 0x8:
0x8:
never executed: case 0x8:
0
498 if (actx
actxDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
499 EVP_CIPHER_CTX *dst = (EVP_CIPHER_CTX *)ptr;-
500-
501 dst->cipher_data =-
502 CRYPTO_memdup((actx), sizeof(*actx) + Poly1305_ctx_size(), __FILE__, 527);-
503 if (dst->cipher_data ==
dst->cipher_da...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
504 ((void *)0)
dst->cipher_da...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
505 ) {-
506 ERR_put_error(6,(182),(173),__FILE__,529);-
507 return
never executed: return 0;
0;
never executed: return 0;
0
508 }-
509 }
never executed: end of block
0
510 return
never executed: return 1;
1;
never executed: return 1;
0
511-
512 case
executed 456 times by 1 test: case 0x9:
Executed by:
  • libcrypto.so.1.1
0x9:
executed 456 times by 1 test: case 0x9:
Executed by:
  • libcrypto.so.1.1
456
513 if (arg <= 0
arg <= 0Description
TRUEnever evaluated
FALSEevaluated 456 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
|| arg > 16
arg > 16Description
TRUEnever evaluated
FALSEevaluated 456 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-456
514 return
never executed: return 0;
0;
never executed: return 0;
0
515 actx->nonce_len = arg;-
516 return
executed 456 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1;
executed 456 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
456
517-
518 case
never executed: case 0x12:
0x12:
never executed: case 0x12:
0
519 if (arg != 12
arg != 12Description
TRUEnever evaluated
FALSEnever evaluated
)
0
520 return
never executed: return 0;
0;
never executed: return 0;
0
521 actx->nonce[0] = actx->key.counter[1]-
522 = ( ((unsigned int)((unsigned char *)ptr)[0]) | ((unsigned int)((unsigned char *)ptr)[1]<<8) | ((unsigned int)((unsigned char *)ptr)[2]<<16) | ((unsigned int)((unsigned char *)ptr)[3]<<24) );-
523 actx->nonce[1] = actx->key.counter[2]-
524 = ( ((unsigned int)((unsigned char *)ptr+4)[0]) | ((unsigned int)((unsigned char *)ptr+4)[1]<<8) | ((unsigned int)((unsigned char *)ptr+4)[2]<<16) | ((unsigned int)((unsigned char *)ptr+4)[3]<<24) );-
525 actx->nonce[2] = actx->key.counter[3]-
526 = ( ((unsigned int)((unsigned char *)ptr+8)[0]) | ((unsigned int)((unsigned char *)ptr+8)[1]<<8) | ((unsigned int)((unsigned char *)ptr+8)[2]<<16) | ((unsigned int)((unsigned char *)ptr+8)[3]<<24) );-
527 return
never executed: return 1;
1;
never executed: return 1;
0
528-
529 case
executed 8134 times by 1 test: case 0x11:
Executed by:
  • libcrypto.so.1.1
0x11:
executed 8134 times by 1 test: case 0x11:
Executed by:
  • libcrypto.so.1.1
8134
530 if (arg <= 0
arg <= 0Description
TRUEnever evaluated
FALSEevaluated 8134 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
|| arg > 16
arg > 16Description
TRUEnever evaluated
FALSEevaluated 8134 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-8134
531 return
never executed: return 0;
0;
never executed: return 0;
0
532 if (ptr !=
ptr != ((void *)0)Description
TRUEevaluated 8074 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 60 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
60-8074
533 ((void *)0)
ptr != ((void *)0)Description
TRUEevaluated 8074 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 60 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
60-8074
534 ) {-
535 memcpy(actx->tag, ptr, arg);-
536 actx->tag_len = arg;-
537 }
executed 8074 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
8074
538 return
executed 8134 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1;
executed 8134 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
8134
539-
540 case
executed 527 times by 1 test: case 0x10:
Executed by:
  • libcrypto.so.1.1
0x10:
executed 527 times by 1 test: case 0x10:
Executed by:
  • libcrypto.so.1.1
527
541 if (arg <= 0
arg <= 0Description
TRUEnever evaluated
FALSEevaluated 527 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
|| arg > 16
arg > 16Description
TRUEnever evaluated
FALSEevaluated 527 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
|| !ctx->encrypt
!ctx->encryptDescription
TRUEnever evaluated
FALSEevaluated 527 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-527
542 return
never executed: return 0;
0;
never executed: return 0;
0
543 memcpy(ptr, actx->tag, arg);-
544 return
executed 527 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1;
executed 527 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
527
545-
546 case
executed 111 times by 1 test: case 0x16:
Executed by:
  • libcrypto.so.1.1
0x16:
executed 111 times by 1 test: case 0x16:
Executed by:
  • libcrypto.so.1.1
111
547 if (arg != 13
arg != 13Description
TRUEnever evaluated
FALSEevaluated 111 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-111
548 return
never executed: return 0;
0;
never executed: return 0;
0
549 {-
550 unsigned int len;-
551 unsigned char *aad = ptr;-
552-
553 memcpy(actx->tls_aad, ptr, 13);-
554 len = aad[13 - 2] << 8 |-
555 aad[13 - 1];-
556 aad = actx->tls_aad;-
557 if (!ctx->encrypt
!ctx->encryptDescription
TRUEevaluated 46 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 65 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
46-65
558 if (len < 16
len < 16Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 45 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
1-45
559 return
executed 1 time by 1 test: return 0;
Executed by:
  • libcrypto.so.1.1
0;
executed 1 time by 1 test: return 0;
Executed by:
  • libcrypto.so.1.1
1
560 len -= 16;-
561 aad[13 - 2] = (unsigned char)(len >> 8);-
562 aad[13 - 1] = (unsigned char)len;-
563 }
executed 45 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
45
564 actx->tls_payload_length = len;-
565-
566-
567-
568-
569 actx->key.counter[1] = actx->nonce[0];-
570 actx->key.counter[2] = actx->nonce[1] ^ ( ((unsigned int)(aad)[0]) | ((unsigned int)(aad)[1]<<8) | ((unsigned int)(aad)[2]<<16) | ((unsigned int)(aad)[3]<<24) );-
571 actx->key.counter[3] = actx->nonce[2] ^ ( ((unsigned int)(aad+4)[0]) | ((unsigned int)(aad+4)[1]<<8) | ((unsigned int)(aad+4)[2]<<16) | ((unsigned int)(aad+4)[3]<<24) );-
572 actx->mac_inited = 0;-
573-
574 return
executed 110 times by 1 test: return 16;
Executed by:
  • libcrypto.so.1.1
16;
executed 110 times by 1 test: return 16;
Executed by:
  • libcrypto.so.1.1
110
575 }-
576-
577 case
never executed: case 0x17:
0x17:
never executed: case 0x17:
0
578-
579 return
never executed: return 1;
1;
never executed: return 1;
0
580-
581 default
never executed: default:
:
never executed: default:
0
582 return
never executed: return -1;
-1;
never executed: return -1;
0
583 }-
584}-
585-
586static EVP_CIPHER chacha20_poly1305 = {-
587 1018,-
588 1,-
589 32,-
590 12,-
591 0x200000 | 0x10 |-
592 0x20 | 0x40 |-
593 0x400 | 0x100000,-
594 chacha20_poly1305_init_key,-
595 chacha20_poly1305_cipher,-
596 chacha20_poly1305_cleanup,-
597 0,-
598 -
599 ((void *)0)-
600 ,-
601 -
602 ((void *)0)-
603 ,-
604 chacha20_poly1305_ctrl,-
605 -
606 ((void *)0)-
607-
608};-
609-
610const EVP_CIPHER *EVP_chacha20_poly1305(void)-
611{-
612 return
executed 3922 times by 1 test: return(&chacha20_poly1305);
Executed by:
  • libcrypto.so.1.1
(&chacha20_poly1305);
executed 3922 times by 1 test: return(&chacha20_poly1305);
Executed by:
  • libcrypto.so.1.1
3922
613}-
Switch to Source codePreprocessed file

Generated by Squish Coco 4.2.2