Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/bn/bn_mod.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx) | - | ||||||||||||
3 | { | - | ||||||||||||
4 | - | |||||||||||||
5 | - | |||||||||||||
6 | - | |||||||||||||
7 | - | |||||||||||||
8 | - | |||||||||||||
9 | if (!(BN_div(
| 2-4223126 | ||||||||||||
10 | ((void *)0)
| 2-4223126 | ||||||||||||
11 | ,(r),(m),(d),(ctx)))
| 2-4223126 | ||||||||||||
12 | return executed 2 times by 1 test: 0;return 0; Executed by:
executed 2 times by 1 test: return 0; Executed by:
| 2 | ||||||||||||
13 | if (!r->neg
| 46681-4176445 | ||||||||||||
14 | return executed 4176445 times by 2 tests: 1;return 1; Executed by:
executed 4176445 times by 2 tests: return 1; Executed by:
| 4176445 | ||||||||||||
15 | - | |||||||||||||
16 | return executed 46681 times by 2 tests: (d->negreturn (d->neg ? BN_sub : BN_add) (r, r, d); Executed by:
executed 46681 times by 2 tests: return (d->neg ? BN_sub : BN_add) (r, r, d); Executed by:
| 208-46681 | ||||||||||||
17 | } | - | ||||||||||||
18 | - | |||||||||||||
19 | int BN_mod_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, | - | ||||||||||||
20 | BN_CTX *ctx) | - | ||||||||||||
21 | { | - | ||||||||||||
22 | if (!BN_add(r, a, b)
| 0-104 | ||||||||||||
23 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
24 | return executed 104 times by 2 tests: BN_nnmod(r, r, m, ctx);return BN_nnmod(r, r, m, ctx); Executed by:
executed 104 times by 2 tests: return BN_nnmod(r, r, m, ctx); Executed by:
| 104 | ||||||||||||
25 | } | - | ||||||||||||
26 | int bn_mod_add_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, | - | ||||||||||||
27 | const BIGNUM *m) | - | ||||||||||||
28 | { | - | ||||||||||||
29 | size_t i, ai, bi, mtop = m->top; | - | ||||||||||||
30 | unsigned long storage[1024 / (8 * 8)]; | - | ||||||||||||
31 | unsigned long carry, temp, mask, *rp, *tp = storage; | - | ||||||||||||
32 | const unsigned long *ap, *bp; | - | ||||||||||||
33 | - | |||||||||||||
34 | if (bn_wexpand(r, mtop) ==
| 0-4337421 | ||||||||||||
35 | ((void *)0)
| 0-4337421 | ||||||||||||
36 | ) | - | ||||||||||||
37 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
38 | - | |||||||||||||
39 | if (mtop > sizeof(storage) / sizeof(storage[0])
| 1868-4335553 | ||||||||||||
40 | && (
| 0-1868 | ||||||||||||
41 | ((void *)0)
| 0-1868 | ||||||||||||
42 | ) | - | ||||||||||||
43 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
44 | - | |||||||||||||
45 | ap = a->d !=
| 0-4337421 | ||||||||||||
46 | ((void *)0)
| 0-4337421 | ||||||||||||
47 | ? a->d : tp; | - | ||||||||||||
48 | bp = b->d !=
| 298-4337123 | ||||||||||||
49 | ((void *)0)
| 298-4337123 | ||||||||||||
50 | ? b->d : tp; | - | ||||||||||||
51 | - | |||||||||||||
52 | for (i = 0, ai = 0, bi = 0, carry = 0; i < mtop
| 4337421-27221631 | ||||||||||||
53 | mask = (unsigned long)0 - ((i - a->top) >> (8 * sizeof(i) - 1)); | - | ||||||||||||
54 | temp = ((ap[ai] & mask) + carry) & (0xffffffffffffffffL); | - | ||||||||||||
55 | carry = (temp < carry); | - | ||||||||||||
56 | - | |||||||||||||
57 | mask = (unsigned long)0 - ((i - b->top) >> (8 * sizeof(i) - 1)); | - | ||||||||||||
58 | tp[i] = ((bp[bi] & mask) + temp) & (0xffffffffffffffffL); | - | ||||||||||||
59 | carry += (tp[i] < temp); | - | ||||||||||||
60 | - | |||||||||||||
61 | i++; | - | ||||||||||||
62 | ai += (i - a->dmax) >> (8 * sizeof(i) - 1); | - | ||||||||||||
63 | bi += (i - b->dmax) >> (8 * sizeof(i) - 1); | - | ||||||||||||
64 | } executed 27221631 times by 2 tests: end of block Executed by:
| 27221631 | ||||||||||||
65 | rp = r->d; | - | ||||||||||||
66 | carry -= bn_sub_words(rp, tp, m->d, mtop); | - | ||||||||||||
67 | for (i = 0; i < mtop
| 4337421-27221631 | ||||||||||||
68 | rp[i] = (carry & tp[i]) | (~carry & rp[i]); | - | ||||||||||||
69 | ((volatile unsigned long *)tp)[i] = 0; | - | ||||||||||||
70 | } executed 27221631 times by 2 tests: end of block Executed by:
| 27221631 | ||||||||||||
71 | r->top = mtop; | - | ||||||||||||
72 | r->flags |= 0; | - | ||||||||||||
73 | r->neg = 0; | - | ||||||||||||
74 | - | |||||||||||||
75 | if (tp != storage
| 1868-4335553 | ||||||||||||
76 | CRYPTO_free(tp, __FILE__, 90); executed 1868 times by 1 test: CRYPTO_free(tp, __FILE__, 90); Executed by:
| 1868 | ||||||||||||
77 | - | |||||||||||||
78 | return executed 4337421 times by 2 tests: 1;return 1; Executed by:
executed 4337421 times by 2 tests: return 1; Executed by:
| 4337421 | ||||||||||||
79 | } | - | ||||||||||||
80 | - | |||||||||||||
81 | int BN_mod_add_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, | - | ||||||||||||
82 | const BIGNUM *m) | - | ||||||||||||
83 | { | - | ||||||||||||
84 | int ret = bn_mod_add_fixed_top(r, a, b, m); | - | ||||||||||||
85 | - | |||||||||||||
86 | if (ret
| 0-4334680 | ||||||||||||
87 | bn_correct_top(r); executed 4334680 times by 2 tests: bn_correct_top(r); Executed by:
| 4334680 | ||||||||||||
88 | - | |||||||||||||
89 | return executed 4334680 times by 2 tests: ret;return ret; Executed by:
executed 4334680 times by 2 tests: return ret; Executed by:
| 4334680 | ||||||||||||
90 | } | - | ||||||||||||
91 | - | |||||||||||||
92 | int BN_mod_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, | - | ||||||||||||
93 | BN_CTX *ctx) | - | ||||||||||||
94 | { | - | ||||||||||||
95 | if (!BN_sub(r, a, b)
| 0-13 | ||||||||||||
96 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
97 | return executed 13 times by 1 test: BN_nnmod(r, r, m, ctx);return BN_nnmod(r, r, m, ctx); Executed by:
executed 13 times by 1 test: return BN_nnmod(r, r, m, ctx); Executed by:
| 13 | ||||||||||||
98 | } | - | ||||||||||||
99 | int bn_mod_sub_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, | - | ||||||||||||
100 | const BIGNUM *m) | - | ||||||||||||
101 | { | - | ||||||||||||
102 | size_t i, ai, bi, mtop = m->top; | - | ||||||||||||
103 | unsigned long borrow, carry, ta, tb, mask, *rp; | - | ||||||||||||
104 | const unsigned long *ap, *bp; | - | ||||||||||||
105 | - | |||||||||||||
106 | if (bn_wexpand(r, mtop) ==
| 0-2374 | ||||||||||||
107 | ((void *)0)
| 0-2374 | ||||||||||||
108 | ) | - | ||||||||||||
109 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
110 | - | |||||||||||||
111 | rp = r->d; | - | ||||||||||||
112 | ap = a->d !=
| 0-2374 | ||||||||||||
113 | ((void *)0)
| 0-2374 | ||||||||||||
114 | ? a->d : rp; | - | ||||||||||||
115 | bp = b->d !=
| 0-2374 | ||||||||||||
116 | ((void *)0)
| 0-2374 | ||||||||||||
117 | ? b->d : rp; | - | ||||||||||||
118 | - | |||||||||||||
119 | for (i = 0, ai = 0, bi = 0, borrow = 0; i < mtop
| 2374-32678 | ||||||||||||
120 | mask = (unsigned long)0 - ((i - a->top) >> (8 * sizeof(i) - 1)); | - | ||||||||||||
121 | ta = ap[ai] & mask; | - | ||||||||||||
122 | - | |||||||||||||
123 | mask = (unsigned long)0 - ((i - b->top) >> (8 * sizeof(i) - 1)); | - | ||||||||||||
124 | tb = bp[bi] & mask; | - | ||||||||||||
125 | rp[i] = ta - tb - borrow; | - | ||||||||||||
126 | if (ta != tb
| 43-32635 | ||||||||||||
127 | borrow = (ta < tb); executed 32635 times by 1 test: borrow = (ta < tb); Executed by:
| 32635 | ||||||||||||
128 | - | |||||||||||||
129 | i++; | - | ||||||||||||
130 | ai += (i - a->dmax) >> (8 * sizeof(i) - 1); | - | ||||||||||||
131 | bi += (i - b->dmax) >> (8 * sizeof(i) - 1); | - | ||||||||||||
132 | } executed 32678 times by 1 test: end of block Executed by:
| 32678 | ||||||||||||
133 | ap = m->d; | - | ||||||||||||
134 | for (i = 0, mask = 0 - borrow, carry = 0; i < mtop
| 2374-32678 | ||||||||||||
135 | ta = ((ap[i] & mask) + carry) & (0xffffffffffffffffL); | - | ||||||||||||
136 | carry = (ta < carry); | - | ||||||||||||
137 | rp[i] = (rp[i] + ta) & (0xffffffffffffffffL); | - | ||||||||||||
138 | carry += (rp[i] < ta); | - | ||||||||||||
139 | } executed 32678 times by 1 test: end of block Executed by:
| 32678 | ||||||||||||
140 | borrow -= carry; | - | ||||||||||||
141 | for (i = 0, mask = 0 - borrow, carry = 0; i < mtop
| 2374-32678 | ||||||||||||
142 | ta = ((ap[i] & mask) + carry) & (0xffffffffffffffffL); | - | ||||||||||||
143 | carry = (ta < carry); | - | ||||||||||||
144 | rp[i] = (rp[i] + ta) & (0xffffffffffffffffL); | - | ||||||||||||
145 | carry += (rp[i] < ta); | - | ||||||||||||
146 | } executed 32678 times by 1 test: end of block Executed by:
| 32678 | ||||||||||||
147 | - | |||||||||||||
148 | r->top = mtop; | - | ||||||||||||
149 | r->flags |= 0; | - | ||||||||||||
150 | r->neg = 0; | - | ||||||||||||
151 | - | |||||||||||||
152 | return executed 2374 times by 1 test: 1;return 1; Executed by:
executed 2374 times by 1 test: return 1; Executed by:
| 2374 | ||||||||||||
153 | } | - | ||||||||||||
154 | - | |||||||||||||
155 | - | |||||||||||||
156 | - | |||||||||||||
157 | - | |||||||||||||
158 | - | |||||||||||||
159 | int BN_mod_sub_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, | - | ||||||||||||
160 | const BIGNUM *m) | - | ||||||||||||
161 | { | - | ||||||||||||
162 | if (!BN_sub(r, a, b)
| 0-4650717 | ||||||||||||
163 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
164 | if (r->neg
| 2309212-2341505 | ||||||||||||
165 | return executed 2309212 times by 2 tests: BN_add(r, r, m);return BN_add(r, r, m); Executed by:
executed 2309212 times by 2 tests: return BN_add(r, r, m); Executed by:
| 2309212 | ||||||||||||
166 | return executed 2341505 times by 2 tests: 1;return 1; Executed by:
executed 2341505 times by 2 tests: return 1; Executed by:
| 2341505 | ||||||||||||
167 | } | - | ||||||||||||
168 | - | |||||||||||||
169 | - | |||||||||||||
170 | int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, | - | ||||||||||||
171 | BN_CTX *ctx) | - | ||||||||||||
172 | { | - | ||||||||||||
173 | BIGNUM *t; | - | ||||||||||||
174 | int ret = 0; | - | ||||||||||||
175 | - | |||||||||||||
176 | ; | - | ||||||||||||
177 | ; | - | ||||||||||||
178 | ; | - | ||||||||||||
179 | - | |||||||||||||
180 | BN_CTX_start(ctx); | - | ||||||||||||
181 | if ((
| 0-3791466 | ||||||||||||
182 | ((void *)0)
| 0-3791466 | ||||||||||||
183 | ) | - | ||||||||||||
184 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
185 | if (a == b
| 189583-3601883 | ||||||||||||
186 | if (!BN_sqr(t, a, ctx)
| 0-3601883 | ||||||||||||
187 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
188 | } executed 3601883 times by 1 test: else {end of block Executed by:
| 3601883 | ||||||||||||
189 | if (!BN_mul(t, a, b, ctx)
| 0-189583 | ||||||||||||
190 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
191 | } executed 189583 times by 2 tests: end of block Executed by:
| 189583 | ||||||||||||
192 | if (!BN_nnmod(r, t, m, ctx)
| 1-3791465 | ||||||||||||
193 | goto executed 1 time by 1 test: err;goto err; Executed by:
executed 1 time by 1 test: goto err; Executed by:
| 1 | ||||||||||||
194 | ; | - | ||||||||||||
195 | ret = 1; | - | ||||||||||||
196 | err: code before this statement executed 3791465 times by 2 tests: err: Executed by:
| 3791465 | ||||||||||||
197 | BN_CTX_end(ctx); | - | ||||||||||||
198 | return executed 3791466 times by 2 tests: ret;return ret; Executed by:
executed 3791466 times by 2 tests: return ret; Executed by:
| 3791466 | ||||||||||||
199 | } | - | ||||||||||||
200 | - | |||||||||||||
201 | int BN_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx) | - | ||||||||||||
202 | { | - | ||||||||||||
203 | if (!BN_sqr(r, a, ctx)
| 0-147879 | ||||||||||||
204 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
205 | - | |||||||||||||
206 | return executed 147879 times by 2 tests: BN_div(return BN_div( ((void *)0) ,(r),(r),(m),(ctx)); Executed by:
executed 147879 times by 2 tests: return BN_div( ((void *)0) ,(r),(r),(m),(ctx)); Executed by:
| 147879 | ||||||||||||
207 | ((void *)0) executed 147879 times by 2 tests: return BN_div( ((void *)0) ,(r),(r),(m),(ctx)); Executed by:
| 147879 | ||||||||||||
208 | ,(r),(r),(m),(ctx)); executed 147879 times by 2 tests: return BN_div( ((void *)0) ,(r),(r),(m),(ctx)); Executed by:
| 147879 | ||||||||||||
209 | } | - | ||||||||||||
210 | - | |||||||||||||
211 | int BN_mod_lshift1(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx) | - | ||||||||||||
212 | { | - | ||||||||||||
213 | if (!BN_lshift1(r, a)
| 0 | ||||||||||||
214 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
215 | ; | - | ||||||||||||
216 | return never executed: BN_nnmod(r, r, m, ctx);return BN_nnmod(r, r, m, ctx); never executed: return BN_nnmod(r, r, m, ctx); | 0 | ||||||||||||
217 | } | - | ||||||||||||
218 | - | |||||||||||||
219 | - | |||||||||||||
220 | - | |||||||||||||
221 | - | |||||||||||||
222 | - | |||||||||||||
223 | int BN_mod_lshift1_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *m) | - | ||||||||||||
224 | { | - | ||||||||||||
225 | if (!BN_lshift1(r, a)
| 0-1775606 | ||||||||||||
226 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
227 | ; | - | ||||||||||||
228 | if (BN_cmp(r, m) >= 0
| 883028-892578 | ||||||||||||
229 | return executed 892578 times by 2 tests: BN_sub(r, r, m);return BN_sub(r, r, m); Executed by:
executed 892578 times by 2 tests: return BN_sub(r, r, m); Executed by:
| 892578 | ||||||||||||
230 | return executed 883028 times by 2 tests: 1;return 1; Executed by:
executed 883028 times by 2 tests: return 1; Executed by:
| 883028 | ||||||||||||
231 | } | - | ||||||||||||
232 | - | |||||||||||||
233 | int BN_mod_lshift(BIGNUM *r, const BIGNUM *a, int n, const BIGNUM *m, | - | ||||||||||||
234 | BN_CTX *ctx) | - | ||||||||||||
235 | { | - | ||||||||||||
236 | BIGNUM *abs_m = | - | ||||||||||||
237 | ((void *)0) | - | ||||||||||||
238 | ; | - | ||||||||||||
239 | int ret; | - | ||||||||||||
240 | - | |||||||||||||
241 | if (!BN_nnmod(r, a, m, ctx)
| 0 | ||||||||||||
242 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
243 | - | |||||||||||||
244 | if (m->neg
| 0 | ||||||||||||
245 | abs_m = BN_dup(m); | - | ||||||||||||
246 | if (abs_m ==
| 0 | ||||||||||||
247 | ((void *)0)
| 0 | ||||||||||||
248 | ) | - | ||||||||||||
249 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
250 | abs_m->neg = 0; | - | ||||||||||||
251 | } never executed: end of block | 0 | ||||||||||||
252 | - | |||||||||||||
253 | ret = BN_mod_lshift_quick(r, r, n, (abs_m ? abs_m : m)); | - | ||||||||||||
254 | ; | - | ||||||||||||
255 | - | |||||||||||||
256 | BN_free(abs_m); | - | ||||||||||||
257 | return never executed: ret;return ret; never executed: return ret; | 0 | ||||||||||||
258 | } | - | ||||||||||||
259 | - | |||||||||||||
260 | - | |||||||||||||
261 | - | |||||||||||||
262 | - | |||||||||||||
263 | - | |||||||||||||
264 | int BN_mod_lshift_quick(BIGNUM *r, const BIGNUM *a, int n, const BIGNUM *m) | - | ||||||||||||
265 | { | - | ||||||||||||
266 | if (r != a
| 151159-783904 | ||||||||||||
267 | if (BN_copy(r, a) ==
| 0-783904 | ||||||||||||
268 | ((void *)0)
| 0-783904 | ||||||||||||
269 | ) | - | ||||||||||||
270 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
271 | } executed 783904 times by 2 tests: end of block Executed by:
| 783904 | ||||||||||||
272 | - | |||||||||||||
273 | while (n > 0
| 935063-1530937 | ||||||||||||
274 | int max_shift; | - | ||||||||||||
275 | - | |||||||||||||
276 | - | |||||||||||||
277 | max_shift = BN_num_bits(m) - BN_num_bits(r); | - | ||||||||||||
278 | - | |||||||||||||
279 | - | |||||||||||||
280 | if (max_shift < 0
| 0-1530937 | ||||||||||||
281 | ERR_put_error(3,(119),(110),__FILE__,294); | - | ||||||||||||
282 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
283 | } | - | ||||||||||||
284 | - | |||||||||||||
285 | if (max_shift > n
| 185297-1345640 | ||||||||||||
286 | max_shift = n; executed 185297 times by 2 tests: max_shift = n; Executed by:
| 185297 | ||||||||||||
287 | - | |||||||||||||
288 | if (max_shift
| 694555-836382 | ||||||||||||
289 | if (!BN_lshift(r, r, max_shift)
| 0-836382 | ||||||||||||
290 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
291 | n -= max_shift; | - | ||||||||||||
292 | } executed 836382 times by 2 tests: else {end of block Executed by:
| 836382 | ||||||||||||
293 | if (!BN_lshift1(r, r)
| 0-694555 | ||||||||||||
294 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
295 | --n; | - | ||||||||||||
296 | } executed 694555 times by 2 tests: end of block Executed by:
| 694555 | ||||||||||||
297 | - | |||||||||||||
298 | - | |||||||||||||
299 | - | |||||||||||||
300 | if (BN_cmp(r, m) >= 0
| 730613-800324 | ||||||||||||
301 | if (!BN_sub(r, r, m)
| 0-800324 | ||||||||||||
302 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
303 | } executed 800324 times by 2 tests: end of block Executed by:
| 800324 | ||||||||||||
304 | } executed 1530937 times by 2 tests: end of block Executed by:
| 1530937 | ||||||||||||
305 | ; | - | ||||||||||||
306 | - | |||||||||||||
307 | return executed 935063 times by 2 tests: 1;return 1; Executed by:
executed 935063 times by 2 tests: return 1; Executed by:
| 935063 | ||||||||||||
308 | } | - | ||||||||||||
Switch to Source code | Preprocessed file |