OpenCoverage

bio_enc.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/evp/bio_enc.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/*-
2 * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.-
3 *-
4 * Licensed under the OpenSSL license (the "License"). You may not use-
5 * this file except in compliance with the License. You can obtain a copy-
6 * in the file LICENSE in the source distribution or at-
7 * https://www.openssl.org/source/license.html-
8 */-
9-
10#include <stdio.h>-
11#include <errno.h>-
12#include "internal/cryptlib.h"-
13#include <openssl/buffer.h>-
14#include <openssl/evp.h>-
15#include "internal/bio.h"-
16-
17static int enc_write(BIO *h, const char *buf, int num);-
18static int enc_read(BIO *h, char *buf, int size);-
19static long enc_ctrl(BIO *h, int cmd, long arg1, void *arg2);-
20static int enc_new(BIO *h);-
21static int enc_free(BIO *data);-
22static long enc_callback_ctrl(BIO *h, int cmd, BIO_info_cb *fps);-
23#define ENC_BLOCK_SIZE (1024*4)-
24#define ENC_MIN_CHUNK (256)-
25#define BUF_OFFSET (ENC_MIN_CHUNK + EVP_MAX_BLOCK_LENGTH)-
26-
27typedef struct enc_struct {-
28 int buf_len;-
29 int buf_off;-
30 int cont; /* <= 0 when finished */-
31 int finished;-
32 int ok; /* bad decrypt */-
33 EVP_CIPHER_CTX *cipher;-
34 unsigned char *read_start, *read_end;-
35 /*-
36 * buf is larger than ENC_BLOCK_SIZE because EVP_DecryptUpdate can return-
37 * up to a block more data than is presented to it-
38 */-
39 unsigned char buf[BUF_OFFSET + ENC_BLOCK_SIZE];-
40} BIO_ENC_CTX;-
41-
42static const BIO_METHOD methods_enc = {-
43 BIO_TYPE_CIPHER,-
44 "cipher",-
45 /* TODO: Convert to new style write function */-
46 bwrite_conv,-
47 enc_write,-
48 /* TODO: Convert to new style read function */-
49 bread_conv,-
50 enc_read,-
51 NULL, /* enc_puts, */-
52 NULL, /* enc_gets, */-
53 enc_ctrl,-
54 enc_new,-
55 enc_free,-
56 enc_callback_ctrl,-
57};-
58-
59const BIO_METHOD *BIO_f_cipher(void)-
60{-
61 return &methods_enc;
executed 37594 times by 1 test: return &methods_enc;
Executed by:
  • libcrypto.so.1.1
37594
62}-
63-
64static int enc_new(BIO *bi)-
65{-
66 BIO_ENC_CTX *ctx;-
67-
68 if ((ctx = OPENSSL_zalloc(sizeof(*ctx))) == NULL) {
(ctx = CRYPTO_...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 37594 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-37594
69 EVPerr(EVP_F_ENC_NEW, ERR_R_MALLOC_FAILURE);-
70 return 0;
never executed: return 0;
0
71 }-
72-
73 ctx->cipher = EVP_CIPHER_CTX_new();-
74 if (ctx->cipher == NULL) {
ctx->cipher == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 37594 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-37594
75 OPENSSL_free(ctx);-
76 return 0;
never executed: return 0;
0
77 }-
78 ctx->cont = 1;-
79 ctx->ok = 1;-
80 ctx->read_end = ctx->read_start = &(ctx->buf[BUF_OFFSET]);-
81 BIO_set_data(bi, ctx);-
82 BIO_set_init(bi, 1);-
83-
84 return 1;
executed 37594 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
37594
85}-
86-
87static int enc_free(BIO *a)-
88{-
89 BIO_ENC_CTX *b;-
90-
91 if (a == NULL)
a == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 37594 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-37594
92 return 0;
never executed: return 0;
0
93-
94 b = BIO_get_data(a);-
95 if (b == NULL)
b == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 37594 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-37594
96 return 0;
never executed: return 0;
0
97-
98 EVP_CIPHER_CTX_free(b->cipher);-
99 OPENSSL_clear_free(b, sizeof(BIO_ENC_CTX));-
100 BIO_set_data(a, NULL);-
101 BIO_set_init(a, 0);-
102-
103 return 1;
executed 37594 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
37594
104}-
105-
106static int enc_read(BIO *b, char *out, int outl)-
107{-
108 int ret = 0, i, blocksize;-
109 BIO_ENC_CTX *ctx;-
110 BIO *next;-
111-
112 if (out == NULL)
out == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 235890 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-235890
113 return 0;
never executed: return 0;
0
114 ctx = BIO_get_data(b);-
115-
116 next = BIO_next(b);-
117 if ((ctx == NULL) || (next == NULL))
(ctx == ((void *)0) )Description
TRUEnever evaluated
FALSEevaluated 235890 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
(next == ((void *)0) )Description
TRUEnever evaluated
FALSEevaluated 235890 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-235890
118 return 0;
never executed: return 0;
0
119-
120 /* First check if there are bytes decoded/encoded */-
121 if (ctx->buf_len > 0) {
ctx->buf_len > 0Description
TRUEevaluated 186712 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 49178 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
49178-186712
122 i = ctx->buf_len - ctx->buf_off;-
123 if (i > outl)
i > outlDescription
TRUEevaluated 122088 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 64624 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
64624-122088
124 i = outl;
executed 122088 times by 1 test: i = outl;
Executed by:
  • libcrypto.so.1.1
122088
125 memcpy(out, &(ctx->buf[ctx->buf_off]), i);-
126 ret = i;-
127 out += i;-
128 outl -= i;-
129 ctx->buf_off += i;-
130 if (ctx->buf_len == ctx->buf_off) {
ctx->buf_len == ctx->buf_offDescription
TRUEevaluated 64624 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 122088 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
64624-122088
131 ctx->buf_len = 0;-
132 ctx->buf_off = 0;-
133 }
executed 64624 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
64624
134 }
executed 186712 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
186712
135-
136 blocksize = EVP_CIPHER_CTX_block_size(ctx->cipher);-
137 if (blocksize == 1)
blocksize == 1Description
TRUEevaluated 196160 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 39730 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
39730-196160
138 blocksize = 0;
executed 196160 times by 1 test: blocksize = 0;
Executed by:
  • libcrypto.so.1.1
196160
139-
140 /*-
141 * At this point, we have room of outl bytes and an empty buffer, so we-
142 * should read in some more.-
143 */-
144-
145 while (outl > 0) {
outl > 0Description
TRUEevaluated 138946 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 166368 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
138946-166368
146 if (ctx->cont <= 0)
ctx->cont <= 0Description
TRUEevaluated 15264 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 123682 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
15264-123682
147 break;
executed 15264 times by 1 test: break;
Executed by:
  • libcrypto.so.1.1
15264
148-
149 if (ctx->read_start == ctx->read_end) { /* time to read more data */
ctx->read_star... ctx->read_endDescription
TRUEevaluated 73928 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 49754 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
49754-73928
150 ctx->read_end = ctx->read_start = &(ctx->buf[BUF_OFFSET]);-
151 i = BIO_read(next, ctx->read_start, ENC_BLOCK_SIZE);-
152 if (i > 0)
i > 0Description
TRUEevaluated 36964 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 36964 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
36964
153 ctx->read_end += i;
executed 36964 times by 1 test: ctx->read_end += i;
Executed by:
  • libcrypto.so.1.1
36964
154 } else {
executed 73928 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
73928
155 i = ctx->read_end - ctx->read_start;-
156 }
executed 49754 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
49754
157-
158 if (i <= 0) {
i <= 0Description
TRUEevaluated 36964 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 86718 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
36964-86718
159 /* Should be continue next time we are called? */-
160 if (!BIO_should_retry(next)) {
!BIO_test_flags(next, 0x08)Description
TRUEevaluated 36964 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-36964
161 ctx->cont = i;-
162 i = EVP_CipherFinal_ex(ctx->cipher,-
163 ctx->buf, &(ctx->buf_len));-
164 ctx->ok = i;-
165 ctx->buf_off = 0;-
166 } else {
executed 36964 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
36964
167 ret = (ret == 0) ? i : ret;
(ret == 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
168 break;
never executed: break;
0
169 }-
170 } else {-
171 if (outl > ENC_MIN_CHUNK) {
outl > (256)Description
TRUEevaluated 40898 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 45820 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
40898-45820
172 /*-
173 * Depending on flags block cipher decrypt can write-
174 * one extra block and then back off, i.e. output buffer-
175 * has to accommodate extra block...-
176 */-
177 int j = outl - blocksize, buf_len;-
178-
179 if (!EVP_CipherUpdate(ctx->cipher,
!EVP_CipherUpd...i > j ? j : i)Description
TRUEnever evaluated
FALSEevaluated 40898 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-40898
180 (unsigned char *)out, &buf_len,
!EVP_CipherUpd...i > j ? j : i)Description
TRUEnever evaluated
FALSEevaluated 40898 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-40898
181 ctx->read_start, i > j ? j : i)) {
!EVP_CipherUpd...i > j ? j : i)Description
TRUEnever evaluated
FALSEevaluated 40898 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-40898
182 BIO_clear_retry_flags(b);-
183 return 0;
never executed: return 0;
0
184 }-
185 ret += buf_len;-
186 out += buf_len;-
187 outl -= buf_len;-
188-
189 if ((i -= j) <= 0) {
(i -= j) <= 0Description
TRUEevaluated 16156 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 24742 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
16156-24742
190 ctx->read_start = ctx->read_end;-
191 continue;
executed 16156 times by 1 test: continue;
Executed by:
  • libcrypto.so.1.1
16156
192 }-
193 ctx->read_start += j;-
194 }
executed 24742 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
24742
195 if (i > ENC_MIN_CHUNK)
i > (256)Description
TRUEevaluated 49754 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 20808 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
20808-49754
196 i = ENC_MIN_CHUNK;
executed 49754 times by 1 test: i = (256);
Executed by:
  • libcrypto.so.1.1
49754
197 if (!EVP_CipherUpdate(ctx->cipher,
!EVP_CipherUpd...read_start, i)Description
TRUEnever evaluated
FALSEevaluated 70562 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-70562
198 ctx->buf, &ctx->buf_len,
!EVP_CipherUpd...read_start, i)Description
TRUEnever evaluated
FALSEevaluated 70562 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-70562
199 ctx->read_start, i)) {
!EVP_CipherUpd...read_start, i)Description
TRUEnever evaluated
FALSEevaluated 70562 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-70562
200 BIO_clear_retry_flags(b);-
201 ctx->ok = 0;-
202 return 0;
never executed: return 0;
0
203 }-
204 ctx->read_start += i;-
205 ctx->cont = 1;-
206 /*-
207 * Note: it is possible for EVP_CipherUpdate to decrypt zero-
208 * bytes because this is or looks like the final block: if this-
209 * happens we should retry and either read more data or decrypt-
210 * the final block-
211 */-
212 if (ctx->buf_len == 0)
ctx->buf_len == 0Description
TRUEevaluated 64 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 70498 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
64-70498
213 continue;
executed 64 times by 1 test: continue;
Executed by:
  • libcrypto.so.1.1
