Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/evp/bio_ok.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||
2 | - | |||||||||||||||||||
3 | static int ok_write(BIO *h, const char *buf, int num); | - | ||||||||||||||||||
4 | static int ok_read(BIO *h, char *buf, int size); | - | ||||||||||||||||||
5 | static long ok_ctrl(BIO *h, int cmd, long arg1, void *arg2); | - | ||||||||||||||||||
6 | static int ok_new(BIO *h); | - | ||||||||||||||||||
7 | static int ok_free(BIO *data); | - | ||||||||||||||||||
8 | static long ok_callback_ctrl(BIO *h, int cmd, BIO_info_cb *fp); | - | ||||||||||||||||||
9 | - | |||||||||||||||||||
10 | static int sig_out(BIO *b); | - | ||||||||||||||||||
11 | static int sig_in(BIO *b); | - | ||||||||||||||||||
12 | static int block_out(BIO *b); | - | ||||||||||||||||||
13 | static int block_in(BIO *b); | - | ||||||||||||||||||
14 | - | |||||||||||||||||||
15 | - | |||||||||||||||||||
16 | - | |||||||||||||||||||
17 | - | |||||||||||||||||||
18 | - | |||||||||||||||||||
19 | typedef struct ok_struct { | - | ||||||||||||||||||
20 | size_t buf_len; | - | ||||||||||||||||||
21 | size_t buf_off; | - | ||||||||||||||||||
22 | size_t buf_len_save; | - | ||||||||||||||||||
23 | size_t buf_off_save; | - | ||||||||||||||||||
24 | int cont; | - | ||||||||||||||||||
25 | int finished; | - | ||||||||||||||||||
26 | EVP_MD_CTX *md; | - | ||||||||||||||||||
27 | int blockout; | - | ||||||||||||||||||
28 | int sigio; | - | ||||||||||||||||||
29 | unsigned char buf[((1024*4)+ 4 + 3*64)]; | - | ||||||||||||||||||
30 | } BIO_OK_CTX; | - | ||||||||||||||||||
31 | - | |||||||||||||||||||
32 | static const BIO_METHOD methods_ok = { | - | ||||||||||||||||||
33 | (10|0x0200), | - | ||||||||||||||||||
34 | "reliable", | - | ||||||||||||||||||
35 | - | |||||||||||||||||||
36 | bwrite_conv, | - | ||||||||||||||||||
37 | ok_write, | - | ||||||||||||||||||
38 | - | |||||||||||||||||||
39 | bread_conv, | - | ||||||||||||||||||
40 | ok_read, | - | ||||||||||||||||||
41 | - | |||||||||||||||||||
42 | ((void *)0) | - | ||||||||||||||||||
43 | , | - | ||||||||||||||||||
44 | - | |||||||||||||||||||
45 | ((void *)0) | - | ||||||||||||||||||
46 | , | - | ||||||||||||||||||
47 | ok_ctrl, | - | ||||||||||||||||||
48 | ok_new, | - | ||||||||||||||||||
49 | ok_free, | - | ||||||||||||||||||
50 | ok_callback_ctrl, | - | ||||||||||||||||||
51 | }; | - | ||||||||||||||||||
52 | - | |||||||||||||||||||
53 | const BIO_METHOD *BIO_f_reliable(void) | - | ||||||||||||||||||
54 | { | - | ||||||||||||||||||
55 | return never executed: &methods_ok;return &methods_ok; never executed: return &methods_ok; | 0 | ||||||||||||||||||
56 | } | - | ||||||||||||||||||
57 | - | |||||||||||||||||||
58 | static int ok_new(BIO *bi) | - | ||||||||||||||||||
59 | { | - | ||||||||||||||||||
60 | BIO_OK_CTX *ctx; | - | ||||||||||||||||||
61 | - | |||||||||||||||||||
62 | if ((
| 0 | ||||||||||||||||||
63 | ((void *)0)
| 0 | ||||||||||||||||||
64 | ) { | - | ||||||||||||||||||
65 | ERR_put_error(6,(200),((1|64)),__FILE__,137); | - | ||||||||||||||||||
66 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
67 | } | - | ||||||||||||||||||
68 | - | |||||||||||||||||||
69 | ctx->cont = 1; | - | ||||||||||||||||||
70 | ctx->sigio = 1; | - | ||||||||||||||||||
71 | ctx->md = EVP_MD_CTX_new(); | - | ||||||||||||||||||
72 | if (ctx->md ==
| 0 | ||||||||||||||||||
73 | ((void *)0)
| 0 | ||||||||||||||||||
74 | ) { | - | ||||||||||||||||||
75 | CRYPTO_free(ctx, __FILE__, 145); | - | ||||||||||||||||||
76 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
77 | } | - | ||||||||||||||||||
78 | BIO_set_init(bi, 0); | - | ||||||||||||||||||
79 | BIO_set_data(bi, ctx); | - | ||||||||||||||||||
80 | - | |||||||||||||||||||
81 | return never executed: 1;return 1; never executed: return 1; | 0 | ||||||||||||||||||
82 | } | - | ||||||||||||||||||
83 | - | |||||||||||||||||||
84 | static int ok_free(BIO *a) | - | ||||||||||||||||||
85 | { | - | ||||||||||||||||||
86 | BIO_OK_CTX *ctx; | - | ||||||||||||||||||
87 | - | |||||||||||||||||||
88 | if (a ==
| 0 | ||||||||||||||||||
89 | ((void *)0)
| 0 | ||||||||||||||||||
90 | ) | - | ||||||||||||||||||
91 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
92 | - | |||||||||||||||||||
93 | ctx = BIO_get_data(a); | - | ||||||||||||||||||
94 | - | |||||||||||||||||||
95 | EVP_MD_CTX_free(ctx->md); | - | ||||||||||||||||||
96 | CRYPTO_clear_free(ctx, sizeof(BIO_OK_CTX), __FILE__, 164); | - | ||||||||||||||||||
97 | BIO_set_data(a, | - | ||||||||||||||||||
98 | ((void *)0) | - | ||||||||||||||||||
99 | ); | - | ||||||||||||||||||
100 | BIO_set_init(a, 0); | - | ||||||||||||||||||
101 | - | |||||||||||||||||||
102 | return never executed: 1;return 1; never executed: return 1; | 0 | ||||||||||||||||||
103 | } | - | ||||||||||||||||||
104 | - | |||||||||||||||||||
105 | static int ok_read(BIO *b, char *out, int outl) | - | ||||||||||||||||||
106 | { | - | ||||||||||||||||||
107 | int ret = 0, i, n; | - | ||||||||||||||||||
108 | BIO_OK_CTX *ctx; | - | ||||||||||||||||||
109 | BIO *next; | - | ||||||||||||||||||
110 | - | |||||||||||||||||||
111 | if (out ==
| 0 | ||||||||||||||||||
112 | ((void *)0)
| 0 | ||||||||||||||||||
113 | ) | - | ||||||||||||||||||
114 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
115 | - | |||||||||||||||||||
116 | ctx = BIO_get_data(b); | - | ||||||||||||||||||
117 | next = BIO_next(b); | - | ||||||||||||||||||
118 | - | |||||||||||||||||||
119 | if ((
| 0 | ||||||||||||||||||
120 | ((void *)0)
| 0 | ||||||||||||||||||
121 | )
| 0 | ||||||||||||||||||
122 | ((void *)0)
| 0 | ||||||||||||||||||
123 | )
| 0 | ||||||||||||||||||
124 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
125 | - | |||||||||||||||||||
126 | while (outl > 0
| 0 | ||||||||||||||||||
127 | - | |||||||||||||||||||
128 | - | |||||||||||||||||||
129 | if (ctx->blockout
| 0 | ||||||||||||||||||
130 | i = ctx->buf_len - ctx->buf_off; | - | ||||||||||||||||||
131 | if (i > outl
| 0 | ||||||||||||||||||
132 | i = outl; never executed: i = outl; | 0 | ||||||||||||||||||
133 | memcpy(out, &(ctx->buf[ctx->buf_off]), i); | - | ||||||||||||||||||
134 | ret += i; | - | ||||||||||||||||||
135 | out += i; | - | ||||||||||||||||||
136 | outl -= i; | - | ||||||||||||||||||
137 | ctx->buf_off += i; | - | ||||||||||||||||||
138 | - | |||||||||||||||||||
139 | - | |||||||||||||||||||
140 | if (ctx->buf_len == ctx->buf_off
| 0 | ||||||||||||||||||
141 | ctx->buf_off = 0; | - | ||||||||||||||||||
142 | - | |||||||||||||||||||
143 | - | |||||||||||||||||||
144 | - | |||||||||||||||||||
145 | - | |||||||||||||||||||
146 | if (ctx->buf_len_save - ctx->buf_off_save > 0
| 0 | ||||||||||||||||||
147 | ctx->buf_len = ctx->buf_len_save - ctx->buf_off_save; | - | ||||||||||||||||||
148 | memmove(ctx->buf, &(ctx->buf[ctx->buf_off_save]), | - | ||||||||||||||||||
149 | ctx->buf_len); | - | ||||||||||||||||||
150 | } never executed: else {end of block | 0 | ||||||||||||||||||
151 | ctx->buf_len = 0; | - | ||||||||||||||||||
152 | } never executed: end of block | 0 | ||||||||||||||||||
153 | ctx->blockout = 0; | - | ||||||||||||||||||
154 | } never executed: end of block | 0 | ||||||||||||||||||
155 | } never executed: end of block | 0 | ||||||||||||||||||
156 | - | |||||||||||||||||||
157 | - | |||||||||||||||||||
158 | if (outl == 0
| 0 | ||||||||||||||||||
159 | break; never executed: break; | 0 | ||||||||||||||||||
160 | - | |||||||||||||||||||
161 | - | |||||||||||||||||||
162 | n = ((1024*4)+ 4 + 3*64) - ctx->buf_len; | - | ||||||||||||||||||
163 | i = BIO_read(next, &(ctx->buf[ctx->buf_len]), n); | - | ||||||||||||||||||
164 | - | |||||||||||||||||||
165 | if (i <= 0
| 0 | ||||||||||||||||||
166 | break; never executed: break; | 0 | ||||||||||||||||||
167 | - | |||||||||||||||||||
168 | ctx->buf_len += i; | - | ||||||||||||||||||
169 | - | |||||||||||||||||||
170 | - | |||||||||||||||||||
171 | if (ctx->sigio == 1
| 0 | ||||||||||||||||||
172 | if (!sig_in(b)
| 0 | ||||||||||||||||||
173 | BIO_clear_flags(b, ((0x01|0x02|0x04)|0x08)); | - | ||||||||||||||||||
174 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
175 | } | - | ||||||||||||||||||
176 | } never executed: end of block | 0 | ||||||||||||||||||
177 | - | |||||||||||||||||||
178 | - | |||||||||||||||||||
179 | if (ctx->sigio == 0
| 0 | ||||||||||||||||||
180 | if (!block_in(b)
| 0 | ||||||||||||||||||
181 | BIO_clear_flags(b, ((0x01|0x02|0x04)|0x08)); | - | ||||||||||||||||||
182 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
183 | } | - | ||||||||||||||||||
184 | } never executed: end of block | 0 | ||||||||||||||||||
185 | - | |||||||||||||||||||
186 | - | |||||||||||||||||||
187 | if (ctx->cont <= 0
| 0 | ||||||||||||||||||
188 | break; never executed: break; | 0 | ||||||||||||||||||
189 | - | |||||||||||||||||||
190 | } never executed: end of block | 0 | ||||||||||||||||||
191 | - | |||||||||||||||||||
192 | BIO_clear_flags(b, ((0x01|0x02|0x04)|0x08)); | - | ||||||||||||||||||
193 | BIO_copy_next_retry(b); | - | ||||||||||||||||||
194 | return never executed: ret;return ret; never executed: return ret; | 0 | ||||||||||||||||||
195 | } | - | ||||||||||||||||||
196 | - | |||||||||||||||||||
197 | static int ok_write(BIO *b, const char *in, int inl) | - | ||||||||||||||||||
198 | { | - | ||||||||||||||||||
199 | int ret = 0, n, i; | - | ||||||||||||||||||
200 | BIO_OK_CTX *ctx; | - | ||||||||||||||||||
201 | BIO *next; | - | ||||||||||||||||||
202 | - | |||||||||||||||||||
203 | if (inl <= 0
| 0 | ||||||||||||||||||
204 | return never executed: inl;return inl; never executed: return inl; | 0 | ||||||||||||||||||
205 | - | |||||||||||||||||||
206 | ctx = BIO_get_data(b); | - | ||||||||||||||||||
207 | next = BIO_next(b); | - | ||||||||||||||||||
208 | ret = inl; | - | ||||||||||||||||||
209 | - | |||||||||||||||||||
210 | if ((
| 0 | ||||||||||||||||||
211 | ((void *)0)
| 0 | ||||||||||||||||||
212 | )
| 0 | ||||||||||||||||||
213 | ((void *)0)
| 0 | ||||||||||||||||||
214 | )
| 0 | ||||||||||||||||||
215 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
216 | - | |||||||||||||||||||
217 | if (ctx->sigio
| 0 | ||||||||||||||||||
218 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
219 | - | |||||||||||||||||||
220 | do { | - | ||||||||||||||||||
221 | BIO_clear_flags(b, ((0x01|0x02|0x04)|0x08)); | - | ||||||||||||||||||
222 | n = ctx->buf_len - ctx->buf_off; | - | ||||||||||||||||||
223 | while (ctx->blockout
| 0 | ||||||||||||||||||
224 | i = BIO_write(next, &(ctx->buf[ctx->buf_off]), n); | - | ||||||||||||||||||
225 | if (i <= 0
| 0 | ||||||||||||||||||
226 | BIO_copy_next_retry(b); | - | ||||||||||||||||||
227 | if (!BIO_test_flags(b, 0x08)
| 0 | ||||||||||||||||||
228 | ctx->cont = 0; never executed: ctx->cont = 0; | 0 | ||||||||||||||||||
229 | return never executed: i;return i; never executed: return i; | 0 | ||||||||||||||||||
230 | } | - | ||||||||||||||||||
231 | ctx->buf_off += i; | - | ||||||||||||||||||
232 | n -= i; | - | ||||||||||||||||||
233 | } never executed: end of block | 0 | ||||||||||||||||||
234 | - | |||||||||||||||||||
235 | - | |||||||||||||||||||
236 | ctx->blockout = 0; | - | ||||||||||||||||||
237 | if (ctx->buf_len == ctx->buf_off
| 0 | ||||||||||||||||||
238 | ctx->buf_len = 4; | - | ||||||||||||||||||
239 | ctx->buf_off = 0; | - | ||||||||||||||||||
240 | } never executed: end of block | 0 | ||||||||||||||||||
241 | - | |||||||||||||||||||
242 | if ((
| 0 | ||||||||||||||||||
243 | ((void *)0)
| 0 | ||||||||||||||||||
244 | )
| 0 | ||||||||||||||||||
245 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
246 | - | |||||||||||||||||||
247 | n = (
| 0 | ||||||||||||||||||
248 | (int)((1024*4) + 4 - ctx->buf_len) : inl; | - | ||||||||||||||||||
249 | - | |||||||||||||||||||
250 | memcpy(&ctx->buf[ctx->buf_len], in, n); | - | ||||||||||||||||||
251 | ctx->buf_len += n; | - | ||||||||||||||||||
252 | inl -= n; | - | ||||||||||||||||||
253 | in += n; | - | ||||||||||||||||||
254 | - | |||||||||||||||||||
255 | if (ctx->buf_len >= (1024*4) + 4
| 0 | ||||||||||||||||||
256 | if (!block_out(b)
| 0 | ||||||||||||||||||
257 | BIO_clear_flags(b, ((0x01|0x02|0x04)|0x08)); | - | ||||||||||||||||||
258 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
259 | } | - | ||||||||||||||||||
260 | } never executed: end of block | 0 | ||||||||||||||||||
261 | } never executed: while (inl > 0end of block
| 0 | ||||||||||||||||||
262 | - | |||||||||||||||||||
263 | BIO_clear_flags(b, ((0x01|0x02|0x04)|0x08)); | - | ||||||||||||||||||
264 | BIO_copy_next_retry(b); | - | ||||||||||||||||||
265 | return never executed: ret;return ret; never executed: return ret; | 0 | ||||||||||||||||||
266 | } | - | ||||||||||||||||||
267 | - | |||||||||||||||||||
268 | static long ok_ctrl(BIO *b, int cmd, long num, void *ptr) | - | ||||||||||||||||||
269 | { | - | ||||||||||||||||||
270 | BIO_OK_CTX *ctx; | - | ||||||||||||||||||
271 | EVP_MD *md; | - | ||||||||||||||||||
272 | const EVP_MD **ppmd; | - | ||||||||||||||||||
273 | long ret = 1; | - | ||||||||||||||||||
274 | int i; | - | ||||||||||||||||||
275 | BIO *next; | - | ||||||||||||||||||
276 | - | |||||||||||||||||||
277 | ctx = BIO_get_data(b); | - | ||||||||||||||||||
278 | next = BIO_next(b); | - | ||||||||||||||||||
279 | - | |||||||||||||||||||
280 | switch (cmd) { | - | ||||||||||||||||||
281 | case never executed: 1:case 1: never executed: case 1: | 0 | ||||||||||||||||||
282 | ctx->buf_len = 0; | - | ||||||||||||||||||
283 | ctx->buf_off = 0; | - | ||||||||||||||||||
284 | ctx->buf_len_save = 0; | - | ||||||||||||||||||
285 | ctx->buf_off_save = 0; | - | ||||||||||||||||||
286 | ctx->cont = 1; | - | ||||||||||||||||||
287 | ctx->finished = 0; | - | ||||||||||||||||||
288 | ctx->blockout = 0; | - | ||||||||||||||||||
289 | ctx->sigio = 1; | - | ||||||||||||||||||
290 | ret = BIO_ctrl(next, cmd, num, ptr); | - | ||||||||||||||||||
291 | break; never executed: break; | 0 | ||||||||||||||||||
292 | case never executed: 2:case 2: never executed: case 2: | 0 | ||||||||||||||||||
293 | if (ctx->cont <= 0
| 0 | ||||||||||||||||||
294 | ret = 1; never executed: ret = 1; | 0 | ||||||||||||||||||
295 | else | - | ||||||||||||||||||
296 | ret = BIO_ctrl(next, cmd, num, ptr); never executed: ret = BIO_ctrl(next, cmd, num, ptr); | 0 | ||||||||||||||||||
297 | break; never executed: break; | 0 | ||||||||||||||||||
298 | case never executed: 10:case 10: never executed: case 10: | 0 | ||||||||||||||||||
299 | case never executed: 13:case 13: never executed: case 13: | 0 | ||||||||||||||||||
300 | ret = ctx->blockout
| 0 | ||||||||||||||||||
301 | if (ret <= 0
| 0 | ||||||||||||||||||
302 | ret = BIO_ctrl(next, cmd, num, ptr); never executed: ret = BIO_ctrl(next, cmd, num, ptr); | 0 | ||||||||||||||||||
303 | break; never executed: break; | 0 | ||||||||||||||||||
304 | case never executed: 11:case 11: never executed: case 11: | 0 | ||||||||||||||||||
305 | - | |||||||||||||||||||
306 | if (ctx->blockout == 0
| 0 | ||||||||||||||||||
307 | if (!block_out(b)
| 0 | ||||||||||||||||||
308 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
309 | - | |||||||||||||||||||
310 | while (ctx->blockout
| 0 | ||||||||||||||||||
311 | i = ok_write(b, | - | ||||||||||||||||||
312 | ((void *)0) | - | ||||||||||||||||||
313 | , 0); | - | ||||||||||||||||||
314 | if (i < 0
| 0 | ||||||||||||||||||
315 | ret = i; | - | ||||||||||||||||||
316 | break; never executed: break; | 0 | ||||||||||||||||||
317 | } | - | ||||||||||||||||||
318 | } never executed: end of block | 0 | ||||||||||||||||||
319 | - | |||||||||||||||||||
320 | ctx->finished = 1; | - | ||||||||||||||||||
321 | ctx->buf_off = ctx->buf_len = 0; | - | ||||||||||||||||||
322 | ctx->cont = (int)ret; | - | ||||||||||||||||||
323 | - | |||||||||||||||||||
324 | - | |||||||||||||||||||
325 | ret = BIO_ctrl(next, cmd, num, ptr); | - | ||||||||||||||||||
326 | break; never executed: break; | 0 | ||||||||||||||||||
327 | case never executed: 101:case 101: never executed: case 101: | 0 | ||||||||||||||||||
328 | BIO_clear_flags(b, ((0x01|0x02|0x04)|0x08)); | - | ||||||||||||||||||
329 | ret = BIO_ctrl(next, cmd, num, ptr); | - | ||||||||||||||||||
330 | BIO_copy_next_retry(b); | - | ||||||||||||||||||
331 | break; never executed: break; | 0 | ||||||||||||||||||
332 | case never executed: 3:case 3: never executed: case 3: | 0 | ||||||||||||||||||
333 | ret = (long)ctx->cont; | - | ||||||||||||||||||
334 | break; never executed: break; | 0 | ||||||||||||||||||
335 | case never executed: 111:case 111: never executed: case 111: | 0 | ||||||||||||||||||
336 | md = ptr; | - | ||||||||||||||||||
337 | if (!EVP_DigestInit_ex(ctx->md, md,
| 0 | ||||||||||||||||||
338 | ((void *)0)
| 0 | ||||||||||||||||||
339 | )
| 0 | ||||||||||||||||||
340 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
341 | BIO_set_init(b, 1); | - | ||||||||||||||||||
342 | break; never executed: break; | 0 | ||||||||||||||||||
343 | case never executed: 112:case 112: never executed: case 112: | 0 | ||||||||||||||||||
344 | if (BIO_get_init(b)
| 0 | ||||||||||||||||||
345 | ppmd = ptr; | - | ||||||||||||||||||
346 | *ppmd = EVP_MD_CTX_md(ctx->md); | - | ||||||||||||||||||
347 | } never executed: elseend of block | 0 | ||||||||||||||||||
348 | ret = 0; never executed: ret = 0; | 0 | ||||||||||||||||||
349 | break; never executed: break; | 0 | ||||||||||||||||||
350 | default never executed: :default: never executed: default: | 0 | ||||||||||||||||||
351 | ret = BIO_ctrl(next, cmd, num, ptr); | - | ||||||||||||||||||
352 | break; never executed: break; | 0 | ||||||||||||||||||
353 | } | - | ||||||||||||||||||
354 | return never executed: ret;return ret; never executed: return ret; | 0 | ||||||||||||||||||
355 | } | - | ||||||||||||||||||
356 | - | |||||||||||||||||||
357 | static long ok_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp) | - | ||||||||||||||||||
358 | { | - | ||||||||||||||||||
359 | long ret = 1; | - | ||||||||||||||||||
360 | BIO *next; | - | ||||||||||||||||||
361 | - | |||||||||||||||||||
362 | next = BIO_next(b); | - | ||||||||||||||||||
363 | - | |||||||||||||||||||
364 | if (next ==
| 0 | ||||||||||||||||||
365 | ((void *)0)
| 0 | ||||||||||||||||||
366 | ) | - | ||||||||||||||||||
367 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
368 | - | |||||||||||||||||||
369 | switch (cmd) { | - | ||||||||||||||||||
370 | default never executed: :default: never executed: default: | 0 | ||||||||||||||||||
371 | ret = BIO_callback_ctrl(next, cmd, fp); | - | ||||||||||||||||||
372 | break; never executed: break; | 0 | ||||||||||||||||||
373 | } | - | ||||||||||||||||||
374 | - | |||||||||||||||||||
375 | return never executed: ret;return ret; never executed: return ret; | 0 | ||||||||||||||||||
376 | } | - | ||||||||||||||||||
377 | - | |||||||||||||||||||
378 | static void longswap(void *_ptr, size_t len) | - | ||||||||||||||||||
379 | { | - | ||||||||||||||||||
380 | const union { | - | ||||||||||||||||||
381 | long one; | - | ||||||||||||||||||
382 | char little; | - | ||||||||||||||||||
383 | } is_endian = { | - | ||||||||||||||||||
384 | 1 | - | ||||||||||||||||||
385 | }; | - | ||||||||||||||||||
386 | - | |||||||||||||||||||
387 | if (is_endian.little
| 0 | ||||||||||||||||||
388 | size_t i; | - | ||||||||||||||||||
389 | unsigned char *p = _ptr, c; | - | ||||||||||||||||||
390 | - | |||||||||||||||||||
391 | for (i = 0; i < len
| 0 | ||||||||||||||||||
392 | c = p[0], p[0] = p[3], p[3] = c; | - | ||||||||||||||||||
393 | c = p[1], p[1] = p[2], p[2] = c; | - | ||||||||||||||||||
394 | } never executed: end of block | 0 | ||||||||||||||||||
395 | } never executed: end of block | 0 | ||||||||||||||||||
396 | } never executed: end of block | 0 | ||||||||||||||||||
397 | - | |||||||||||||||||||
398 | static int sig_out(BIO *b) | - | ||||||||||||||||||
399 | { | - | ||||||||||||||||||
400 | BIO_OK_CTX *ctx; | - | ||||||||||||||||||
401 | EVP_MD_CTX *md; | - | ||||||||||||||||||
402 | const EVP_MD *digest; | - | ||||||||||||||||||
403 | int md_size; | - | ||||||||||||||||||
404 | void *md_data; | - | ||||||||||||||||||
405 | - | |||||||||||||||||||
406 | ctx = BIO_get_data(b); | - | ||||||||||||||||||
407 | md = ctx->md; | - | ||||||||||||||||||
408 | digest = EVP_MD_CTX_md(md); | - | ||||||||||||||||||
409 | md_size = EVP_MD_size(digest); | - | ||||||||||||||||||
410 | md_data = EVP_MD_CTX_md_data(md); | - | ||||||||||||||||||
411 | - | |||||||||||||||||||
412 | if (ctx->buf_len + 2 * md_size > (1024*4)
| 0 | ||||||||||||||||||
413 | return never executed: 1;return 1; never executed: return 1; | 0 | ||||||||||||||||||
414 | - | |||||||||||||||||||
415 | if (!EVP_DigestInit_ex(md, digest,
| 0 | ||||||||||||||||||
416 | ((void *)0)
| 0 | ||||||||||||||||||
417 | )
| 0 | ||||||||||||||||||
418 | goto never executed: berr;goto berr; never executed: goto berr; | 0 | ||||||||||||||||||
419 | - | |||||||||||||||||||
420 | - | |||||||||||||||||||
421 | - | |||||||||||||||||||
422 | - | |||||||||||||||||||
423 | if (RAND_bytes(md_data, md_size) <= 0
| 0 | ||||||||||||||||||
424 | goto never executed: berr;goto berr; never executed: goto berr; | 0 | ||||||||||||||||||
425 | memcpy(&(ctx->buf[ctx->buf_len]), md_data, md_size); | - | ||||||||||||||||||
426 | longswap(&(ctx->buf[ctx->buf_len]), md_size); | - | ||||||||||||||||||
427 | ctx->buf_len += md_size; | - | ||||||||||||||||||
428 | - | |||||||||||||||||||
429 | if (!EVP_DigestUpdate(md, "The quick brown fox jumped over the lazy dog's back.", strlen("The quick brown fox jumped over the lazy dog's back."))
| 0 | ||||||||||||||||||
430 | goto never executed: berr;goto berr; never executed: goto berr; | 0 | ||||||||||||||||||
431 | if (!EVP_DigestFinal_ex(md, &(ctx->buf[ctx->buf_len]),
| 0 | ||||||||||||||||||
432 | ((void *)0)
| 0 | ||||||||||||||||||
433 | )
| 0 | ||||||||||||||||||
434 | goto never executed: berr;goto berr; never executed: goto berr; | 0 | ||||||||||||||||||
435 | ctx->buf_len += md_size; | - | ||||||||||||||||||
436 | ctx->blockout = 1; | - | ||||||||||||||||||
437 | ctx->sigio = 0; | - | ||||||||||||||||||
438 | return never executed: 1;return 1; never executed: return 1; | 0 | ||||||||||||||||||
439 | berr: | - | ||||||||||||||||||
440 | BIO_clear_flags(b, ((0x01|0x02|0x04)|0x08)); | - | ||||||||||||||||||
441 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
442 | } | - | ||||||||||||||||||
443 | - | |||||||||||||||||||
444 | static int sig_in(BIO *b) | - | ||||||||||||||||||
445 | { | - | ||||||||||||||||||
446 | BIO_OK_CTX *ctx; | - | ||||||||||||||||||
447 | EVP_MD_CTX *md; | - | ||||||||||||||||||
448 | unsigned char tmp[64]; | - | ||||||||||||||||||
449 | int ret = 0; | - | ||||||||||||||||||
450 | const EVP_MD *digest; | - | ||||||||||||||||||
451 | int md_size; | - | ||||||||||||||||||
452 | void *md_data; | - | ||||||||||||||||||
453 | - | |||||||||||||||||||
454 | ctx = BIO_get_data(b); | - | ||||||||||||||||||
455 | md = ctx->md; | - | ||||||||||||||||||
456 | digest = EVP_MD_CTX_md(md); | - | ||||||||||||||||||
457 | md_size = EVP_MD_size(digest); | - | ||||||||||||||||||
458 | md_data = EVP_MD_CTX_md_data(md); | - | ||||||||||||||||||
459 | - | |||||||||||||||||||
460 | if ((
| 0 | ||||||||||||||||||
461 | return never executed: 1;return 1; never executed: return 1; | 0 | ||||||||||||||||||
462 | - | |||||||||||||||||||
463 | if (!EVP_DigestInit_ex(md, digest,
| 0 | ||||||||||||||||||
464 | ((void *)0)
| 0 | ||||||||||||||||||
465 | )
| 0 | ||||||||||||||||||
466 | goto never executed: berr;goto berr; never executed: goto berr; | 0 | ||||||||||||||||||
467 | memcpy(md_data, &(ctx->buf[ctx->buf_off]), md_size); | - | ||||||||||||||||||
468 | longswap(md_data, md_size); | - | ||||||||||||||||||
469 | ctx->buf_off += md_size; | - | ||||||||||||||||||
470 | - | |||||||||||||||||||
471 | if (!EVP_DigestUpdate(md, "The quick brown fox jumped over the lazy dog's back.", strlen("The quick brown fox jumped over the lazy dog's back."))
| 0 | ||||||||||||||||||
472 | goto never executed: berr;goto berr; never executed: goto berr; | 0 | ||||||||||||||||||
473 | if (!EVP_DigestFinal_ex(md, tmp,
| 0 | ||||||||||||||||||
474 | ((void *)0)
| 0 | ||||||||||||||||||
475 | )
| 0 | ||||||||||||||||||
476 | goto never executed: berr;goto berr; never executed: goto berr; | 0 | ||||||||||||||||||
477 | ret = memcmp(&(ctx->buf[ctx->buf_off]), tmp, md_size) == 0; | - | ||||||||||||||||||
478 | ctx->buf_off += md_size; | - | ||||||||||||||||||
479 | if (ret == 1
| 0 | ||||||||||||||||||
480 | ctx->sigio = 0; | - | ||||||||||||||||||
481 | if (ctx->buf_len != ctx->buf_off
| 0 | ||||||||||||||||||
482 | memmove(ctx->buf, &(ctx->buf[ctx->buf_off]), | - | ||||||||||||||||||
483 | ctx->buf_len - ctx->buf_off); | - | ||||||||||||||||||
484 | } never executed: end of block | 0 | ||||||||||||||||||
485 | ctx->buf_len -= ctx->buf_off; | - | ||||||||||||||||||
486 | ctx->buf_off = 0; | - | ||||||||||||||||||
487 | } never executed: else {end of block | 0 | ||||||||||||||||||
488 | ctx->cont = 0; | - | ||||||||||||||||||
489 | } never executed: end of block | 0 | ||||||||||||||||||
490 | return never executed: 1;return 1; never executed: return 1; | 0 | ||||||||||||||||||
491 | berr: | - | ||||||||||||||||||
492 | BIO_clear_flags(b, ((0x01|0x02|0x04)|0x08)); | - | ||||||||||||||||||
493 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
494 | } | - | ||||||||||||||||||
495 | - | |||||||||||||||||||
496 | static int block_out(BIO *b) | - | ||||||||||||||||||
497 | { | - | ||||||||||||||||||
498 | BIO_OK_CTX *ctx; | - | ||||||||||||||||||
499 | EVP_MD_CTX *md; | - | ||||||||||||||||||
500 | unsigned long tl; | - | ||||||||||||||||||
501 | const EVP_MD *digest; | - | ||||||||||||||||||
502 | int md_size; | - | ||||||||||||||||||
503 | - | |||||||||||||||||||
504 | ctx = BIO_get_data(b); | - | ||||||||||||||||||
505 | md = ctx->md; | - | ||||||||||||||||||
506 | digest = EVP_MD_CTX_md(md); | - | ||||||||||||||||||
507 | md_size = EVP_MD_size(digest); | - | ||||||||||||||||||
508 | - | |||||||||||||||||||
509 | tl = ctx->buf_len - 4; | - | ||||||||||||||||||
510 | ctx->buf[0] = (unsigned char)(tl >> 24); | - | ||||||||||||||||||
511 | ctx->buf[1] = (unsigned char)(tl >> 16); | - | ||||||||||||||||||
512 | ctx->buf[2] = (unsigned char)(tl >> 8); | - | ||||||||||||||||||
513 | ctx->buf[3] = (unsigned char)(tl); | - | ||||||||||||||||||
514 | if (!EVP_DigestUpdate(md,
| 0 | ||||||||||||||||||
515 | (unsigned char *)&(ctx->buf[4]), tl)
| 0 | ||||||||||||||||||
516 | goto never executed: berr;goto berr; never executed: goto berr; | 0 | ||||||||||||||||||
517 | if (!EVP_DigestFinal_ex(md, &(ctx->buf[ctx->buf_len]),
| 0 | ||||||||||||||||||
518 | ((void *)0)
| 0 | ||||||||||||||||||
519 | )
| 0 | ||||||||||||||||||
520 | goto never executed: berr;goto berr; never executed: goto berr; | 0 | ||||||||||||||||||
521 | ctx->buf_len += md_size; | - | ||||||||||||||||||
522 | ctx->blockout = 1; | - | ||||||||||||||||||
523 | return never executed: 1;return 1; never executed: return 1; | 0 | ||||||||||||||||||
524 | berr: | - | ||||||||||||||||||
525 | BIO_clear_flags(b, ((0x01|0x02|0x04)|0x08)); | - | ||||||||||||||||||
526 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
527 | } | - | ||||||||||||||||||
528 | - | |||||||||||||||||||
529 | static int block_in(BIO *b) | - | ||||||||||||||||||
530 | { | - | ||||||||||||||||||
531 | BIO_OK_CTX *ctx; | - | ||||||||||||||||||
532 | EVP_MD_CTX *md; | - | ||||||||||||||||||
533 | unsigned long tl = 0; | - | ||||||||||||||||||
534 | unsigned char tmp[64]; | - | ||||||||||||||||||
535 | int md_size; | - | ||||||||||||||||||
536 | - | |||||||||||||||||||
537 | ctx = BIO_get_data(b); | - | ||||||||||||||||||
538 | md = ctx->md; | - | ||||||||||||||||||
539 | md_size = EVP_MD_size(EVP_MD_CTX_md(md)); | - | ||||||||||||||||||
540 | - | |||||||||||||||||||
541 | - | |||||||||||||||||||
542 | ((void) (0)) | - | ||||||||||||||||||
543 | ; | - | ||||||||||||||||||
544 | tl = ctx->buf[0]; | - | ||||||||||||||||||
545 | tl <<= 8; | - | ||||||||||||||||||
546 | tl |= ctx->buf[1]; | - | ||||||||||||||||||
547 | tl <<= 8; | - | ||||||||||||||||||
548 | tl |= ctx->buf[2]; | - | ||||||||||||||||||
549 | tl <<= 8; | - | ||||||||||||||||||
550 | tl |= ctx->buf[3]; | - | ||||||||||||||||||
551 | - | |||||||||||||||||||
552 | if (ctx->buf_len < tl + 4 + md_size
| 0 | ||||||||||||||||||
553 | return never executed: 1;return 1; never executed: return 1; | 0 | ||||||||||||||||||
554 | - | |||||||||||||||||||
555 | if (!EVP_DigestUpdate(md,
| 0 | ||||||||||||||||||
556 | (unsigned char *)&(ctx->buf[4]), tl)
| 0 | ||||||||||||||||||
557 | goto never executed: berr;goto berr; never executed: goto berr; | 0 | ||||||||||||||||||
558 | if (!EVP_DigestFinal_ex(md, tmp,
| 0 | ||||||||||||||||||
559 | ((void *)0)
| 0 | ||||||||||||||||||
560 | )
| 0 | ||||||||||||||||||
561 | goto never executed: berr;goto berr; never executed: goto berr; | 0 | ||||||||||||||||||
562 | if (memcmp(&(ctx->buf[tl + 4]), tmp, md_size) == 0
| 0 | ||||||||||||||||||
563 | - | |||||||||||||||||||
564 | ctx->buf_off_save = tl + 4 + md_size; | - | ||||||||||||||||||
565 | ctx->buf_len_save = ctx->buf_len; | - | ||||||||||||||||||
566 | ctx->buf_off = 4; | - | ||||||||||||||||||
567 | ctx->buf_len = tl + 4; | - | ||||||||||||||||||
568 | ctx->blockout = 1; | - | ||||||||||||||||||
569 | } never executed: else {end of block | 0 | ||||||||||||||||||
570 | ctx->cont = 0; | - | ||||||||||||||||||
571 | } never executed: end of block | 0 | ||||||||||||||||||
572 | return never executed: 1;return 1; never executed: return 1; | 0 | ||||||||||||||||||
573 | berr: | - | ||||||||||||||||||
574 | BIO_clear_flags(b, ((0x01|0x02|0x04)|0x08)); | - | ||||||||||||||||||
575 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
576 | } | - | ||||||||||||||||||
Switch to Source code | Preprocessed file |