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