64
214 }
executed 70498 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
70498
215-
216 if (ctx->buf_len <= outl)
ctx->buf_len <= outlDescription
TRUEevaluated 43910 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 63552 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
43910-63552
217 i = ctx->buf_len;
executed 43910 times by 1 test: i = ctx->buf_len;
Executed by:
  • libcrypto.so.1.1
43910
218 else-
219 i = outl;
executed 63552 times by 1 test: i = outl;
Executed by:
  • libcrypto.so.1.1
63552
220 if (i <= 0)
i <= 0Description
TRUEevaluated 54258 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 53204 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
53204-54258
221 break;
executed 54258 times by 1 test: break;
Executed by:
  • libcrypto.so.1.1
54258
222 memcpy(out, ctx->buf, i);-
223 ret += i;-
224 ctx->buf_off = i;-
225 outl -= i;-
226 out += i;-
227 }
executed 53204 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
53204
228-
229 BIO_clear_retry_flags(b);-
230 BIO_copy_next_retry(b);-
231 return ((ret == 0) ? ctx->cont : ret);
executed 235890 times by 1 test: return ((ret == 0) ? ctx->cont : ret);
Executed by:
  • libcrypto.so.1.1
(ret == 0)Description
TRUEevaluated 12356 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 223534 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
12356-235890
232}-
233-
234static int enc_write(BIO *b, const char *in, int inl)-
235{-
236 int ret = 0, n, i;-
237 BIO_ENC_CTX *ctx;-
238 BIO *next;-
239-
240 ctx = BIO_get_data(b);-
241 next = BIO_next(b);-
242 if ((ctx == NULL) || (next == NULL))
(ctx == ((void *)0) )Description
TRUEnever evaluated
FALSEevaluated 6255 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
(next == ((void *)0) )Description
TRUEnever evaluated
FALSEevaluated 6255 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-6255
243 return 0;
never executed: return 0;
0
244-
245 ret = inl;-
246-
247 BIO_clear_retry_flags(b);-
248 n = ctx->buf_len - ctx->buf_off;-
249 while (n > 0) {
n > 0Description
TRUEevaluated 313 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 6255 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
313-6255
250 i = BIO_write(next, &(ctx->buf[ctx->buf_off]), n);-
251 if (i <= 0) {
i <= 0Description
TRUEnever evaluated
FALSEevaluated 313 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-313
252 BIO_copy_next_retry(b);-
253 return i;
never executed: return i;
0
254 }-
255 ctx->buf_off += i;-
256 n -= i;-
257 }
executed 313 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
313
258 /* at this point all pending data has been written */-
259-
260 if ((in == NULL) || (inl <= 0))
(in == ((void *)0) )Description
TRUEevaluated 313 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 5942 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
(inl <= 0)Description
TRUEnever evaluated
FALSEevaluated 5942 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-5942
261 return 0;
executed 313 times by 1 test: return 0;
Executed by:
  • libcrypto.so.1.1
313
262-
263 ctx->buf_off = 0;-
264 while (inl > 0) {
inl > 0Description
TRUEevaluated 5942 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 5942 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
5942
265 n = (inl > ENC_BLOCK_SIZE) ? ENC_BLOCK_SIZE : inl;
(inl > (1024*4))Description
TRUEnever evaluated
FALSEevaluated 5942 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-5942
266 if (!EVP_CipherUpdate(ctx->cipher,
!EVP_CipherUpd... char *)in, n)Description
TRUEnever evaluated
FALSEevaluated 5942 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-5942
267 ctx->buf, &ctx->buf_len,
!EVP_CipherUpd... char *)in, n)Description
TRUEnever evaluated
FALSEevaluated 5942 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-5942
268 (const unsigned char *)in, n)) {
!EVP_CipherUpd... char *)in, n)Description
TRUEnever evaluated
FALSEevaluated 5942 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-5942
269 BIO_clear_retry_flags(b);-
270 ctx->ok = 0;-
271 return 0;
never executed: return 0;
0
272 }-
273 inl -= n;-
274 in += n;-
275-
276 ctx->buf_off = 0;-
277 n = ctx->buf_len;-
278 while (n > 0) {
n > 0Description
TRUEevaluated 5896 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 5942 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
5896-5942
279 i = BIO_write(next, &(ctx->buf[ctx->buf_off]), n);-
280 if (i <= 0) {
i <= 0Description
TRUEnever evaluated
FALSEevaluated 5896 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-5896
281 BIO_copy_next_retry(b);-
282 return (ret == inl) ? i : ret - inl;
never executed: return (ret == inl) ? i : ret - inl;
(ret == inl)Description
TRUEnever evaluated
FALSEnever evaluated
0
283 }-
284 n -= i;-
285 ctx->buf_off += i;-
286 }
executed 5896 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
5896
287 ctx->buf_len = 0;-
288 ctx->buf_off = 0;-
289 }
executed 5942 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
5942
290 BIO_copy_next_retry(b);-
291 return ret;
executed 5942 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
5942
292}-
293-
294static long enc_ctrl(BIO *b, int cmd, long num, void *ptr)-
295{-
296 BIO *dbio;-
297 BIO_ENC_CTX *ctx, *dctx;-
298 long ret = 1;-
299 int i;-
300 EVP_CIPHER_CTX **c_ctx;-
301 BIO *next;-
302-
303 ctx = BIO_get_data(b);-
304 next = BIO_next(b);-
305 if (ctx == NULL)
ctx == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 39033 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-39033
306 return 0;
never executed: return 0;
0
307-
308 switch (cmd) {-
309 case BIO_CTRL_RESET:
never executed: case 1:
0
310 ctx->ok = 1;-
311 ctx->finished = 0;-
312 if (!EVP_CipherInit_ex(ctx->cipher, NULL, NULL, NULL, NULL,
!EVP_CipherIni...(ctx->cipher))Description
TRUEnever evaluated
FALSEnever evaluated
0
313 EVP_CIPHER_CTX_encrypting(ctx->cipher)))
!EVP_CipherIni...(ctx->cipher))Description
TRUEnever evaluated
FALSEnever evaluated
0
314 return 0;
never executed: return 0;
0
315 ret = BIO_ctrl(next, cmd, num, ptr);-
316 break;
never executed: break;
0
317 case BIO_CTRL_EOF: /* More to read */
never executed: case 2:
0
318 if (ctx->cont <= 0)
ctx->cont <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
319 ret = 1;
never executed: ret = 1;
0
320 else-
321 ret = BIO_ctrl(next, cmd, num, ptr);
never executed: ret = BIO_ctrl(next, cmd, num, ptr);
0
322 break;
never executed: break;
0
323 case BIO_CTRL_WPENDING:
never executed: case 13:
0
324 ret = ctx->buf_len - ctx->buf_off;-
325 if (ret <= 0)
ret <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
326 ret = BIO_ctrl(next, cmd, num, ptr);
never executed: ret = BIO_ctrl(next, cmd, num, ptr);
0
327 break;
never executed: break;
0
328 case BIO_CTRL_PENDING: /* More to read in buffer */
never executed: case 10:
0
329 ret = ctx->buf_len - ctx->buf_off;-
330 if (ret <= 0)
ret <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
331 ret = BIO_ctrl(next, cmd, num, ptr);
never executed: ret = BIO_ctrl(next, cmd, num, ptr);
0
332 break;
never executed: break;
0
333 case BIO_CTRL_FLUSH:
executed 670 times by 1 test: case 11:
Executed by:
  • libcrypto.so.1.1
