Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/bn/bn_gcd.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||
2 | static BIGNUM *euclid(BIGNUM *a, BIGNUM *b); | - | ||||||||||||||||||
3 | - | |||||||||||||||||||
4 | int BN_gcd(BIGNUM *r, const BIGNUM *in_a, const BIGNUM *in_b, BN_CTX *ctx) | - | ||||||||||||||||||
5 | { | - | ||||||||||||||||||
6 | BIGNUM *a, *b, *t; | - | ||||||||||||||||||
7 | int ret = 0; | - | ||||||||||||||||||
8 | - | |||||||||||||||||||
9 | ; | - | ||||||||||||||||||
10 | ; | - | ||||||||||||||||||
11 | - | |||||||||||||||||||
12 | BN_CTX_start(ctx); | - | ||||||||||||||||||
13 | a = BN_CTX_get(ctx); | - | ||||||||||||||||||
14 | b = BN_CTX_get(ctx); | - | ||||||||||||||||||
15 | if (b ==
| 0-25 | ||||||||||||||||||
16 | ((void *)0)
| 0-25 | ||||||||||||||||||
17 | ) | - | ||||||||||||||||||
18 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
19 | - | |||||||||||||||||||
20 | if (BN_copy(a, in_a) ==
| 0-25 | ||||||||||||||||||
21 | ((void *)0)
| 0-25 | ||||||||||||||||||
22 | ) | - | ||||||||||||||||||
23 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
24 | if (BN_copy(b, in_b) ==
| 0-25 | ||||||||||||||||||
25 | ((void *)0)
| 0-25 | ||||||||||||||||||
26 | ) | - | ||||||||||||||||||
27 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
28 | a->neg = 0; | - | ||||||||||||||||||
29 | b->neg = 0; | - | ||||||||||||||||||
30 | - | |||||||||||||||||||
31 | if (BN_cmp(a, b) < 0
| 11-14 | ||||||||||||||||||
32 | t = a; | - | ||||||||||||||||||
33 | a = b; | - | ||||||||||||||||||
34 | b = t; | - | ||||||||||||||||||
35 | } executed 14 times by 1 test: end of block Executed by:
| 14 | ||||||||||||||||||
36 | t = euclid(a, b); | - | ||||||||||||||||||
37 | if (t ==
| 0-25 | ||||||||||||||||||
38 | ((void *)0)
| 0-25 | ||||||||||||||||||
39 | ) | - | ||||||||||||||||||
40 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
41 | - | |||||||||||||||||||
42 | if (BN_copy(r, t) ==
| 0-25 | ||||||||||||||||||
43 | ((void *)0)
| 0-25 | ||||||||||||||||||
44 | ) | - | ||||||||||||||||||
45 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
46 | ret = 1; | - | ||||||||||||||||||
47 | err: code before this statement executed 25 times by 1 test: err: Executed by:
| 25 | ||||||||||||||||||
48 | BN_CTX_end(ctx); | - | ||||||||||||||||||
49 | ; | - | ||||||||||||||||||
50 | return executed 25 times by 1 test: ret;return ret; Executed by:
executed 25 times by 1 test: return ret; Executed by:
| 25 | ||||||||||||||||||
51 | } | - | ||||||||||||||||||
52 | - | |||||||||||||||||||
53 | static BIGNUM *euclid(BIGNUM *a, BIGNUM *b) | - | ||||||||||||||||||
54 | { | - | ||||||||||||||||||
55 | BIGNUM *t; | - | ||||||||||||||||||
56 | int shifts = 0; | - | ||||||||||||||||||
57 | - | |||||||||||||||||||
58 | ; | - | ||||||||||||||||||
59 | ; | - | ||||||||||||||||||
60 | - | |||||||||||||||||||
61 | - | |||||||||||||||||||
62 | while (!BN_is_zero(b)
| 25-29254 | ||||||||||||||||||
63 | - | |||||||||||||||||||
64 | - | |||||||||||||||||||
65 | if (BN_is_odd(a)
| 11312-17942 | ||||||||||||||||||
66 | if (BN_is_odd(b)
| 3370-14572 | ||||||||||||||||||
67 | if (!BN_sub(a, a, b)
| 0-14572 | ||||||||||||||||||
68 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
69 | if (!BN_rshift1(a, a)
| 0-14572 | ||||||||||||||||||
70 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
71 | if (BN_cmp(a, b) < 0
| 2563-12009 | ||||||||||||||||||
72 | t = a; | - | ||||||||||||||||||
73 | a = b; | - | ||||||||||||||||||
74 | b = t; | - | ||||||||||||||||||
75 | } executed 2563 times by 1 test: end of block Executed by:
| 2563 | ||||||||||||||||||
76 | } executed 14572 times by 1 test: else {end of block Executed by:
| 14572 | ||||||||||||||||||
77 | - | |||||||||||||||||||
78 | if (!BN_rshift1(b, b)
| 0-3370 | ||||||||||||||||||
79 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
80 | if (BN_cmp(a, b) < 0
| 0-3370 | ||||||||||||||||||
81 | t = a; | - | ||||||||||||||||||
82 | a = b; | - | ||||||||||||||||||
83 | b = t; | - | ||||||||||||||||||
84 | } never executed: end of block | 0 | ||||||||||||||||||
85 | } executed 3370 times by 1 test: end of block Executed by:
| 3370 | ||||||||||||||||||
86 | } else { | - | ||||||||||||||||||
87 | - | |||||||||||||||||||
88 | if (BN_is_odd(b)
| 29-11283 | ||||||||||||||||||
89 | if (!BN_rshift1(a, a)
| 0-11283 | ||||||||||||||||||
90 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
91 | if (BN_cmp(a, b) < 0
| 779-10504 | ||||||||||||||||||
92 | t = a; | - | ||||||||||||||||||
93 | a = b; | - | ||||||||||||||||||
94 | b = t; | - | ||||||||||||||||||
95 | } executed 779 times by 1 test: end of block Executed by:
| 779 | ||||||||||||||||||
96 | } executed 11283 times by 1 test: else {end of block Executed by:
| 11283 | ||||||||||||||||||
97 | - | |||||||||||||||||||
98 | if (!BN_rshift1(a, a)
| 0-29 | ||||||||||||||||||
99 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
100 | if (!BN_rshift1(b, b)
| 0-29 | ||||||||||||||||||
101 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
102 | shifts++; | - | ||||||||||||||||||
103 | } executed 29 times by 1 test: end of block Executed by:
| 29 | ||||||||||||||||||
104 | } | - | ||||||||||||||||||
105 | - | |||||||||||||||||||
106 | } | - | ||||||||||||||||||
107 | - | |||||||||||||||||||
108 | if (shifts
| 1-24 | ||||||||||||||||||
109 | if (!BN_lshift(a, a, shifts)
| 0-24 | ||||||||||||||||||
110 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
111 | } executed 24 times by 1 test: end of block Executed by:
| 24 | ||||||||||||||||||
112 | ; | - | ||||||||||||||||||
113 | return executed 25 times by 1 test: a;return a; Executed by:
executed 25 times by 1 test: return a; Executed by:
| 25 | ||||||||||||||||||
114 | err: | - | ||||||||||||||||||
115 | return never executed: return ((void *)0) ; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
116 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
117 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
118 | } | - | ||||||||||||||||||
119 | - | |||||||||||||||||||
120 | - | |||||||||||||||||||
121 | static BIGNUM *BN_mod_inverse_no_branch(BIGNUM *in, | - | ||||||||||||||||||
122 | const BIGNUM *a, const BIGNUM *n, | - | ||||||||||||||||||
123 | BN_CTX *ctx); | - | ||||||||||||||||||
124 | - | |||||||||||||||||||
125 | BIGNUM *BN_mod_inverse(BIGNUM *in, | - | ||||||||||||||||||
126 | const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx) | - | ||||||||||||||||||
127 | { | - | ||||||||||||||||||
128 | BIGNUM *rv; | - | ||||||||||||||||||
129 | int noinv; | - | ||||||||||||||||||
130 | rv = int_bn_mod_inverse(in, a, n, ctx, &noinv); | - | ||||||||||||||||||
131 | if (noinv
| 455-79056 | ||||||||||||||||||
132 | ERR_put_error(3,(110),(108),__FILE__,131); executed 455 times by 1 test: ERR_put_error(3,(110),(108),__FILE__,131); Executed by:
| 455 | ||||||||||||||||||
133 | return executed 79511 times by 2 tests: rv;return rv; Executed by:
executed 79511 times by 2 tests: return rv; Executed by:
| 79511 | ||||||||||||||||||
134 | } | - | ||||||||||||||||||
135 | - | |||||||||||||||||||
136 | BIGNUM *int_bn_mod_inverse(BIGNUM *in, | - | ||||||||||||||||||
137 | const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx, | - | ||||||||||||||||||
138 | int *pnoinv) | - | ||||||||||||||||||
139 | { | - | ||||||||||||||||||
140 | BIGNUM *A, *B, *X, *Y, *M, *D, *T, *R = | - | ||||||||||||||||||
141 | ((void *)0) | - | ||||||||||||||||||
142 | ; | - | ||||||||||||||||||
143 | BIGNUM *ret = | - | ||||||||||||||||||
144 | ((void *)0) | - | ||||||||||||||||||
145 | ; | - | ||||||||||||||||||
146 | int sign; | - | ||||||||||||||||||
147 | - | |||||||||||||||||||
148 | - | |||||||||||||||||||
149 | if (BN_abs_is_word(n, 1)
| 0-81259 | ||||||||||||||||||
150 | if (pnoinv !=
| 0-39 | ||||||||||||||||||
151 | ((void *)0)
| 0-39 | ||||||||||||||||||
152 | ) | - | ||||||||||||||||||
153 | * executed 39 times by 1 test: pnoinv = 1;*pnoinv = 1; Executed by:
executed 39 times by 1 test: *pnoinv = 1; Executed by:
| 39 | ||||||||||||||||||
154 | return executed 39 times by 1 test: return ((void *)0) ; Executed by:
executed 39 times by 1 test: return ((void *)0) ; Executed by:
| 39 | ||||||||||||||||||
155 | ((void *)0) executed 39 times by 1 test: return ((void *)0) ; Executed by:
| 39 | ||||||||||||||||||
156 | ; executed 39 times by 1 test: return ((void *)0) ; Executed by:
| 39 | ||||||||||||||||||
157 | } | - | ||||||||||||||||||
158 | - | |||||||||||||||||||
159 | if (pnoinv !=
| 0-81220 | ||||||||||||||||||
160 | ((void *)0)
| 0-81220 | ||||||||||||||||||
161 | ) | - | ||||||||||||||||||
162 | * executed 81220 times by 2 tests: pnoinv = 0;*pnoinv = 0; Executed by:
executed 81220 times by 2 tests: *pnoinv = 0; Executed by:
| 81220 | ||||||||||||||||||
163 | - | |||||||||||||||||||
164 | if ((
| 211-81009 | ||||||||||||||||||
165 | || (
| 10315-70694 | ||||||||||||||||||
166 | return executed 10526 times by 1 test: BN_mod_inverse_no_branch(in, a, n, ctx);return BN_mod_inverse_no_branch(in, a, n, ctx); Executed by:
executed 10526 times by 1 test: return BN_mod_inverse_no_branch(in, a, n, ctx); Executed by:
| 10526 | ||||||||||||||||||
167 | } | - | ||||||||||||||||||
168 | - | |||||||||||||||||||
169 | ; | - | ||||||||||||||||||
170 | ; | - | ||||||||||||||||||
171 | - | |||||||||||||||||||
172 | BN_CTX_start(ctx); | - | ||||||||||||||||||
173 | A = BN_CTX_get(ctx); | - | ||||||||||||||||||
174 | B = BN_CTX_get(ctx); | - | ||||||||||||||||||
175 | X = BN_CTX_get(ctx); | - | ||||||||||||||||||
176 | D = BN_CTX_get(ctx); | - | ||||||||||||||||||
177 | M = BN_CTX_get(ctx); | - | ||||||||||||||||||
178 | Y = BN_CTX_get(ctx); | - | ||||||||||||||||||
179 | T = BN_CTX_get(ctx); | - | ||||||||||||||||||
180 | if (T ==
| 0-70694 | ||||||||||||||||||
181 | ((void *)0)
| 0-70694 | ||||||||||||||||||
182 | ) | - | ||||||||||||||||||
183 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
184 | - | |||||||||||||||||||
185 | if (in ==
| 0-70694 | ||||||||||||||||||
186 | ((void *)0)
| 0-70694 | ||||||||||||||||||
187 | ) | - | ||||||||||||||||||
188 | R = BN_new(); never executed: R = BN_new(); | 0 | ||||||||||||||||||
189 | else | - | ||||||||||||||||||
190 | R = in; executed 70694 times by 2 tests: R = in; Executed by:
| 70694 | ||||||||||||||||||
191 | if (R ==
| 0-70694 | ||||||||||||||||||
192 | ((void *)0)
| 0-70694 | ||||||||||||||||||
193 | ) | - | ||||||||||||||||||
194 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
195 | - | |||||||||||||||||||
196 | (BN_set_word((X),1)); | - | ||||||||||||||||||
197 | (BN_set_word((Y),0)); | - | ||||||||||||||||||
198 | if (BN_copy(B, a) ==
| 0-70694 | ||||||||||||||||||
199 | ((void *)0)
| 0-70694 | ||||||||||||||||||
200 | ) | - | ||||||||||||||||||
201 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
202 | if (BN_copy(A, n) ==
| 0-70694 | ||||||||||||||||||
203 | ((void *)0)
| 0-70694 | ||||||||||||||||||
204 | ) | - | ||||||||||||||||||
205 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
206 | A->neg = 0; | - | ||||||||||||||||||
207 | if (B->neg
| 0-70694 | ||||||||||||||||||
208 | if (!BN_nnmod(B, B, A, ctx)
| 0-68387 | ||||||||||||||||||
209 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
210 | } executed 68387 times by 2 tests: end of block Executed by:
| 68387 | ||||||||||||||||||
211 | sign = -1; | - | ||||||||||||||||||
212 | if (BN_is_odd(n)
| 0-70143 | ||||||||||||||||||
213 | - | |||||||||||||||||||
214 | - | |||||||||||||||||||
215 | - | |||||||||||||||||||
216 | - | |||||||||||||||||||
217 | - | |||||||||||||||||||
218 | - | |||||||||||||||||||
219 | int shift; | - | ||||||||||||||||||
220 | - | |||||||||||||||||||
221 | while (!BN_is_zero(B)
| 70143-4775524 | ||||||||||||||||||
222 | shift = 0; | - | ||||||||||||||||||
223 | while (!BN_is_bit_set(B, shift)
| 1833163-4775524 | ||||||||||||||||||
224 | shift++; | - | ||||||||||||||||||
225 | - | |||||||||||||||||||
226 | if (BN_is_odd(X)
| 870111-963052 | ||||||||||||||||||
227 | if (!BN_uadd(X, X, n)
| 0-870111 | ||||||||||||||||||
228 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
229 | } executed 870111 times by 2 tests: end of block Executed by:
| 870111 | ||||||||||||||||||
230 | - | |||||||||||||||||||
231 | - | |||||||||||||||||||
232 | - | |||||||||||||||||||
233 | if (!BN_rshift1(X, X)
| 0-1833163 | ||||||||||||||||||
234 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
235 | } executed 1833163 times by 2 tests: end of block Executed by:
| 1833163 | ||||||||||||||||||
236 | if (shift > 0
| 1554190-3221334 | ||||||||||||||||||
237 | if (!BN_rshift(B, B, shift)
| 0-1554190 | ||||||||||||||||||
238 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
239 | } executed 1554190 times by 2 tests: end of block Executed by:
| 1554190 | ||||||||||||||||||
240 | - | |||||||||||||||||||
241 | - | |||||||||||||||||||
242 | - | |||||||||||||||||||
243 | - | |||||||||||||||||||
244 | shift = 0; | - | ||||||||||||||||||
245 | while (!BN_is_bit_set(A, shift)
| 3437183-4775524 | ||||||||||||||||||
246 | shift++; | - | ||||||||||||||||||
247 | - | |||||||||||||||||||
248 | if (BN_is_odd(Y)
| 1096353-2340830 | ||||||||||||||||||
249 | if (!BN_uadd(Y, Y, n)
| 0-2340830 | ||||||||||||||||||
250 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
251 | } executed 2340830 times by 2 tests: end of block Executed by:
| 2340830 | ||||||||||||||||||
252 | - | |||||||||||||||||||
253 | if (!BN_rshift1(Y, Y)
| 0-3437183 | ||||||||||||||||||
254 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
255 | } executed 3437183 times by 2 tests: end of block Executed by:
| 3437183 | ||||||||||||||||||
256 | if (shift > 0
| 1613783-3161741 | ||||||||||||||||||
257 | if (!BN_rshift(A, A, shift)
| 0-3161741 | ||||||||||||||||||
258 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
259 | } executed 3161741 times by 2 tests: end of block Executed by:
| 3161741 | ||||||||||||||||||
260 | if (BN_ucmp(B, A) >= 0
| 1613783-3161741 | ||||||||||||||||||
261 | - | |||||||||||||||||||
262 | if (!BN_uadd(X, X, Y)
| 0-1613783 | ||||||||||||||||||
263 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
264 | - | |||||||||||||||||||
265 | - | |||||||||||||||||||
266 | - | |||||||||||||||||||
267 | - | |||||||||||||||||||
268 | if (!BN_usub(B, B, A)
| 0-1613783 | ||||||||||||||||||
269 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
270 | } executed 1613783 times by 2 tests: else {end of block Executed by:
| 1613783 | ||||||||||||||||||
271 | - | |||||||||||||||||||
272 | if (!BN_uadd(Y, Y, X)
| 0-3161741 | ||||||||||||||||||
273 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
274 | - | |||||||||||||||||||
275 | - | |||||||||||||||||||
276 | - | |||||||||||||||||||
277 | if (!BN_usub(A, A, B)
| 0-3161741 | ||||||||||||||||||
278 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
279 | } executed 3161741 times by 2 tests: end of block Executed by:
| 3161741 | ||||||||||||||||||
280 | } | - | ||||||||||||||||||
281 | } executed 70143 times by 2 tests: else {end of block Executed by:
| 70143 | ||||||||||||||||||
282 | - | |||||||||||||||||||
283 | - | |||||||||||||||||||
284 | while (!BN_is_zero(B)
| 551-23007 | ||||||||||||||||||
285 | BIGNUM *tmp; | - | ||||||||||||||||||
286 | if (BN_num_bits(A) == BN_num_bits(B)
| 4676-18331 | ||||||||||||||||||
287 | if (!(BN_set_word((D),1))
| 0-4676 | ||||||||||||||||||
288 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
289 | if (!BN_sub(M, A, B)
| 0-4676 | ||||||||||||||||||
290 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
291 | } executed 4676 times by 1 test: else if (BN_num_bits(A) == BN_num_bits(B) + 1end of block Executed by:
| 4676-9861 | ||||||||||||||||||
292 | - | |||||||||||||||||||
293 | if (!BN_lshift1(T, B)
| 0-8470 | ||||||||||||||||||
294 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
295 | if (BN_ucmp(A, T) < 0
| 3710-4760 | ||||||||||||||||||
296 | - | |||||||||||||||||||
297 | if (!(BN_set_word((D),1))
| 0-4760 | ||||||||||||||||||
298 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
299 | if (!BN_sub(M, A, B)
| 0-4760 | ||||||||||||||||||
300 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
301 | } executed 4760 times by 1 test: else {end of block Executed by:
| 4760 | ||||||||||||||||||
302 | - | |||||||||||||||||||
303 | if (!BN_sub(M, A, T)
| 0-3710 | ||||||||||||||||||
304 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
305 | if (!BN_add(D, T, B)
| 0-3710 | ||||||||||||||||||
306 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
307 | if (BN_ucmp(A, D) < 0
| 632-3078 | ||||||||||||||||||
308 | - | |||||||||||||||||||
309 | if (!BN_set_word(D, 2)
| 0-3078 | ||||||||||||||||||
310 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
311 | - | |||||||||||||||||||
312 | - | |||||||||||||||||||
313 | - | |||||||||||||||||||
314 | } executed 3078 times by 1 test: else {end of block Executed by:
| 3078 | ||||||||||||||||||
315 | - | |||||||||||||||||||
316 | if (!BN_set_word(D, 3)
| 0-632 | ||||||||||||||||||
317 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
318 | - | |||||||||||||||||||
319 | - | |||||||||||||||||||
320 | - | |||||||||||||||||||
321 | if (!BN_sub(M, M, B)
| 0-632 | ||||||||||||||||||
322 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
323 | } executed 632 times by 1 test: end of block Executed by:
| 632 | ||||||||||||||||||
324 | } | - | ||||||||||||||||||
325 | } else { | - | ||||||||||||||||||
326 | if (!BN_div(D, M, A, B, ctx)
| 0-9861 | ||||||||||||||||||
327 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
328 | } executed 9861 times by 1 test: end of block Executed by:
| 9861 | ||||||||||||||||||
329 | tmp = A; | - | ||||||||||||||||||
330 | - | |||||||||||||||||||
331 | - | |||||||||||||||||||
332 | A = B; | - | ||||||||||||||||||
333 | B = M; | - | ||||||||||||||||||
334 | if (BN_is_one(D)
| 9436-13571 | ||||||||||||||||||
335 | if (!BN_add(tmp, X, Y)
| 0-9436 | ||||||||||||||||||
336 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
337 | } executed 9436 times by 1 test: else {end of block Executed by:
| 9436 | ||||||||||||||||||
338 | if (BN_is_word(D, 2)
| 4135-9436 | ||||||||||||||||||
339 | if (!BN_lshift1(tmp, X)
| 0-4135 | ||||||||||||||||||
340 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
341 | } executed 4135 times by 1 test: else if (BN_is_word(D, 4)end of block Executed by:
| 1560-7876 | ||||||||||||||||||
342 | if (!BN_lshift(tmp, X, 2)
| 0-1560 | ||||||||||||||||||
343 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
344 | } executed 1560 times by 1 test: else if (D->top == 1end of block Executed by:
| 6-7870 | ||||||||||||||||||
345 | if (!BN_copy(tmp, X)
| 0-7870 | ||||||||||||||||||
346 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
347 | if (!BN_mul_word(tmp, D->d[0])
| 0-7870 | ||||||||||||||||||
348 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
349 | } executed 7870 times by 1 test: else {end of block Executed by:
| 7870 | ||||||||||||||||||
350 | if (!BN_mul(tmp, D, X, ctx)
| 0-6 | ||||||||||||||||||
351 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
352 | } executed 6 times by 1 test: end of block Executed by:
| 6 | ||||||||||||||||||
353 | if (!BN_add(tmp, tmp, Y)
| 0-13571 | ||||||||||||||||||
354 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
355 | } executed 13571 times by 1 test: end of block Executed by:
| 13571 | ||||||||||||||||||
356 | - | |||||||||||||||||||
357 | M = Y; | - | ||||||||||||||||||
358 | Y = X; | - | ||||||||||||||||||
359 | X = tmp; | - | ||||||||||||||||||
360 | sign = -sign; | - | ||||||||||||||||||
361 | } executed 23007 times by 1 test: end of block Executed by:
| 23007 | ||||||||||||||||||
362 | } executed 551 times by 1 test: end of block Executed by:
| 551 | ||||||||||||||||||
363 | if (sign < 0
| 169-70525 | ||||||||||||||||||
364 | if (!BN_sub(Y, n, Y)
| 0-70525 | ||||||||||||||||||
365 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
366 | } executed 70525 times by 2 tests: end of block Executed by:
| 70525 | ||||||||||||||||||
367 | - | |||||||||||||||||||
368 | - | |||||||||||||||||||
369 | if (BN_is_one(A)
| 416-70278 | ||||||||||||||||||
370 | - | |||||||||||||||||||
371 | if (!Y->neg
| 0-45337 | ||||||||||||||||||
372 | if (!BN_copy(R, Y)
| 0-24941 | ||||||||||||||||||
373 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
374 | } executed 24941 times by 2 tests: else {end of block Executed by:
| 24941 | ||||||||||||||||||
375 | if (!BN_nnmod(R, Y, n, ctx)
| 0-45337 | ||||||||||||||||||
376 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
377 | } executed 45337 times by 2 tests: end of block Executed by:
| 45337 | ||||||||||||||||||
378 | } else { | - | ||||||||||||||||||
379 | if (pnoinv
| 0-416 | ||||||||||||||||||
380 | * executed 416 times by 1 test: pnoinv = 1;*pnoinv = 1; Executed by:
executed 416 times by 1 test: *pnoinv = 1; Executed by:
| 416 | ||||||||||||||||||
381 | goto executed 416 times by 1 test: err;goto err; Executed by:
executed 416 times by 1 test: goto err; Executed by:
| 416 | ||||||||||||||||||
382 | } | - | ||||||||||||||||||
383 | ret = R; | - | ||||||||||||||||||
384 | err: code before this statement executed 70278 times by 2 tests: err: Executed by:
| 70278 | ||||||||||||||||||
385 | if ((
| 416-70278 | ||||||||||||||||||
386 | ((void *)0)
| 416-70278 | ||||||||||||||||||
387 | )
| 0-70278 | ||||||||||||||||||
388 | ((void *)0)
| 0-416 | ||||||||||||||||||
389 | )
| 0-416 | ||||||||||||||||||
390 | BN_free(R); never executed: BN_free(R); | 0 | ||||||||||||||||||
391 | BN_CTX_end(ctx); | - | ||||||||||||||||||
392 | ; | - | ||||||||||||||||||
393 | return executed 70694 times by 2 tests: ret;return ret; Executed by:
executed 70694 times by 2 tests: return ret; Executed by:
| 70694 | ||||||||||||||||||
394 | } | - | ||||||||||||||||||
395 | - | |||||||||||||||||||
396 | - | |||||||||||||||||||
397 | - | |||||||||||||||||||
398 | - | |||||||||||||||||||
399 | - | |||||||||||||||||||
400 | static BIGNUM *BN_mod_inverse_no_branch(BIGNUM *in, | - | ||||||||||||||||||
401 | const BIGNUM *a, const BIGNUM *n, | - | ||||||||||||||||||
402 | BN_CTX *ctx) | - | ||||||||||||||||||
403 | { | - | ||||||||||||||||||
404 | BIGNUM *A, *B, *X, *Y, *M, *D, *T, *R = | - | ||||||||||||||||||
405 | ((void *)0) | - | ||||||||||||||||||
406 | ; | - | ||||||||||||||||||
407 | BIGNUM *ret = | - | ||||||||||||||||||
408 | ((void *)0) | - | ||||||||||||||||||
409 | ; | - | ||||||||||||||||||
410 | int sign; | - | ||||||||||||||||||
411 | - | |||||||||||||||||||
412 | ; | - | ||||||||||||||||||
413 | ; | - | ||||||||||||||||||
414 | - | |||||||||||||||||||
415 | BN_CTX_start(ctx); | - | ||||||||||||||||||
416 | A = BN_CTX_get(ctx); | - | ||||||||||||||||||
417 | B = BN_CTX_get(ctx); | - | ||||||||||||||||||
418 | X = BN_CTX_get(ctx); | - | ||||||||||||||||||
419 | D = BN_CTX_get(ctx); | - | ||||||||||||||||||
420 | M = BN_CTX_get(ctx); | - | ||||||||||||||||||
421 | Y = BN_CTX_get(ctx); | - | ||||||||||||||||||
422 | T = BN_CTX_get(ctx); | - | ||||||||||||||||||
423 | if (T ==
| 0-10526 | ||||||||||||||||||
424 | ((void *)0)
| 0-10526 | ||||||||||||||||||
425 | ) | - | ||||||||||||||||||
426 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
427 | - | |||||||||||||||||||
428 | if (in ==
| 64-10462 | ||||||||||||||||||
429 | ((void *)0)
| 64-10462 | ||||||||||||||||||
430 | ) | - | ||||||||||||||||||
431 | R = BN_new(); executed 64 times by 1 test: R = BN_new(); Executed by:
| 64 | ||||||||||||||||||
432 | else | - | ||||||||||||||||||
433 | R = in; executed 10462 times by 1 test: R = in; Executed by:
| 10462 | ||||||||||||||||||
434 | if (R ==
| 0-10526 | ||||||||||||||||||
435 | ((void *)0)
| 0-10526 | ||||||||||||||||||
436 | ) | - | ||||||||||||||||||
437 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
438 | - | |||||||||||||||||||
439 | (BN_set_word((X),1)); | - | ||||||||||||||||||
440 | (BN_set_word((Y),0)); | - | ||||||||||||||||||
441 | if (BN_copy(B, a) ==
| 0-10526 | ||||||||||||||||||
442 | ((void *)0)
| 0-10526 | ||||||||||||||||||
443 | ) | - | ||||||||||||||||||
444 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
445 | if (BN_copy(A, n) ==
| 0-10526 | ||||||||||||||||||
446 | ((void *)0)
| 0-10526 | ||||||||||||||||||
447 | ) | - | ||||||||||||||||||
448 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
449 | A->neg = 0; | - | ||||||||||||||||||
450 | - | |||||||||||||||||||
451 | if (B->neg
| 0-10526 | ||||||||||||||||||
452 | - | |||||||||||||||||||
453 | - | |||||||||||||||||||
454 | - | |||||||||||||||||||
455 | - | |||||||||||||||||||
456 | { | - | ||||||||||||||||||
457 | BIGNUM local_B; | - | ||||||||||||||||||
458 | bn_init(&local_B); | - | ||||||||||||||||||
459 | BN_with_flags(&local_B, B, 0x04); | - | ||||||||||||||||||
460 | if (!BN_nnmod(B, &local_B, A, ctx)
| 0-8676 | ||||||||||||||||||
461 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
462 | - | |||||||||||||||||||
463 | } | - | ||||||||||||||||||
464 | } executed 8676 times by 1 test: end of block Executed by:
| 8676 | ||||||||||||||||||
465 | sign = -1; | - | ||||||||||||||||||
466 | while (!BN_is_zero(B)
| 10526-2412196 | ||||||||||||||||||
467 | BIGNUM *tmp; | - | ||||||||||||||||||
468 | { | - | ||||||||||||||||||
469 | BIGNUM local_A; | - | ||||||||||||||||||
470 | bn_init(&local_A); | - | ||||||||||||||||||
471 | BN_with_flags(&local_A, A, 0x04); | - | ||||||||||||||||||
472 | - | |||||||||||||||||||
473 | - | |||||||||||||||||||
474 | if (!BN_div(D, M, &local_A, B, ctx)
| 0-2412196 | ||||||||||||||||||
475 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
476 | - | |||||||||||||||||||
477 | } | - | ||||||||||||||||||
478 | tmp = A; | - | ||||||||||||||||||
479 | - | |||||||||||||||||||
480 | - | |||||||||||||||||||
481 | - | |||||||||||||||||||
482 | A = B; | - | ||||||||||||||||||
483 | B = M; | - | ||||||||||||||||||
484 | if (!BN_mul(tmp, D, X, ctx)
| 0-2412196 | ||||||||||||||||||
485 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
486 | if (!BN_add(tmp, tmp, Y)
| 0-2412196 | ||||||||||||||||||
487 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
488 | - | |||||||||||||||||||
489 | M = Y; | - | ||||||||||||||||||
490 | - | |||||||||||||||||||
491 | Y = X; | - | ||||||||||||||||||
492 | X = tmp; | - | ||||||||||||||||||
493 | sign = -sign; | - | ||||||||||||||||||
494 | } executed 2412196 times by 1 test: end of block Executed by:
| 2412196 | ||||||||||||||||||
495 | if (sign < 0
| 3386-7140 | ||||||||||||||||||
496 | if (!BN_sub(Y, n, Y)
| 0-7140 | ||||||||||||||||||
497 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
498 | } executed 7140 times by 1 test: end of block Executed by:
| 7140 | ||||||||||||||||||
499 | - | |||||||||||||||||||
500 | - | |||||||||||||||||||
501 | if (BN_is_one(A)
| 0-10526 | ||||||||||||||||||
502 | - | |||||||||||||||||||
503 | if (!Y->neg
| 0-10526 | ||||||||||||||||||
504 | if (!BN_copy(R, Y)
| 0-10526 | ||||||||||||||||||
505 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
506 | } executed 10526 times by 1 test: else {end of block Executed by:
| 10526 | ||||||||||||||||||
507 | if (!BN_nnmod(R, Y, n, ctx)
| 0 | ||||||||||||||||||
508 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
509 | } never executed: end of block | 0 | ||||||||||||||||||
510 | } else { | - | ||||||||||||||||||
511 | ERR_put_error(3,(139),(108),__FILE__,613); | - | ||||||||||||||||||
512 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
513 | } | - | ||||||||||||||||||
514 | ret = R; | - | ||||||||||||||||||
515 | err: code before this statement executed 10526 times by 1 test: err: Executed by:
| 10526 | ||||||||||||||||||
516 | if ((
| 0-10526 | ||||||||||||||||||
517 | ((void *)0)
| 0-10526 | ||||||||||||||||||
518 | )
| 0-10526 | ||||||||||||||||||
519 | ((void *)0)
| 0 | ||||||||||||||||||
520 | )
| 0 | ||||||||||||||||||
521 | BN_free(R); never executed: BN_free(R); | 0 | ||||||||||||||||||
522 | BN_CTX_end(ctx); | - | ||||||||||||||||||
523 | ; | - | ||||||||||||||||||
524 | return executed 10526 times by 1 test: ret;return ret; Executed by:
executed 10526 times by 1 test: return ret; Executed by:
| 10526 | ||||||||||||||||||
525 | } | - | ||||||||||||||||||
Switch to Source code | Preprocessed file |