Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/evp/bio_md.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||
2 | - | |||||||||||||||||||
3 | - | |||||||||||||||||||
4 | - | |||||||||||||||||||
5 | - | |||||||||||||||||||
6 | static int md_write(BIO *h, char const *buf, int num); | - | ||||||||||||||||||
7 | static int md_read(BIO *h, char *buf, int size); | - | ||||||||||||||||||
8 | - | |||||||||||||||||||
9 | static int md_gets(BIO *h, char *str, int size); | - | ||||||||||||||||||
10 | static long md_ctrl(BIO *h, int cmd, long arg1, void *arg2); | - | ||||||||||||||||||
11 | static int md_new(BIO *h); | - | ||||||||||||||||||
12 | static int md_free(BIO *data); | - | ||||||||||||||||||
13 | static long md_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp); | - | ||||||||||||||||||
14 | - | |||||||||||||||||||
15 | static const BIO_METHOD methods_md = { | - | ||||||||||||||||||
16 | .type = (8|0x0200), | - | ||||||||||||||||||
17 | .name = "message digest", | - | ||||||||||||||||||
18 | .bwrite = md_write, | - | ||||||||||||||||||
19 | .bread = md_read, | - | ||||||||||||||||||
20 | .bgets = md_gets, | - | ||||||||||||||||||
21 | .ctrl = md_ctrl, | - | ||||||||||||||||||
22 | .create = md_new, | - | ||||||||||||||||||
23 | .destroy = md_free, | - | ||||||||||||||||||
24 | .callback_ctrl = md_callback_ctrl | - | ||||||||||||||||||
25 | }; | - | ||||||||||||||||||
26 | - | |||||||||||||||||||
27 | const BIO_METHOD * | - | ||||||||||||||||||
28 | BIO_f_md(void) | - | ||||||||||||||||||
29 | { | - | ||||||||||||||||||
30 | return executed 4 times by 1 test: (&methods_md);return (&methods_md); Executed by:
executed 4 times by 1 test: return (&methods_md); Executed by:
| 4 | ||||||||||||||||||
31 | } | - | ||||||||||||||||||
32 | - | |||||||||||||||||||
33 | static int | - | ||||||||||||||||||
34 | md_new(BIO *bi) | - | ||||||||||||||||||
35 | { | - | ||||||||||||||||||
36 | EVP_MD_CTX *ctx; | - | ||||||||||||||||||
37 | - | |||||||||||||||||||
38 | ctx = EVP_MD_CTX_create(); | - | ||||||||||||||||||
39 | if (ctx ==
| 0-4 | ||||||||||||||||||
40 | ((void *)0)
| 0-4 | ||||||||||||||||||
41 | ) | - | ||||||||||||||||||
42 | return never executed: (0);return (0); never executed: return (0); | 0 | ||||||||||||||||||
43 | - | |||||||||||||||||||
44 | bi->init = 0; | - | ||||||||||||||||||
45 | bi->ptr = (char *)ctx; | - | ||||||||||||||||||
46 | bi->flags = 0; | - | ||||||||||||||||||
47 | return executed 4 times by 1 test: (1);return (1); Executed by:
executed 4 times by 1 test: return (1); Executed by:
| 4 | ||||||||||||||||||
48 | } | - | ||||||||||||||||||
49 | - | |||||||||||||||||||
50 | static int | - | ||||||||||||||||||
51 | md_free(BIO *a) | - | ||||||||||||||||||
52 | { | - | ||||||||||||||||||
53 | if (a ==
| 0-4 | ||||||||||||||||||
54 | ((void *)0)
| 0-4 | ||||||||||||||||||
55 | ) | - | ||||||||||||||||||
56 | return never executed: (0);return (0); never executed: return (0); | 0 | ||||||||||||||||||
57 | EVP_MD_CTX_destroy(a->ptr); | - | ||||||||||||||||||
58 | a->ptr = | - | ||||||||||||||||||
59 | ((void *)0) | - | ||||||||||||||||||
60 | ; | - | ||||||||||||||||||
61 | a->init = 0; | - | ||||||||||||||||||
62 | a->flags = 0; | - | ||||||||||||||||||
63 | return executed 4 times by 1 test: (1);return (1); Executed by:
executed 4 times by 1 test: return (1); Executed by:
| 4 | ||||||||||||||||||
64 | } | - | ||||||||||||||||||
65 | - | |||||||||||||||||||
66 | static int | - | ||||||||||||||||||
67 | md_read(BIO *b, char *out, int outl) | - | ||||||||||||||||||
68 | { | - | ||||||||||||||||||
69 | int ret = 0; | - | ||||||||||||||||||
70 | EVP_MD_CTX *ctx; | - | ||||||||||||||||||
71 | - | |||||||||||||||||||
72 | if (out ==
| 0-4 | ||||||||||||||||||
73 | ((void *)0)
| 0-4 | ||||||||||||||||||
74 | ) | - | ||||||||||||||||||
75 | return never executed: (0);return (0); never executed: return (0); | 0 | ||||||||||||||||||
76 | ctx = b->ptr; | - | ||||||||||||||||||
77 | - | |||||||||||||||||||
78 | if ((
| 0-4 | ||||||||||||||||||
79 | ((void *)0)
| 0-4 | ||||||||||||||||||
80 | )
| 0-4 | ||||||||||||||||||
81 | ((void *)0)
| 0-4 | ||||||||||||||||||
82 | )
| 0-4 | ||||||||||||||||||
83 | return never executed: (0);return (0); never executed: return (0); | 0 | ||||||||||||||||||
84 | - | |||||||||||||||||||
85 | ret = BIO_read(b->next_bio, out, outl); | - | ||||||||||||||||||
86 | if (b->init
| 0-4 | ||||||||||||||||||
87 | if (ret > 0
| 2 | ||||||||||||||||||
88 | if (EVP_DigestUpdate(ctx, (unsigned char *)out,
| 0-2 | ||||||||||||||||||
89 | (unsigned int)ret) <= 0
| 0-2 | ||||||||||||||||||
90 | return never executed: (-1);return (-1); never executed: return (-1); | 0 | ||||||||||||||||||
91 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
92 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||
93 | BIO_clear_flags(b, ((0x01|0x02|0x04)|0x08)); | - | ||||||||||||||||||
94 | BIO_copy_next_retry(b); | - | ||||||||||||||||||
95 | return executed 4 times by 1 test: (ret);return (ret); Executed by:
executed 4 times by 1 test: return (ret); Executed by:
| 4 | ||||||||||||||||||
96 | } | - | ||||||||||||||||||
97 | - | |||||||||||||||||||
98 | static int | - | ||||||||||||||||||
99 | md_write(BIO *b, const char *in, int inl) | - | ||||||||||||||||||
100 | { | - | ||||||||||||||||||
101 | int ret = 0; | - | ||||||||||||||||||
102 | EVP_MD_CTX *ctx; | - | ||||||||||||||||||
103 | - | |||||||||||||||||||
104 | if ((
| 0-2 | ||||||||||||||||||
105 | ((void *)0)
| 0-2 | ||||||||||||||||||
106 | )
| 0-2 | ||||||||||||||||||
107 | return never executed: (0);return (0); never executed: return (0); | 0 | ||||||||||||||||||
108 | ctx = b->ptr; | - | ||||||||||||||||||
109 | - | |||||||||||||||||||
110 | if ((
| 0-2 | ||||||||||||||||||
111 | ((void *)0)
| 0-2 | ||||||||||||||||||
112 | )
| 0-2 | ||||||||||||||||||
113 | ((void *)0)
| 0-2 | ||||||||||||||||||
114 | )
| 0-2 | ||||||||||||||||||
115 | ret = BIO_write(b->next_bio, in, inl); executed 2 times by 1 test: ret = BIO_write(b->next_bio, in, inl); Executed by:
| 2 | ||||||||||||||||||
116 | if (b->init
| 0-2 | ||||||||||||||||||
117 | if (ret > 0
| 0-2 | ||||||||||||||||||
118 | if (!EVP_DigestUpdate(ctx, (const unsigned char *)in,
| 0-2 | ||||||||||||||||||
119 | (unsigned int)ret)
| 0-2 | ||||||||||||||||||
120 | BIO_clear_flags(b, ((0x01|0x02|0x04)|0x08)); | - | ||||||||||||||||||
121 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
122 | } | - | ||||||||||||||||||
123 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
124 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
125 | if (b->next_bio !=
| 0-2 | ||||||||||||||||||
126 | ((void *)0)
| 0-2 | ||||||||||||||||||
127 | ) { | - | ||||||||||||||||||
128 | BIO_clear_flags(b, ((0x01|0x02|0x04)|0x08)); | - | ||||||||||||||||||
129 | BIO_copy_next_retry(b); | - | ||||||||||||||||||
130 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
131 | return executed 2 times by 1 test: (ret);return (ret); Executed by:
executed 2 times by 1 test: return (ret); Executed by:
| 2 | ||||||||||||||||||
132 | } | - | ||||||||||||||||||
133 | - | |||||||||||||||||||
134 | static long | - | ||||||||||||||||||
135 | md_ctrl(BIO *b, int cmd, long num, void *ptr) | - | ||||||||||||||||||
136 | { | - | ||||||||||||||||||
137 | EVP_MD_CTX *ctx, *dctx, **pctx; | - | ||||||||||||||||||
138 | const EVP_MD **ppmd; | - | ||||||||||||||||||
139 | EVP_MD *md; | - | ||||||||||||||||||
140 | long ret = 1; | - | ||||||||||||||||||
141 | BIO *dbio; | - | ||||||||||||||||||
142 | - | |||||||||||||||||||
143 | ctx = b->ptr; | - | ||||||||||||||||||
144 | - | |||||||||||||||||||
145 | switch (cmd) { | - | ||||||||||||||||||
146 | case never executed: 1:case 1: never executed: case 1: | 0 | ||||||||||||||||||
147 | if (b->init
| 0 | ||||||||||||||||||
148 | ret = EVP_DigestInit_ex(ctx, ctx->digest, never executed: ret = EVP_DigestInit_ex(ctx, ctx->digest, ((void *)0) ); | 0 | ||||||||||||||||||
149 | ((void *)0) never executed: ret = EVP_DigestInit_ex(ctx, ctx->digest, ((void *)0) ); | 0 | ||||||||||||||||||
150 | ); never executed: ret = EVP_DigestInit_ex(ctx, ctx->digest, ((void *)0) ); | 0 | ||||||||||||||||||
151 | else | - | ||||||||||||||||||
152 | ret = 0; never executed: ret = 0; | 0 | ||||||||||||||||||
153 | if (ret > 0
| 0 | ||||||||||||||||||
154 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); never executed: ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | 0 | ||||||||||||||||||
155 | break; never executed: break; | 0 | ||||||||||||||||||
156 | case never executed: 112:case 112: never executed: case 112: | 0 | ||||||||||||||||||
157 | if (b->init
| 0 | ||||||||||||||||||
158 | ppmd = ptr; | - | ||||||||||||||||||
159 | *ppmd = ctx->digest; | - | ||||||||||||||||||
160 | } never executed: elseend of block | 0 | ||||||||||||||||||
161 | ret = 0; never executed: ret = 0; | 0 | ||||||||||||||||||
162 | break; never executed: break; | 0 | ||||||||||||||||||
163 | case executed 4 times by 1 test: 120:case 120: Executed by:
executed 4 times by 1 test: case 120: Executed by:
| 4 | ||||||||||||||||||
164 | pctx = ptr; | - | ||||||||||||||||||
165 | *pctx = ctx; | - | ||||||||||||||||||
166 | b->init = 1; | - | ||||||||||||||||||
167 | break; executed 4 times by 1 test: break; Executed by:
| 4 | ||||||||||||||||||
168 | case never executed: 148:case 148: never executed: case 148: | 0 | ||||||||||||||||||
169 | if (b->init
| 0 | ||||||||||||||||||
170 | b->ptr = ptr; never executed: b->ptr = ptr; | 0 | ||||||||||||||||||
171 | else | - | ||||||||||||||||||
172 | ret = 0; never executed: ret = 0; | 0 | ||||||||||||||||||
173 | break; never executed: break; | 0 | ||||||||||||||||||
174 | case never executed: 101:case 101: never executed: case 101: | 0 | ||||||||||||||||||
175 | BIO_clear_flags(b, ((0x01|0x02|0x04)|0x08)); | - | ||||||||||||||||||
176 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | - | ||||||||||||||||||
177 | BIO_copy_next_retry(b); | - | ||||||||||||||||||
178 | break; never executed: break; | 0 | ||||||||||||||||||
179 | - | |||||||||||||||||||
180 | case executed 4 times by 1 test: 111:case 111: Executed by:
executed 4 times by 1 test: case 111: Executed by:
| 4 | ||||||||||||||||||
181 | md = ptr; | - | ||||||||||||||||||
182 | ret = EVP_DigestInit_ex(ctx, md, | - | ||||||||||||||||||
183 | ((void *)0) | - | ||||||||||||||||||
184 | ); | - | ||||||||||||||||||
185 | if (ret > 0
| 0-4 | ||||||||||||||||||
186 | b->init = 1; executed 4 times by 1 test: b->init = 1; Executed by:
| 4 | ||||||||||||||||||
187 | break; executed 4 times by 1 test: break; Executed by:
| 4 | ||||||||||||||||||
188 | case never executed: 12:case 12: never executed: case 12: | 0 | ||||||||||||||||||
189 | dbio = ptr; | - | ||||||||||||||||||
190 | dctx = dbio->ptr; | - | ||||||||||||||||||
191 | if (!EVP_MD_CTX_copy_ex(dctx, ctx)
| 0 | ||||||||||||||||||
192 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
193 | b->init = 1; | - | ||||||||||||||||||
194 | break; never executed: break; | 0 | ||||||||||||||||||
195 | default executed 12 times by 1 test: :default: Executed by:
executed 12 times by 1 test: default: Executed by:
| 12 | ||||||||||||||||||
196 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | - | ||||||||||||||||||
197 | break; executed 12 times by 1 test: break; Executed by:
| 12 | ||||||||||||||||||
198 | } | - | ||||||||||||||||||
199 | return executed 20 times by 1 test: (ret);return (ret); Executed by:
executed 20 times by 1 test: return (ret); Executed by:
| 20 | ||||||||||||||||||
200 | } | - | ||||||||||||||||||
201 | - | |||||||||||||||||||
202 | static long | - | ||||||||||||||||||
203 | md_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) | - | ||||||||||||||||||
204 | { | - | ||||||||||||||||||
205 | long ret = 1; | - | ||||||||||||||||||
206 | - | |||||||||||||||||||
207 | if (b->next_bio ==
| 0 | ||||||||||||||||||
208 | ((void *)0)
| 0 | ||||||||||||||||||
209 | ) | - | ||||||||||||||||||
210 | return never executed: (0);return (0); never executed: return (0); | 0 | ||||||||||||||||||
211 | switch (cmd) { | - | ||||||||||||||||||
212 | default never executed: :default: never executed: default: | 0 | ||||||||||||||||||
213 | ret = BIO_callback_ctrl(b->next_bio, cmd, fp); | - | ||||||||||||||||||
214 | break; never executed: break; | 0 | ||||||||||||||||||
215 | } | - | ||||||||||||||||||
216 | return never executed: (ret);return (ret); never executed: return (ret); | 0 | ||||||||||||||||||
217 | } | - | ||||||||||||||||||
218 | - | |||||||||||||||||||
219 | static int | - | ||||||||||||||||||
220 | md_gets(BIO *bp, char *buf, int size) | - | ||||||||||||||||||
221 | { | - | ||||||||||||||||||
222 | EVP_MD_CTX *ctx; | - | ||||||||||||||||||
223 | unsigned int ret; | - | ||||||||||||||||||
224 | - | |||||||||||||||||||
225 | ctx = bp->ptr; | - | ||||||||||||||||||
226 | if (size < ctx->digest->md_size
| 0 | ||||||||||||||||||
227 | return never executed: (0);return (0); never executed: return (0); | 0 | ||||||||||||||||||
228 | if (EVP_DigestFinal_ex(ctx, (unsigned char *)buf, &ret) <= 0
| 0 | ||||||||||||||||||
229 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||||||||
230 | - | |||||||||||||||||||
231 | return never executed: ((int)ret);return ((int)ret); never executed: return ((int)ret); | 0 | ||||||||||||||||||
232 | } | - | ||||||||||||||||||
Switch to Source code | Preprocessed file |