670
334 /* do a final write */-
335 again:-
336 while (ctx->buf_len != ctx->buf_off) {
ctx->buf_len != ctx->buf_offDescription
TRUEevaluated 313 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1310 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
313-1310
337 i = enc_write(b, NULL, 0);-
338 if (i < 0)
i < 0Description
TRUEnever evaluated
FALSEevaluated 313 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-313
339 return i;
never executed: return i;
0
340 }
executed 313 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
313
341-
342 if (!ctx->finished) {
!ctx->finishedDescription
TRUEevaluated 642 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 668 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
642-668
343 ctx->finished = 1;-
344 ctx->buf_off = 0;-
345 ret = EVP_CipherFinal_ex(ctx->cipher,-
346 (unsigned char *)ctx->buf,-
347 &(ctx->buf_len));-
348 ctx->ok = (int)ret;-
349 if (ret <= 0)
ret <= 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 640 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
2-640
350 break;
executed 2 times by 1 test: break;
Executed by:
  • libcrypto.so.1.1
2
351-
352 /* push out the bytes */-
353 goto again;
executed 640 times by 1 test: goto again;
Executed by:
  • libcrypto.so.1.1
640
354 }-
355-
356 /* Finally flush the underlying BIO */-
357 ret = BIO_ctrl(next, cmd, num, ptr);-
358 break;
executed 668 times by 1 test: break;
Executed by:
  • libcrypto.so.1.1
