OpenCoverage

bn_ctx.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/bn/bn_ctx.c
Switch to Source codePreprocessed file
LineSourceCount
1typedef struct bignum_pool_item {-
2-
3 BIGNUM vals[16];-
4-
5 struct bignum_pool_item *prev, *next;-
6} BN_POOL_ITEM;-
7-
8typedef struct bignum_pool {-
9-
10 BN_POOL_ITEM *head, *current, *tail;-
11-
12 unsigned used, size;-
13} BN_POOL;-
14static void BN_POOL_init(BN_POOL *);-
15static void BN_POOL_finish(BN_POOL *);-
16static BIGNUM *BN_POOL_get(BN_POOL *, int);-
17static void BN_POOL_release(BN_POOL *, unsigned int);-
18-
19-
20-
21-
22-
23-
24typedef struct bignum_ctx_stack {-
25-
26 unsigned int *indexes;-
27-
28 unsigned int depth, size;-
29} BN_STACK;-
30static void BN_STACK_init(BN_STACK *);-
31static void BN_STACK_finish(BN_STACK *);-
32static int BN_STACK_push(BN_STACK *, unsigned int);-
33static unsigned int BN_STACK_pop(BN_STACK *);-
34-
35-
36-
37-
38-
39-
40struct 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};-
54BN_CTX *BN_CTX_new(void)-
55{-
56 BN_CTX *ret;-
57-
58 if ((
(ret = CRYPTO_...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 135934 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
ret = CRYPTO_zalloc(sizeof(*ret), __FILE__, 138)) ==
(ret = CRYPTO_...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 135934 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
0-135934
59 ((void *)0)
(ret = CRYPTO_...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 135934 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
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: return ret;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
ret;
executed 135934 times by 2 tests: return ret;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
135934
70}-
71-
72BN_CTX *BN_CTX_secure_new(void)-
73{-
74 BN_CTX *ret = BN_CTX_new();-
75-
76 if (ret !=
ret != ((void *)0)Description
TRUEevaluated 402 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEnever evaluated
0-402
77 ((void *)0)
ret != ((void *)0)Description
TRUEevaluated 402 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEnever evaluated
0-402
78 )-
79 ret->flags = 0x08;
executed 402 times by 2 tests: ret->flags = 0x08;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
402
80 return
executed 402 times by 2 tests: return ret;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
ret;
executed 402 times by 2 tests: return ret;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
402
81}-
82-
83void BN_CTX_free(BN_CTX *ctx)-
84{-
85 if (ctx ==
ctx == ((void *)0)Description
TRUEevaluated 551182 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 135934 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
135934-551182
86 ((void *)0)
ctx == ((void *)0)Description
TRUEevaluated 551182 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 135934 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
135934-551182
87 )-
88 return;
executed 551182 times by 2 tests: return;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
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:
  • libcrypto.so.1.1
  • sm2_internal_test
135934
93-
94void BN_CTX_start(BN_CTX *ctx)-
95{-
96 ;-
97-
98 if (ctx->err_stack
ctx->err_stackDescription
TRUEnever evaluated
FALSEevaluated 74719294 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
|| ctx->too_many
ctx->too_manyDescription
TRUEnever evaluated
FALSEevaluated 74719294 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
)
0-74719294
99 ctx->err_stack++;
never executed: ctx->err_stack++;
0
100-
101 else if (!BN_STACK_push(&ctx->stack, ctx->used)
!BN_STACK_push...ck, ctx->used)Description
TRUEnever evaluated
FALSEevaluated 74719294 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
) {
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:
  • libcrypto.so.1.1
  • sm2_internal_test
74719294
107-
108void BN_CTX_end(BN_CTX *ctx)-
109{-
110 ;-
111 if (ctx->err_stack
ctx->err_stackDescription
TRUEnever evaluated
FALSEevaluated 74719278 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
)
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
fp < ctx->usedDescription
TRUEevaluated 71593884 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 3125394 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
)
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:
  • libcrypto.so.1.1
  • sm2_internal_test
71593884
118 ctx->used = fp;-
119-
120 ctx->too_many = 0;-
121 }
executed 74719278 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
74719278
122 ;-
123}-
124-
125BIGNUM *BN_CTX_get(BN_CTX *ctx)-
126{-
127 BIGNUM *ret;-
128-
129 ;-
130 if (ctx->err_stack
ctx->err_stackDescription
TRUEnever evaluated
FALSEevaluated 97054752 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
|| ctx->too_many
ctx->too_manyDescription
TRUEnever evaluated
FALSEevaluated 97054752 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
)
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 ((
(ret = BN_POOL...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 97054752 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
ret = BN_POOL_get(&ctx->pool, ctx->flags)) ==
(ret = BN_POOL...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 97054752 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
0-97054752
135 ((void *)0)
(ret = BN_POOL...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 97054752 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
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: return ret;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
ret;
executed 97054752 times by 2 tests: return ret;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
97054752
152}-
153-
154-
155-
156-
157-
158static 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:
  • libcrypto.so.1.1
  • sm2_internal_test
135934
165-
166static 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:
  • libcrypto.so.1.1
  • sm2_internal_test
135934
173-
174-
175static int BN_STACK_push(BN_STACK *st, unsigned int idx)-
176{-
177 if (st->depth == st->size
st->depth == st->sizeDescription
TRUEevaluated 135647 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 74583647 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
) {
135647-74583647
178-
179 unsigned int newsize =-
180 st->size
st->sizeDescription
TRUEnever evaluated
FALSEevaluated 135647 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
? (st->size * 3 / 2) : 32;
0-135647
181 unsigned int *newitems;-
182-
183 if ((
(newitems = CR...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 135647 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
newitems = CRYPTO_malloc(sizeof(*newitems) * newsize, __FILE__, 260)) ==
(newitems = CR...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 135647 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
0-135647
184 ((void *)0)
(newitems = CR...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 135647 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
0-135647
185 ) {-
186 ERR_put_error(3,(148),((1|64)),__FILE__,261);-
187 return
never executed: return 0;
0;
never executed: return 0;
0
188 }-
189 if (st->depth
st->depthDescription
TRUEnever evaluated
FALSEevaluated 135647 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
)
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:
  • libcrypto.so.1.1
  • sm2_internal_test
135647
195 st->indexes[(st->depth)++] = idx;-
196 return
executed 74719294 times by 2 tests: return 1;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
1;
executed 74719294 times by 2 tests: return 1;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
74719294
197}-
198-
199static unsigned int BN_STACK_pop(BN_STACK *st)-
200{-
201 return
executed 74719278 times by 2 tests: return st->indexes[--(st->depth)];
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
st->indexes[--(st->depth)];
executed 74719278 times by 2 tests: return st->indexes[--(st->depth)];
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
74719278
202}-
203-
204-
205-
206-
207-
208static 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:
  • libcrypto.so.1.1
  • sm2_internal_test
135934
215-
216static void BN_POOL_finish(BN_POOL *p)-
217{-
218 unsigned int loop;-
219 BIGNUM *bn;-
220-
221 while (p->head
p->headDescription
TRUEevaluated 142688 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 135934 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
) {
135934-142688
222 for (loop = 0, bn = p->head->vals; loop++ < 16
loop++ < 16Description
TRUEevaluated 2283008 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 142688 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
; bn++)
142688-2283008
223 if (bn->d
bn->dDescription
TRUEevaluated 1303185 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 979823 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
)
979823-1303185
224 BN_clear_free(bn);
executed 1303185 times by 2 tests: BN_clear_free(bn);
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
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:
  • libcrypto.so.1.1
  • sm2_internal_test
142688
229}
executed 135934 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
135934
230-
231-
232static 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
p->used == p->sizeDescription
TRUEevaluated 142688 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 96912064 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
) {
142688-96912064
239 BN_POOL_ITEM *item;-
240-
241 if ((
(item = CRYPTO...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 142688 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
item = CRYPTO_malloc(sizeof(*item), __FILE__, 314)) ==
(item = CRYPTO...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 142688 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
0-142688
242 ((void *)0)
(item = CRYPTO...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 142688 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
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
loop++ < 16Description
TRUEevaluated 2283008 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 142688 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
; bn++) {
142688-2283008
250 bn_init(bn);-
251 if ((
(flag & 0x08) != 0Description
TRUEevaluated 6272 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 2276736 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
flag & 0x08) != 0
(flag & 0x08) != 0Description
TRUEevaluated 6272 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 2276736 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
)
6272-2276736
252 BN_set_flags(bn, 0x08);
executed 6272 times by 2 tests: BN_set_flags(bn, 0x08);
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
6272
253 }
executed 2283008 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
2283008
254 item->prev = p->tail;-
255 item->next = -
256 ((void *)0)-
257 ;-
258-
259 if (p->head ==
p->head == ((void *)0)Description
TRUEevaluated 135192 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 7496 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
7496-135192
260 ((void *)0)
p->head == ((void *)0)Description
TRUEevaluated 135192 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 7496 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
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:
  • libcrypto.so.1.1
  • sm2_internal_test
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:
  • libcrypto.so.1.1
  • sm2_internal_test
7496
268 p->size += 16;-
269 p->used++;-
270-
271 return
executed 142688 times by 2 tests: return item->vals;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
item->vals;
executed 142688 times by 2 tests: return item->vals;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
142688
272 }-
273-
274 if (!p->used
!p->usedDescription
TRUEevaluated 240365 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 96671699 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
)
240365-96671699
275 p->current = p->head;
executed 240365 times by 2 tests: p->current = p->head;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
240365
276 else if ((
(p->used % 16) == 0Description
TRUEevaluated 3946415 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 92725284 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
p->used % 16) == 0
(p->used % 16) == 0Description
TRUEevaluated 3946415 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 92725284 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
)
3946415-92725284
277 p->current = p->current->next;
executed 3946415 times by 1 test: p->current = p->current->next;
Executed by:
  • libcrypto.so.1.1
3946415
278 return
executed 96912064 times by 2 tests: return p->current->vals + ((p->used++) % 16);
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
p->current->vals + ((p->used++) % 16);
executed 96912064 times by 2 tests: return p->current->vals + ((p->used++) % 16);
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
96912064
279}-
280-
281static 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--
num--Description
TRUEevaluated 97054414 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 71593884 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
) {
71593884-97054414
287 ;-
288 if (offset == 0
offset == 0Description
TRUEevaluated 4329383 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 92725031 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
) {
4329383-92725031
289 offset = 16 - 1;-
290 p->current = p->current->prev;-
291 }
executed 4329383 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
else
4329383
292 offset--;
executed 92725031 times by 2 tests: offset--;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
92725031
293 }-
294}
executed 71593884 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
71593884
Switch to Source codePreprocessed file

Generated by Squish Coco 4.2.2