Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/bn/bn_exp2.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
2 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
3 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
4 | int BN_mod_exp2_mont(BIGNUM *rr, const BIGNUM *a1, const BIGNUM *p1, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
5 | const BIGNUM *a2, const BIGNUM *p2, const BIGNUM *m, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
6 | BN_CTX *ctx, BN_MONT_CTX *in_mont) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
7 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
8 | int i, j, bits, b, bits1, bits2, ret = | - | ||||||||||||||||||||||||||||||||||||||||||||||||
9 | 0, wpos1, wpos2, window1, window2, wvalue1, wvalue2; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
10 | int r_is_one = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
11 | BIGNUM *d, *r; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
12 | const BIGNUM *a_mod_m; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
13 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
14 | BIGNUM *val1[32], *val2[32]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
15 | BN_MONT_CTX *mont = | - | ||||||||||||||||||||||||||||||||||||||||||||||||
16 | ((void *)0) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
17 | ; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
18 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
19 | ; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
20 | ; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
21 | ; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
22 | ; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
23 | ; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
24 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
25 | if (!(m->d[0] & 1)
| 0-283 | ||||||||||||||||||||||||||||||||||||||||||||||||
26 | ERR_put_error(3,(118),(102),__FILE__,36); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
27 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
28 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
29 | bits1 = BN_num_bits(p1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
30 | bits2 = BN_num_bits(p2); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
31 | if ((
| 0-283 | ||||||||||||||||||||||||||||||||||||||||||||||||
32 | ret = (BN_set_word((rr),1)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
33 | return never executed: ret;return ret; never executed: return ret; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
34 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
35 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
36 | bits = (
| 88-195 | ||||||||||||||||||||||||||||||||||||||||||||||||
37 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
38 | BN_CTX_start(ctx); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
39 | d = BN_CTX_get(ctx); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
40 | r = BN_CTX_get(ctx); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
41 | val1[0] = BN_CTX_get(ctx); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
42 | val2[0] = BN_CTX_get(ctx); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
43 | if (val2[0] ==
| 0-283 | ||||||||||||||||||||||||||||||||||||||||||||||||
44 | ((void *)0)
| 0-283 | ||||||||||||||||||||||||||||||||||||||||||||||||
45 | ) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
46 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
47 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
48 | if (in_mont !=
| 0-283 | ||||||||||||||||||||||||||||||||||||||||||||||||
49 | ((void *)0)
| 0-283 | ||||||||||||||||||||||||||||||||||||||||||||||||
50 | ) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
51 | mont = in_mont; executed 283 times by 1 test: mont = in_mont; Executed by:
| 283 | ||||||||||||||||||||||||||||||||||||||||||||||||
52 | else { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
53 | if ((
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
54 | ((void *)0)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
55 | ) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
56 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
57 | if (!BN_MONT_CTX_set(mont, m, ctx)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
58 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
59 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
60 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
61 | window1 = ((
| 0-283 | ||||||||||||||||||||||||||||||||||||||||||||||||
62 | window2 = ((
| 0-283 | ||||||||||||||||||||||||||||||||||||||||||||||||
63 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
64 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
65 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
66 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
67 | if (a1->neg
| 0-283 | ||||||||||||||||||||||||||||||||||||||||||||||||
68 | if (!BN_div(
| 0-120 | ||||||||||||||||||||||||||||||||||||||||||||||||
69 | ((void *)0)
| 0-120 | ||||||||||||||||||||||||||||||||||||||||||||||||
70 | ,(val1[0]),(a1),(m),(ctx))
| 0-120 | ||||||||||||||||||||||||||||||||||||||||||||||||
71 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
72 | a_mod_m = val1[0]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
73 | } executed 120 times by 1 test: elseend of block Executed by:
| 120 | ||||||||||||||||||||||||||||||||||||||||||||||||
74 | a_mod_m = a1; executed 163 times by 1 test: a_mod_m = a1; Executed by:
| 163 | ||||||||||||||||||||||||||||||||||||||||||||||||
75 | if (BN_is_zero(a_mod_m)
| 1-282 | ||||||||||||||||||||||||||||||||||||||||||||||||
76 | (BN_set_word((rr),0)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
77 | ret = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
78 | goto executed 1 time by 1 test: err;goto err; Executed by:
executed 1 time by 1 test: goto err; Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
79 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
80 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
81 | if (!BN_to_montgomery(val1[0], a_mod_m, mont, ctx)
| 0-282 | ||||||||||||||||||||||||||||||||||||||||||||||||
82 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
83 | if (window1 > 1
| 0-282 | ||||||||||||||||||||||||||||||||||||||||||||||||
84 | if (!BN_mod_mul_montgomery(d, val1[0], val1[0], mont, ctx)
| 0-282 | ||||||||||||||||||||||||||||||||||||||||||||||||
85 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
86 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
87 | j = 1 << (window1 - 1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
88 | for (i = 1; i < j
| 282-2494 | ||||||||||||||||||||||||||||||||||||||||||||||||
89 | if (((
| 0-2494 | ||||||||||||||||||||||||||||||||||||||||||||||||
90 | ((void *)0)
| 0-2494 | ||||||||||||||||||||||||||||||||||||||||||||||||
91 | )
| 0-2494 | ||||||||||||||||||||||||||||||||||||||||||||||||
92 | !BN_mod_mul_montgomery(val1[i], val1[i - 1], d, mont, ctx)
| 0-2494 | ||||||||||||||||||||||||||||||||||||||||||||||||
93 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
94 | } executed 2494 times by 1 test: end of block Executed by:
| 2494 | ||||||||||||||||||||||||||||||||||||||||||||||||
95 | } executed 282 times by 1 test: end of block Executed by:
| 282 | ||||||||||||||||||||||||||||||||||||||||||||||||
96 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
97 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
98 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
99 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
100 | if (a2->neg
| 1-208 | ||||||||||||||||||||||||||||||||||||||||||||||||
101 | if (!BN_div(
| 0-75 | ||||||||||||||||||||||||||||||||||||||||||||||||
102 | ((void *)0)
| 0-75 | ||||||||||||||||||||||||||||||||||||||||||||||||
103 | ,(val2[0]),(a2),(m),(ctx))
| 0-75 | ||||||||||||||||||||||||||||||||||||||||||||||||
104 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
105 | a_mod_m = val2[0]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
106 | } executed 75 times by 1 test: elseend of block Executed by:
| 75 | ||||||||||||||||||||||||||||||||||||||||||||||||
107 | a_mod_m = a2; executed 207 times by 1 test: a_mod_m = a2; Executed by:
| 207 | ||||||||||||||||||||||||||||||||||||||||||||||||
108 | if (BN_is_zero(a_mod_m)
| 2-280 | ||||||||||||||||||||||||||||||||||||||||||||||||
109 | (BN_set_word((rr),0)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
110 | ret = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
111 | goto executed 2 times by 1 test: err;goto err; Executed by:
executed 2 times by 1 test: goto err; Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||||||||
112 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
113 | if (!BN_to_montgomery(val2[0], a_mod_m, mont, ctx)
| 0-280 | ||||||||||||||||||||||||||||||||||||||||||||||||
114 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
115 | if (window2 > 1
| 4-276 | ||||||||||||||||||||||||||||||||||||||||||||||||
116 | if (!BN_mod_mul_montgomery(d, val2[0], val2[0], mont, ctx)
| 0-276 | ||||||||||||||||||||||||||||||||||||||||||||||||
117 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
118 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
119 | j = 1 << (window2 - 1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
120 | for (i = 1; i < j
| 276-2448 | ||||||||||||||||||||||||||||||||||||||||||||||||
121 | if (((
| 0-2448 | ||||||||||||||||||||||||||||||||||||||||||||||||
122 | ((void *)0)
| 0-2448 | ||||||||||||||||||||||||||||||||||||||||||||||||
123 | )
| 0-2448 | ||||||||||||||||||||||||||||||||||||||||||||||||
124 | !BN_mod_mul_montgomery(val2[i], val2[i - 1], d, mont, ctx)
| 0-2448 | ||||||||||||||||||||||||||||||||||||||||||||||||
125 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
126 | } executed 2448 times by 1 test: end of block Executed by:
| 2448 | ||||||||||||||||||||||||||||||||||||||||||||||||
127 | } executed 276 times by 1 test: end of block Executed by:
| 276 | ||||||||||||||||||||||||||||||||||||||||||||||||
128 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
129 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
130 | r_is_one = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
131 | wvalue1 = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
132 | wvalue2 = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
133 | wpos1 = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
134 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
135 | wpos2 = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
136 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
137 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
138 | if (!BN_to_montgomery(r, BN_value_one(), mont, ctx)
| 0-280 | ||||||||||||||||||||||||||||||||||||||||||||||||
139 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
140 | for (b = bits - 1; b >= 0
| 280-63046 | ||||||||||||||||||||||||||||||||||||||||||||||||
141 | if (!r_is_one
| 769-62277 | ||||||||||||||||||||||||||||||||||||||||||||||||
142 | if (!BN_mod_mul_montgomery(r, r, r, mont, ctx)
| 0-62277 | ||||||||||||||||||||||||||||||||||||||||||||||||
143 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
144 | } executed 62277 times by 1 test: end of block Executed by:
| 62277 | ||||||||||||||||||||||||||||||||||||||||||||||||
145 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
146 | if (!wvalue1
| 27678-35368 | ||||||||||||||||||||||||||||||||||||||||||||||||
147 | if (BN_is_bit_set(p1, b)
| 12021-23347 | ||||||||||||||||||||||||||||||||||||||||||||||||
148 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
149 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
150 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
151 | i = b - window1 + 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
152 | while (!BN_is_bit_set(p1, i)
| 11171-12021 | ||||||||||||||||||||||||||||||||||||||||||||||||
153 | i++; executed 11171 times by 1 test: i++; Executed by:
| 11171 | ||||||||||||||||||||||||||||||||||||||||||||||||
154 | wpos1 = i; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
155 | wvalue1 = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
156 | for (i = b - 1; i >= wpos1
| 12021-27678 | ||||||||||||||||||||||||||||||||||||||||||||||||
157 | wvalue1 <<= 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
158 | if (BN_is_bit_set(p1, i)
| 8434-19244 | ||||||||||||||||||||||||||||||||||||||||||||||||
159 | wvalue1++; executed 19244 times by 1 test: wvalue1++; Executed by:
| 19244 | ||||||||||||||||||||||||||||||||||||||||||||||||
160 | } executed 27678 times by 1 test: end of block Executed by:
| 27678 | ||||||||||||||||||||||||||||||||||||||||||||||||
161 | } executed 12021 times by 1 test: end of block Executed by:
| 12021 | ||||||||||||||||||||||||||||||||||||||||||||||||
162 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
163 | if (!wvalue2
| 27208-35838 | ||||||||||||||||||||||||||||||||||||||||||||||||
164 | if (BN_is_bit_set(p2, b)
| 11811-24027 | ||||||||||||||||||||||||||||||||||||||||||||||||
165 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
166 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
167 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
168 | i = b - window2 + 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
169 | while (!BN_is_bit_set(p2, i)
| 10992-11811 | ||||||||||||||||||||||||||||||||||||||||||||||||
170 | i++; executed 10992 times by 1 test: i++; Executed by:
| 10992 | ||||||||||||||||||||||||||||||||||||||||||||||||
171 | wpos2 = i; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
172 | wvalue2 = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
173 | for (i = b - 1; i >= wpos2
| 11811-27208 | ||||||||||||||||||||||||||||||||||||||||||||||||
174 | wvalue2 <<= 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
175 | if (BN_is_bit_set(p2, i)
| 8612-18596 | ||||||||||||||||||||||||||||||||||||||||||||||||
176 | wvalue2++; executed 18596 times by 1 test: wvalue2++; Executed by:
| 18596 | ||||||||||||||||||||||||||||||||||||||||||||||||
177 | } executed 27208 times by 1 test: end of block Executed by:
| 27208 | ||||||||||||||||||||||||||||||||||||||||||||||||
178 | } executed 11811 times by 1 test: end of block Executed by:
| 11811 | ||||||||||||||||||||||||||||||||||||||||||||||||
179 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
180 | if (wvalue1
| 12021-39699 | ||||||||||||||||||||||||||||||||||||||||||||||||
181 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
182 | if (!BN_mod_mul_montgomery(r, r, val1[wvalue1 >> 1], mont, ctx)
| 0-12021 | ||||||||||||||||||||||||||||||||||||||||||||||||
183 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
184 | wvalue1 = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
185 | r_is_one = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
186 | } executed 12021 times by 1 test: end of block Executed by:
| 12021 | ||||||||||||||||||||||||||||||||||||||||||||||||
187 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
188 | if (wvalue2
| 11811-39019 | ||||||||||||||||||||||||||||||||||||||||||||||||
189 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
190 | if (!BN_mod_mul_montgomery(r, r, val2[wvalue2 >> 1], mont, ctx)
| 0-11811 | ||||||||||||||||||||||||||||||||||||||||||||||||
191 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
192 | wvalue2 = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
193 | r_is_one = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
194 | } executed 11811 times by 1 test: end of block Executed by:
| 11811 | ||||||||||||||||||||||||||||||||||||||||||||||||
195 | } executed 63046 times by 1 test: end of block Executed by:
| 63046 | ||||||||||||||||||||||||||||||||||||||||||||||||
196 | if (!BN_from_montgomery(rr, r, mont, ctx)
| 0-280 | ||||||||||||||||||||||||||||||||||||||||||||||||
197 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
198 | ret = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
199 | err: code before this statement executed 280 times by 1 test: err: Executed by:
| 280 | ||||||||||||||||||||||||||||||||||||||||||||||||
200 | if (in_mont ==
| 0-283 | ||||||||||||||||||||||||||||||||||||||||||||||||
201 | ((void *)0)
| 0-283 | ||||||||||||||||||||||||||||||||||||||||||||||||
202 | ) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
203 | BN_MONT_CTX_free(mont); never executed: BN_MONT_CTX_free(mont); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
204 | BN_CTX_end(ctx); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
205 | ; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
206 | return executed 283 times by 1 test: ret;return ret; Executed by:
executed 283 times by 1 test: return ret; Executed by:
| 283 | ||||||||||||||||||||||||||||||||||||||||||||||||
207 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
Switch to Source code | Preprocessed file |