668
359 case BIO_C_GET_CIPHER_STATUS:
executed 28 times by 1 test: case 113:
Executed by:
  • libcrypto.so.1.1
28
360 ret = (long)ctx->ok;-
361 break;
executed 28 times by 1 test: break;
Executed by:
  • libcrypto.so.1.1
28
362 case BIO_C_DO_STATE_MACHINE:
never executed: case 101:
0
363 BIO_clear_retry_flags(b);-
364 ret = BIO_ctrl(next, cmd, num, ptr);-
365 BIO_copy_next_retry(b);-
366 break;
never executed: break;
0
367 case BIO_C_GET_CIPHER_CTX:
executed 658 times by 1 test: case 129:
Executed by:
  • libcrypto.so.1.1
658
368 c_ctx = (EVP_CIPHER_CTX **)ptr;-
369 *c_ctx = ctx->cipher;-
370 BIO_set_init(b, 1);-
371 break;
executed 658 times by 1 test: break;
Executed by:
  • libcrypto.so.1.1
658
372 case BIO_CTRL_DUP:
never executed: case 12:
0
373 dbio = (BIO *)ptr;-
374 dctx = BIO_get_data(dbio);-
375 dctx->cipher = EVP_CIPHER_CTX_new();-
376 if (dctx->cipher == NULL)
dctx->cipher == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
377 return 0;
never executed: return 0;
0
378 ret = EVP_CIPHER_CTX_copy(dctx->cipher, ctx->cipher);-
379 if (ret)
retDescription
TRUEnever evaluated
FALSEnever evaluated
0
380 BIO_set_init(dbio, 1);
never executed: BIO_set_init(dbio, 1);
0
381 break;
never executed: break;
0
382 default:
executed 37677 times by 1 test: default:
Executed by:
  • libcrypto.so.1.1
