Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/bn/bn_ctx.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | typedef struct bignum_pool_item { | - | ||||||||||||
2 | - | |||||||||||||
3 | BIGNUM vals[16]; | - | ||||||||||||
4 | - | |||||||||||||
5 | struct bignum_pool_item *prev, *next; | - | ||||||||||||
6 | } BN_POOL_ITEM; | - | ||||||||||||
7 | - | |||||||||||||
8 | typedef struct bignum_pool { | - | ||||||||||||
9 | - | |||||||||||||
10 | BN_POOL_ITEM *head, *current, *tail; | - | ||||||||||||
11 | - | |||||||||||||
12 | unsigned used, size; | - | ||||||||||||
13 | } BN_POOL; | - | ||||||||||||
14 | static void BN_POOL_init(BN_POOL *); | - | ||||||||||||
15 | static void BN_POOL_finish(BN_POOL *); | - | ||||||||||||
16 | static BIGNUM *BN_POOL_get(BN_POOL *, int); | - | ||||||||||||
17 | static void BN_POOL_release(BN_POOL *, unsigned int); | - | ||||||||||||
18 | - | |||||||||||||
19 | - | |||||||||||||
20 | - | |||||||||||||
21 | - | |||||||||||||
22 | - | |||||||||||||
23 | - | |||||||||||||
24 | typedef struct bignum_ctx_stack { | - | ||||||||||||
25 | - | |||||||||||||
26 | unsigned int *indexes; | - | ||||||||||||
27 | - | |||||||||||||
28 | unsigned int depth, size; | - | ||||||||||||
29 | } BN_STACK; | - | ||||||||||||
30 | static void BN_STACK_init(BN_STACK *); | - | ||||||||||||
31 | static void BN_STACK_finish(BN_STACK *); | - | ||||||||||||
32 | static int BN_STACK_push(BN_STACK *, unsigned int); | - | ||||||||||||
33 | static unsigned int BN_STACK_pop(BN_STACK *); | - | ||||||||||||
34 | - | |||||||||||||
35 | - | |||||||||||||
36 | - | |||||||||||||
37 | - | |||||||||||||
38 | - | |||||||||||||
39 | - | |||||||||||||
40 | struct bignum_ctx { | - | ||||||||||||
41 | - | |||||||||||||
42 | BN_POOL pool; | - | ||||||||||||
43 | - | |||||||||||||
44 | BN_STACK stack; | - | ||||||||||||
45 | - | |||||||||||||
46 | unsigned int used; | - | ||||||||||||
47 | - | |||||||||||||
48 | int err_stack; | - | ||||||||||||
49 | - | |||||||||||||
50 | int too_many; | - | ||||||||||||
51 | - | |||||||||||||
52 | int flags; | - | ||||||||||||
53 | }; | - | ||||||||||||
54 | BN_CTX *BN_CTX_new(void) | - | ||||||||||||
55 | { | - | ||||||||||||
56 | BN_CTX *ret; | - | ||||||||||||
57 | - | |||||||||||||
58 | if ((
| 0-135934 | ||||||||||||
59 | ((void *)0)
| 0-135934 | ||||||||||||
60 | ) { | - | ||||||||||||
61 | ERR_put_error(3,(106),((1|64)),__FILE__,139); | - | ||||||||||||
62 | return never executed: return ((void *)0) ; never executed: return ((void *)0) ; | 0 | ||||||||||||
63 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||
64 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||
65 | } | - | ||||||||||||
66 | - | |||||||||||||
67 | BN_POOL_init(&ret->pool); | - | ||||||||||||
68 | BN_STACK_init(&ret->stack); | - | ||||||||||||
69 | return executed 135934 times by 2 tests: ret;return ret; Executed by:
executed 135934 times by 2 tests: return ret; Executed by:
| 135934 | ||||||||||||
70 | } | - | ||||||||||||
71 | - | |||||||||||||
72 | BN_CTX *BN_CTX_secure_new(void) | - | ||||||||||||
73 | { | - | ||||||||||||
74 | BN_CTX *ret = BN_CTX_new(); | - | ||||||||||||
75 | - | |||||||||||||
76 | if (ret !=
| 0-402 | ||||||||||||
77 | ((void *)0)
| 0-402 | ||||||||||||
78 | ) | - | ||||||||||||
79 | ret->flags = 0x08; executed 402 times by 2 tests: ret->flags = 0x08; Executed by:
| 402 | ||||||||||||
80 | return executed 402 times by 2 tests: ret;return ret; Executed by:
executed 402 times by 2 tests: return ret; Executed by:
| 402 | ||||||||||||
81 | } | - | ||||||||||||
82 | - | |||||||||||||
83 | void BN_CTX_free(BN_CTX *ctx) | - | ||||||||||||
84 | { | - | ||||||||||||
85 | if (ctx ==
| 135934-551182 | ||||||||||||
86 | ((void *)0)
| 135934-551182 | ||||||||||||
87 | ) | - | ||||||||||||
88 | return; executed 551182 times by 2 tests: return; Executed by:
| 551182 | ||||||||||||
89 | BN_STACK_finish(&ctx->stack); | - | ||||||||||||
90 | BN_POOL_finish(&ctx->pool); | - | ||||||||||||
91 | CRYPTO_free(ctx, __FILE__, 178); | - | ||||||||||||
92 | } executed 135934 times by 2 tests: end of block Executed by:
| 135934 | ||||||||||||
93 | - | |||||||||||||
94 | void BN_CTX_start(BN_CTX *ctx) | - | ||||||||||||
95 | { | - | ||||||||||||
96 | ; | - | ||||||||||||
97 | - | |||||||||||||
98 | if (ctx->err_stack
| 0-74719294 | ||||||||||||
99 | ctx->err_stack++; never executed: ctx->err_stack++; | 0 | ||||||||||||
100 | - | |||||||||||||
101 | else if (!BN_STACK_push(&ctx->stack, ctx->used)
| 0-74719294 | ||||||||||||
102 | ERR_put_error(3,(129),(109),__FILE__,189); | - | ||||||||||||
103 | ctx->err_stack++; | - | ||||||||||||
104 | } never executed: end of block | 0 | ||||||||||||
105 | ; | - | ||||||||||||
106 | } executed 74719294 times by 2 tests: end of block Executed by:
| 74719294 | ||||||||||||
107 | - | |||||||||||||
108 | void BN_CTX_end(BN_CTX *ctx) | - | ||||||||||||
109 | { | - | ||||||||||||
110 | ; | - | ||||||||||||
111 | if (ctx->err_stack
| 0-74719278 | ||||||||||||
112 | ctx->err_stack--; never executed: ctx->err_stack--; | 0 | ||||||||||||
113 | else { | - | ||||||||||||
114 | unsigned int fp = BN_STACK_pop(&ctx->stack); | - | ||||||||||||
115 | - | |||||||||||||
116 | if (fp < ctx->used
| 3125394-71593884 | ||||||||||||
117 | BN_POOL_release(&ctx->pool, ctx->used - fp); executed 71593884 times by 2 tests: BN_POOL_release(&ctx->pool, ctx->used - fp); Executed by:
| 71593884 | ||||||||||||
118 | ctx->used = fp; | - | ||||||||||||
119 | - | |||||||||||||
120 | ctx->too_many = 0; | - | ||||||||||||
121 | } executed 74719278 times by 2 tests: end of block Executed by:
| 74719278 | ||||||||||||
122 | ; | - | ||||||||||||
123 | } | - | ||||||||||||
124 | - | |||||||||||||
125 | BIGNUM *BN_CTX_get(BN_CTX *ctx) | - | ||||||||||||
126 | { | - | ||||||||||||
127 | BIGNUM *ret; | - | ||||||||||||
128 | - | |||||||||||||
129 | ; | - | ||||||||||||
130 | if (ctx->err_stack
| 0-97054752 | ||||||||||||
131 | return never executed: return ((void *)0) ; never executed: return ((void *)0) ; | 0 | ||||||||||||
132 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||
133 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||
134 | if ((
| 0-97054752 | ||||||||||||
135 | ((void *)0)
| 0-97054752 | ||||||||||||
136 | ) { | - | ||||||||||||
137 | - | |||||||||||||
138 | - | |||||||||||||
139 | - | |||||||||||||
140 | - | |||||||||||||
141 | ctx->too_many = 1; | - | ||||||||||||
142 | ERR_put_error(3,(116),(109),__FILE__,225); | - | ||||||||||||
143 | return never executed: return ((void *)0) ; never executed: return ((void *)0) ; | 0 | ||||||||||||
144 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||
145 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||
146 | } | - | ||||||||||||
147 | - | |||||||||||||
148 | (BN_set_word((ret),0)); | - | ||||||||||||
149 | ctx->used++; | - | ||||||||||||
150 | ; | - | ||||||||||||
151 | return executed 97054752 times by 2 tests: ret;return ret; Executed by:
executed 97054752 times by 2 tests: return ret; Executed by:
| 97054752 | ||||||||||||
152 | } | - | ||||||||||||
153 | - | |||||||||||||
154 | - | |||||||||||||
155 | - | |||||||||||||
156 | - | |||||||||||||
157 | - | |||||||||||||
158 | static void BN_STACK_init(BN_STACK *st) | - | ||||||||||||
159 | { | - | ||||||||||||
160 | st->indexes = | - | ||||||||||||
161 | ((void *)0) | - | ||||||||||||
162 | ; | - | ||||||||||||
163 | st->depth = st->size = 0; | - | ||||||||||||
164 | } executed 135934 times by 2 tests: end of block Executed by:
| 135934 | ||||||||||||
165 | - | |||||||||||||
166 | static void BN_STACK_finish(BN_STACK *st) | - | ||||||||||||
167 | { | - | ||||||||||||
168 | CRYPTO_free(st->indexes, __FILE__, 247); | - | ||||||||||||
169 | st->indexes = | - | ||||||||||||
170 | ((void *)0) | - | ||||||||||||
171 | ; | - | ||||||||||||
172 | } executed 135934 times by 2 tests: end of block Executed by:
| 135934 | ||||||||||||
173 | - | |||||||||||||
174 | - | |||||||||||||
175 | static int BN_STACK_push(BN_STACK *st, unsigned int idx) | - | ||||||||||||
176 | { | - | ||||||||||||
177 | if (st->depth == st->size
| 135647-74583647 | ||||||||||||
178 | - | |||||||||||||
179 | unsigned int newsize = | - | ||||||||||||
180 | st->size
| 0-135647 | ||||||||||||
181 | unsigned int *newitems; | - | ||||||||||||
182 | - | |||||||||||||
183 | if ((
| 0-135647 | ||||||||||||
184 | ((void *)0)
| 0-135647 | ||||||||||||
185 | ) { | - | ||||||||||||
186 | ERR_put_error(3,(148),((1|64)),__FILE__,261); | - | ||||||||||||
187 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
188 | } | - | ||||||||||||
189 | if (st->depth
| 0-135647 | ||||||||||||
190 | memcpy(newitems, st->indexes, sizeof(*newitems) * st->depth); never executed: memcpy(newitems, st->indexes, sizeof(*newitems) * st->depth); | 0 | ||||||||||||
191 | CRYPTO_free(st->indexes, __FILE__, 266); | - | ||||||||||||
192 | st->indexes = newitems; | - | ||||||||||||
193 | st->size = newsize; | - | ||||||||||||
194 | } executed 135647 times by 2 tests: end of block Executed by:
| 135647 | ||||||||||||
195 | st->indexes[(st->depth)++] = idx; | - | ||||||||||||
196 | return executed 74719294 times by 2 tests: 1;return 1; Executed by:
executed 74719294 times by 2 tests: return 1; Executed by:
| 74719294 | ||||||||||||
197 | } | - | ||||||||||||
198 | - | |||||||||||||
199 | static unsigned int BN_STACK_pop(BN_STACK *st) | - | ||||||||||||
200 | { | - | ||||||||||||
201 | return executed 74719278 times by 2 tests: st->indexes[--(st->depth)];return st->indexes[--(st->depth)]; Executed by:
executed 74719278 times by 2 tests: return st->indexes[--(st->depth)]; Executed by:
| 74719278 | ||||||||||||
202 | } | - | ||||||||||||
203 | - | |||||||||||||
204 | - | |||||||||||||
205 | - | |||||||||||||
206 | - | |||||||||||||
207 | - | |||||||||||||
208 | static void BN_POOL_init(BN_POOL *p) | - | ||||||||||||
209 | { | - | ||||||||||||
210 | p->head = p->current = p->tail = | - | ||||||||||||
211 | ((void *)0) | - | ||||||||||||
212 | ; | - | ||||||||||||
213 | p->used = p->size = 0; | - | ||||||||||||
214 | } executed 135934 times by 2 tests: end of block Executed by:
| 135934 | ||||||||||||
215 | - | |||||||||||||
216 | static void BN_POOL_finish(BN_POOL *p) | - | ||||||||||||
217 | { | - | ||||||||||||
218 | unsigned int loop; | - | ||||||||||||
219 | BIGNUM *bn; | - | ||||||||||||
220 | - | |||||||||||||
221 | while (p->head
| 135934-142688 | ||||||||||||
222 | for (loop = 0, bn = p->head->vals; loop++ < 16
| 142688-2283008 | ||||||||||||
223 | if (bn->d
| 979823-1303185 | ||||||||||||
224 | BN_clear_free(bn); executed 1303185 times by 2 tests: BN_clear_free(bn); Executed by:
| 1303185 | ||||||||||||
225 | p->current = p->head->next; | - | ||||||||||||
226 | CRYPTO_free(p->head, __FILE__, 299); | - | ||||||||||||
227 | p->head = p->current; | - | ||||||||||||
228 | } executed 142688 times by 2 tests: end of block Executed by:
| 142688 | ||||||||||||
229 | } executed 135934 times by 2 tests: end of block Executed by:
| 135934 | ||||||||||||
230 | - | |||||||||||||
231 | - | |||||||||||||
232 | static BIGNUM *BN_POOL_get(BN_POOL *p, int flag) | - | ||||||||||||
233 | { | - | ||||||||||||
234 | BIGNUM *bn; | - | ||||||||||||
235 | unsigned int loop; | - | ||||||||||||
236 | - | |||||||||||||
237 | - | |||||||||||||
238 | if (p->used == p->size
| 142688-96912064 | ||||||||||||
239 | BN_POOL_ITEM *item; | - | ||||||||||||
240 | - | |||||||||||||
241 | if ((
| 0-142688 | ||||||||||||
242 | ((void *)0)
| 0-142688 | ||||||||||||
243 | ) { | - | ||||||||||||
244 | ERR_put_error(3,(147),((1|64)),__FILE__,315); | - | ||||||||||||
245 | return never executed: return ((void *)0) ; never executed: return ((void *)0) ; | 0 | ||||||||||||
246 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||
247 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||
248 | } | - | ||||||||||||
249 | for (loop = 0, bn = item->vals; loop++ < 16
| 142688-2283008 | ||||||||||||
250 | bn_init(bn); | - | ||||||||||||
251 | if ((
| 6272-2276736 | ||||||||||||
252 | BN_set_flags(bn, 0x08); executed 6272 times by 2 tests: BN_set_flags(bn, 0x08); Executed by:
| 6272 | ||||||||||||
253 | } executed 2283008 times by 2 tests: end of block Executed by:
| 2283008 | ||||||||||||
254 | item->prev = p->tail; | - | ||||||||||||
255 | item->next = | - | ||||||||||||
256 | ((void *)0) | - | ||||||||||||
257 | ; | - | ||||||||||||
258 | - | |||||||||||||
259 | if (p->head ==
| 7496-135192 | ||||||||||||
260 | ((void *)0)
| 7496-135192 | ||||||||||||
261 | ) | - | ||||||||||||
262 | p->head = p->current = p->tail = item; executed 135192 times by 2 tests: p->head = p->current = p->tail = item; Executed by:
| 135192 | ||||||||||||
263 | else { | - | ||||||||||||
264 | p->tail->next = item; | - | ||||||||||||
265 | p->tail = item; | - | ||||||||||||
266 | p->current = item; | - | ||||||||||||
267 | } executed 7496 times by 2 tests: end of block Executed by:
| 7496 | ||||||||||||
268 | p->size += 16; | - | ||||||||||||
269 | p->used++; | - | ||||||||||||
270 | - | |||||||||||||
271 | return executed 142688 times by 2 tests: item->vals;return item->vals; Executed by:
executed 142688 times by 2 tests: return item->vals; Executed by:
| 142688 | ||||||||||||
272 | } | - | ||||||||||||
273 | - | |||||||||||||
274 | if (!p->used
| 240365-96671699 | ||||||||||||
275 | p->current = p->head; executed 240365 times by 2 tests: p->current = p->head; Executed by:
| 240365 | ||||||||||||
276 | else if ((
| 3946415-92725284 | ||||||||||||
277 | p->current = p->current->next; executed 3946415 times by 1 test: p->current = p->current->next; Executed by:
| 3946415 | ||||||||||||
278 | return executed 96912064 times by 2 tests: p->current->vals + ((p->used++) % 16);return p->current->vals + ((p->used++) % 16); Executed by:
executed 96912064 times by 2 tests: return p->current->vals + ((p->used++) % 16); Executed by:
| 96912064 | ||||||||||||
279 | } | - | ||||||||||||
280 | - | |||||||||||||
281 | static void BN_POOL_release(BN_POOL *p, unsigned int num) | - | ||||||||||||
282 | { | - | ||||||||||||
283 | unsigned int offset = (p->used - 1) % 16; | - | ||||||||||||
284 | - | |||||||||||||
285 | p->used -= num; | - | ||||||||||||
286 | while (num--
| 71593884-97054414 | ||||||||||||
287 | ; | - | ||||||||||||
288 | if (offset == 0
| 4329383-92725031 | ||||||||||||
289 | offset = 16 - 1; | - | ||||||||||||
290 | p->current = p->current->prev; | - | ||||||||||||
291 | } executed 4329383 times by 2 tests: elseend of block Executed by:
| 4329383 | ||||||||||||
292 | offset--; executed 92725031 times by 2 tests: offset--; Executed by:
| 92725031 | ||||||||||||
293 | } | - | ||||||||||||
294 | } executed 71593884 times by 2 tests: end of block Executed by:
| 71593884 | ||||||||||||
Switch to Source code | Preprocessed file |