37677
383 ret = BIO_ctrl(next, cmd, num, ptr);-
384 break;
executed 37677 times by 1 test: break;
Executed by:
  • libcrypto.so.1.1
37677
385 }-
386 return ret;
executed 39033 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
39033
387}-
388-
389static long enc_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp)-
390{-
391 long ret = 1;-
392 BIO *next = BIO_next(b);-
393-
394 if (next == NULL)
next == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
395 return 0;
never executed: return 0;
0
396 switch (cmd) {-
397 default:
never executed: default:
0
398 ret = BIO_callback_ctrl(next, cmd, fp);-
399 break;
never executed: break;
0
400 }-
401 return ret;
never executed: return ret;
0
402}-
403-
404int BIO_set_cipher(BIO *b, const EVP_CIPHER *c, const unsigned char *k,-
405 const unsigned char *i, int e)-
406{-
407 BIO_ENC_CTX *ctx;-
408 long (*callback) (struct bio_st *, int, const char *, int, long, long);-
409-
410 ctx = BIO_get_data(b);-
411 if (ctx == NULL)
ctx == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 36936 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-36936
412 return 0;
never executed: return 0;
0
413-
414 callback = BIO_get_callback(b);-
415-
416 if ((callback != NULL) &&
(callback != ((void *)0) )Description
TRUEnever evaluated
FALSEevaluated 36936 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-36936
417 (callback(b, BIO_CB_CTRL, (const char *)c, BIO_CTRL_SET, e,
(callback(b, 0..., e, 0L) <= 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
418 0L) <= 0))
(callback(b, 0..., e, 0L) <= 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
419 return 0;
never executed: return 0;
0
420-
421 BIO_set_init(b, 1);-
422-
423 if (!EVP_CipherInit_ex(ctx->cipher, c, NULL, k, i, e))
!EVP_CipherIni...)0) , k, i, e)Description
TRUEnever evaluated
FALSEevaluated 36936 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-36936
424 return 0;
never executed: return 0;
0
425-
426 if (callback != NULL)
callback != ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 36936 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-36936
427 return callback(b, BIO_CB_CTRL, (const char *)c, BIO_CTRL_SET, e, 1L);
never executed: return callback(b, 0x06, (const char *)c, 4, e, 1L);
0
428 return 1;
executed 36936 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
36936
429}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2