Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/bn/bn_gf2m.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | void bn_GF2m_mul_2x2(unsigned long *r, unsigned long a1, unsigned long a0, unsigned long b1, | - | ||||||||||||||||||
2 | unsigned long b0); | - | ||||||||||||||||||
3 | - | |||||||||||||||||||
4 | - | |||||||||||||||||||
5 | - | |||||||||||||||||||
6 | - | |||||||||||||||||||
7 | - | |||||||||||||||||||
8 | - | |||||||||||||||||||
9 | int BN_GF2m_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b) | - | ||||||||||||||||||
10 | { | - | ||||||||||||||||||
11 | int i; | - | ||||||||||||||||||
12 | const BIGNUM *at, *bt; | - | ||||||||||||||||||
13 | - | |||||||||||||||||||
14 | ; | - | ||||||||||||||||||
15 | ; | - | ||||||||||||||||||
16 | - | |||||||||||||||||||
17 | if (a->top < b->top
| 96203-33753235 | ||||||||||||||||||
18 | at = b; | - | ||||||||||||||||||
19 | bt = a; | - | ||||||||||||||||||
20 | } executed 96203 times by 1 test: else {end of block Executed by:
| 96203 | ||||||||||||||||||
21 | at = a; | - | ||||||||||||||||||
22 | bt = b; | - | ||||||||||||||||||
23 | } executed 33753235 times by 1 test: end of block Executed by:
| 33753235 | ||||||||||||||||||
24 | - | |||||||||||||||||||
25 | if (bn_wexpand(r, at->top) ==
| 0-33849438 | ||||||||||||||||||
26 | ((void *)0)
| 0-33849438 | ||||||||||||||||||
27 | ) | - | ||||||||||||||||||
28 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
29 | - | |||||||||||||||||||
30 | for (i = 0; i < bt->top
| 33849438-199055657 | ||||||||||||||||||
31 | r->d[i] = at->d[i] ^ bt->d[i]; | - | ||||||||||||||||||
32 | } executed 199055657 times by 1 test: end of block Executed by:
| 199055657 | ||||||||||||||||||
33 | for (; i < at->top
| 1085927-33849438 | ||||||||||||||||||
34 | r->d[i] = at->d[i]; | - | ||||||||||||||||||
35 | } executed 1085927 times by 1 test: end of block Executed by:
| 1085927 | ||||||||||||||||||
36 | - | |||||||||||||||||||
37 | r->top = at->top; | - | ||||||||||||||||||
38 | bn_correct_top(r); | - | ||||||||||||||||||
39 | - | |||||||||||||||||||
40 | return executed 33849438 times by 1 test: 1;return 1; Executed by:
executed 33849438 times by 1 test: return 1; Executed by:
| 33849438 | ||||||||||||||||||
41 | } | - | ||||||||||||||||||
42 | int BN_GF2m_mod_arr(BIGNUM *r, const BIGNUM *a, const int p[]) | - | ||||||||||||||||||
43 | { | - | ||||||||||||||||||
44 | int j, k; | - | ||||||||||||||||||
45 | int n, dN, d0, d1; | - | ||||||||||||||||||
46 | unsigned long zz, *z; | - | ||||||||||||||||||
47 | - | |||||||||||||||||||
48 | ; | - | ||||||||||||||||||
49 | - | |||||||||||||||||||
50 | if (!p[0]
| 0-54755526 | ||||||||||||||||||
51 | - | |||||||||||||||||||
52 | (BN_set_word((r),0)); | - | ||||||||||||||||||
53 | return never executed: 1;return 1; never executed: return 1; | 0 | ||||||||||||||||||
54 | } | - | ||||||||||||||||||
55 | - | |||||||||||||||||||
56 | - | |||||||||||||||||||
57 | - | |||||||||||||||||||
58 | - | |||||||||||||||||||
59 | - | |||||||||||||||||||
60 | if (a != r
| 42664-54712862 | ||||||||||||||||||
61 | if (!bn_wexpand(r, a->top)
| 0-54712862 | ||||||||||||||||||
62 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
63 | for (j = 0; j < a->top
| 54712862-634631023 | ||||||||||||||||||
64 | r->d[j] = a->d[j]; | - | ||||||||||||||||||
65 | } executed 634631023 times by 1 test: end of block Executed by:
| 634631023 | ||||||||||||||||||
66 | r->top = a->top; | - | ||||||||||||||||||
67 | } executed 54712862 times by 1 test: end of block Executed by:
| 54712862 | ||||||||||||||||||
68 | z = r->d; | - | ||||||||||||||||||
69 | - | |||||||||||||||||||
70 | - | |||||||||||||||||||
71 | dN = p[0] / (8 * 8); | - | ||||||||||||||||||
72 | for (j = r->top - 1; j > dN
| 54755526-630952008 | ||||||||||||||||||
73 | zz = z[j]; | - | ||||||||||||||||||
74 | if (z[j] == 0
| 315473556-315478452 | ||||||||||||||||||
75 | j--; | - | ||||||||||||||||||
76 | continue; executed 315478452 times by 1 test: continue; Executed by:
| 315478452 | ||||||||||||||||||
77 | } | - | ||||||||||||||||||
78 | z[j] = 0; | - | ||||||||||||||||||
79 | - | |||||||||||||||||||
80 | for (k = 1; p[k] != 0
| 315473556-912934854 | ||||||||||||||||||
81 | - | |||||||||||||||||||
82 | n = p[0] - p[k]; | - | ||||||||||||||||||
83 | d0 = n % (8 * 8); | - | ||||||||||||||||||
84 | d1 = (8 * 8) - d0; | - | ||||||||||||||||||
85 | n /= (8 * 8); | - | ||||||||||||||||||
86 | z[j - n] ^= (zz >> d0); | - | ||||||||||||||||||
87 | if (d0
| 203663-912731191 | ||||||||||||||||||
88 | z[j - n - 1] ^= (zz << d1); executed 912731191 times by 1 test: z[j - n - 1] ^= (zz << d1); Executed by:
| 912731191 | ||||||||||||||||||
89 | } executed 912934854 times by 1 test: end of block Executed by:
| 912934854 | ||||||||||||||||||
90 | - | |||||||||||||||||||
91 | - | |||||||||||||||||||
92 | n = dN; | - | ||||||||||||||||||
93 | d0 = p[0] % (8 * 8); | - | ||||||||||||||||||
94 | d1 = (8 * 8) - d0; | - | ||||||||||||||||||
95 | z[j - n] ^= (zz >> d0); | - | ||||||||||||||||||
96 | if (d0
| 0-315473556 | ||||||||||||||||||
97 | z[j - n - 1] ^= (zz << d1); executed 315473556 times by 1 test: z[j - n - 1] ^= (zz << d1); Executed by:
| 315473556 | ||||||||||||||||||
98 | } executed 315473556 times by 1 test: end of block Executed by:
| 315473556 | ||||||||||||||||||
99 | - | |||||||||||||||||||
100 | - | |||||||||||||||||||
101 | while (j == dN
| 274903-108386740 | ||||||||||||||||||
102 | - | |||||||||||||||||||
103 | d0 = p[0] % (8 * 8); | - | ||||||||||||||||||
104 | zz = z[dN] >> d0; | - | ||||||||||||||||||
105 | if (zz == 0
| 53906117-54480623 | ||||||||||||||||||
106 | break; executed 54480623 times by 1 test: break; Executed by:
| 54480623 | ||||||||||||||||||
107 | d1 = (8 * 8) - d0; | - | ||||||||||||||||||
108 | - | |||||||||||||||||||
109 | - | |||||||||||||||||||
110 | if (d0
| 0-53906117 | ||||||||||||||||||
111 | z[dN] = (z[dN] << d1) >> d1; executed 53906117 times by 1 test: z[dN] = (z[dN] << d1) >> d1; Executed by:
| 53906117 | ||||||||||||||||||
112 | else | - | ||||||||||||||||||
113 | z[dN] = 0; never executed: z[dN] = 0; | 0 | ||||||||||||||||||
114 | z[0] ^= zz; | - | ||||||||||||||||||
115 | - | |||||||||||||||||||
116 | for (k = 1; p[k] != 0
| 53906117-154452711 | ||||||||||||||||||
117 | unsigned long tmp_ulong; | - | ||||||||||||||||||
118 | - | |||||||||||||||||||
119 | - | |||||||||||||||||||
120 | n = p[k] / (8 * 8); | - | ||||||||||||||||||
121 | d0 = p[k] % (8 * 8); | - | ||||||||||||||||||
122 | d1 = (8 * 8) - d0; | - | ||||||||||||||||||
123 | z[n] ^= (zz << d0); | - | ||||||||||||||||||
124 | if (d0
| 0-154452711 | ||||||||||||||||||
125 | z[n + 1] ^= tmp_ulong; executed 1226248 times by 1 test: z[n + 1] ^= tmp_ulong; Executed by:
| 1226248 | ||||||||||||||||||
126 | } executed 154452711 times by 1 test: end of block Executed by:
| 154452711 | ||||||||||||||||||
127 | - | |||||||||||||||||||
128 | } executed 53906117 times by 1 test: end of block Executed by:
| 53906117 | ||||||||||||||||||
129 | - | |||||||||||||||||||
130 | bn_correct_top(r); | - | ||||||||||||||||||
131 | return executed 54755526 times by 1 test: 1;return 1; Executed by:
executed 54755526 times by 1 test: return 1; Executed by:
| 54755526 | ||||||||||||||||||
132 | } | - | ||||||||||||||||||
133 | - | |||||||||||||||||||
134 | - | |||||||||||||||||||
135 | - | |||||||||||||||||||
136 | - | |||||||||||||||||||
137 | - | |||||||||||||||||||
138 | - | |||||||||||||||||||
139 | - | |||||||||||||||||||
140 | int BN_GF2m_mod(BIGNUM *r, const BIGNUM *a, const BIGNUM *p) | - | ||||||||||||||||||
141 | { | - | ||||||||||||||||||
142 | int ret = 0; | - | ||||||||||||||||||
143 | int arr[6]; | - | ||||||||||||||||||
144 | ; | - | ||||||||||||||||||
145 | ; | - | ||||||||||||||||||
146 | ret = BN_GF2m_poly2arr(p, arr, (sizeof(arr)/sizeof((arr)[0]))); | - | ||||||||||||||||||
147 | if (!ret
| 0-74082 | ||||||||||||||||||
148 | ERR_put_error(3,(131),(106),__FILE__,398); | - | ||||||||||||||||||
149 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
150 | } | - | ||||||||||||||||||
151 | ret = BN_GF2m_mod_arr(r, a, arr); | - | ||||||||||||||||||
152 | ; | - | ||||||||||||||||||
153 | return executed 74082 times by 1 test: ret;return ret; Executed by:
executed 74082 times by 1 test: return ret; Executed by:
| 74082 | ||||||||||||||||||
154 | } | - | ||||||||||||||||||
155 | - | |||||||||||||||||||
156 | - | |||||||||||||||||||
157 | - | |||||||||||||||||||
158 | - | |||||||||||||||||||
159 | - | |||||||||||||||||||
160 | int BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, | - | ||||||||||||||||||
161 | const int p[], BN_CTX *ctx) | - | ||||||||||||||||||
162 | { | - | ||||||||||||||||||
163 | int zlen, i, j, k, ret = 0; | - | ||||||||||||||||||
164 | BIGNUM *s; | - | ||||||||||||||||||
165 | unsigned long x1, x0, y1, y0, zz[4]; | - | ||||||||||||||||||
166 | - | |||||||||||||||||||
167 | ; | - | ||||||||||||||||||
168 | ; | - | ||||||||||||||||||
169 | - | |||||||||||||||||||
170 | if (a == b
| 0-19552766 | ||||||||||||||||||
171 | return never executed: BN_GF2m_mod_sqr_arr(r, a, p, ctx);return BN_GF2m_mod_sqr_arr(r, a, p, ctx); never executed: return BN_GF2m_mod_sqr_arr(r, a, p, ctx); | 0 | ||||||||||||||||||
172 | } | - | ||||||||||||||||||
173 | - | |||||||||||||||||||
174 | BN_CTX_start(ctx); | - | ||||||||||||||||||
175 | if ((
| 0-19552766 | ||||||||||||||||||
176 | ((void *)0)
| 0-19552766 | ||||||||||||||||||
177 | ) | - | ||||||||||||||||||
178 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
179 | - | |||||||||||||||||||
180 | zlen = a->top + b->top + 4; | - | ||||||||||||||||||
181 | if (!bn_wexpand(s, zlen)
| 0-19552766 | ||||||||||||||||||
182 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
183 | s->top = zlen; | - | ||||||||||||||||||
184 | - | |||||||||||||||||||
185 | for (i = 0; i < zlen
| 19552766-305716397 | ||||||||||||||||||
186 | s->d[i] = 0; executed 305716397 times by 1 test: s->d[i] = 0; Executed by:
| 305716397 | ||||||||||||||||||
187 | - | |||||||||||||||||||
188 | for (j = 0; j < b->top
| 19552766-58335979 | ||||||||||||||||||
189 | y0 = b->d[j]; | - | ||||||||||||||||||
190 | y1 = ((
| 3018680-55317299 | ||||||||||||||||||
191 | for (i = 0; i < a->top
| 58335979-179393583 | ||||||||||||||||||
192 | x0 = a->d[i]; | - | ||||||||||||||||||
193 | x1 = ((
| 10022750-169370833 | ||||||||||||||||||
194 | bn_GF2m_mul_2x2(zz, x1, x0, y1, y0); | - | ||||||||||||||||||
195 | for (k = 0; k < 4
| 179393583-717574332 | ||||||||||||||||||
196 | s->d[i + j + k] ^= zz[k]; executed 717574332 times by 1 test: s->d[i + j + k] ^= zz[k]; Executed by:
| 717574332 | ||||||||||||||||||
197 | } executed 179393583 times by 1 test: end of block Executed by:
| 179393583 | ||||||||||||||||||
198 | } executed 58335979 times by 1 test: end of block Executed by:
| 58335979 | ||||||||||||||||||
199 | - | |||||||||||||||||||
200 | bn_correct_top(s); | - | ||||||||||||||||||
201 | if (BN_GF2m_mod_arr(r, s, p)
| 0-19552766 | ||||||||||||||||||
202 | ret = 1; executed 19552766 times by 1 test: ret = 1; Executed by:
| 19552766 | ||||||||||||||||||
203 | ; | - | ||||||||||||||||||
204 | - | |||||||||||||||||||
205 | err: code before this statement executed 19552766 times by 1 test: err: Executed by:
| 19552766 | ||||||||||||||||||
206 | BN_CTX_end(ctx); | - | ||||||||||||||||||
207 | return executed 19552766 times by 1 test: ret;return ret; Executed by:
executed 19552766 times by 1 test: return ret; Executed by:
| 19552766 | ||||||||||||||||||
208 | } | - | ||||||||||||||||||
209 | int BN_GF2m_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, | - | ||||||||||||||||||
210 | const BIGNUM *p, BN_CTX *ctx) | - | ||||||||||||||||||
211 | { | - | ||||||||||||||||||
212 | int ret = 0; | - | ||||||||||||||||||
213 | const int max = BN_num_bits(p) + 1; | - | ||||||||||||||||||
214 | int *arr = | - | ||||||||||||||||||
215 | ((void *)0) | - | ||||||||||||||||||
216 | ; | - | ||||||||||||||||||
217 | ; | - | ||||||||||||||||||
218 | ; | - | ||||||||||||||||||
219 | ; | - | ||||||||||||||||||
220 | if ((
| 0-219585 | ||||||||||||||||||
221 | ((void *)0)
| 0-219585 | ||||||||||||||||||
222 | ) | - | ||||||||||||||||||
223 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
224 | ret = BN_GF2m_poly2arr(p, arr, max); | - | ||||||||||||||||||
225 | if (!ret
| 0-219585 | ||||||||||||||||||
226 | ERR_put_error(3,(133),(106),__FILE__,478); | - | ||||||||||||||||||
227 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
228 | } | - | ||||||||||||||||||
229 | ret = BN_GF2m_mod_mul_arr(r, a, b, arr, ctx); | - | ||||||||||||||||||
230 | ; | - | ||||||||||||||||||
231 | err: code before this statement executed 219585 times by 1 test: err: Executed by:
| 219585 | ||||||||||||||||||
232 | CRYPTO_free(arr, __FILE__, 484); | - | ||||||||||||||||||
233 | return executed 219585 times by 1 test: ret;return ret; Executed by:
executed 219585 times by 1 test: return ret; Executed by:
| 219585 | ||||||||||||||||||
234 | } | - | ||||||||||||||||||
235 | - | |||||||||||||||||||
236 | - | |||||||||||||||||||
237 | int BN_GF2m_mod_sqr_arr(BIGNUM *r, const BIGNUM *a, const int p[], | - | ||||||||||||||||||
238 | BN_CTX *ctx) | - | ||||||||||||||||||
239 | { | - | ||||||||||||||||||
240 | int i, ret = 0; | - | ||||||||||||||||||
241 | BIGNUM *s; | - | ||||||||||||||||||
242 | - | |||||||||||||||||||
243 | ; | - | ||||||||||||||||||
244 | BN_CTX_start(ctx); | - | ||||||||||||||||||
245 | if ((
| 0-35053540 | ||||||||||||||||||
246 | ((void *)0)
| 0-35053540 | ||||||||||||||||||
247 | ) | - | ||||||||||||||||||
248 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
249 | if (!bn_wexpand(s, 2 * a->top)
| 0-35053540 | ||||||||||||||||||
250 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
251 | - | |||||||||||||||||||
252 | for (i = a->top - 1; i >= 0
| 35053540-204697073 | ||||||||||||||||||
253 | s->d[2 * i + 1] = (((((a->d[i]) >> 60) & 8) << 3) | ((((a->d[i]) >> 60) & 4) << 2) | ((((a->d[i]) >> 60) & 2) << 1) | (((a->d[i]) >> 60) & 1)) << 56 | (((((a->d[i]) >> 56) & 8) << 3) | ((((a->d[i]) >> 56) & 4) << 2) | ((((a->d[i]) >> 56) & 2) << 1) | (((a->d[i]) >> 56) & 1)) << 48 | (((((a->d[i]) >> 52) & 8) << 3) | ((((a->d[i]) >> 52) & 4) << 2) | ((((a->d[i]) >> 52) & 2) << 1) | (((a->d[i]) >> 52) & 1)) << 40 | (((((a->d[i]) >> 48) & 8) << 3) | ((((a->d[i]) >> 48) & 4) << 2) | ((((a->d[i]) >> 48) & 2) << 1) | (((a->d[i]) >> 48) & 1)) << 32 | (((((a->d[i]) >> 44) & 8) << 3) | ((((a->d[i]) >> 44) & 4) << 2) | ((((a->d[i]) >> 44) & 2) << 1) | (((a->d[i]) >> 44) & 1)) << 24 | (((((a->d[i]) >> 40) & 8) << 3) | ((((a->d[i]) >> 40) & 4) << 2) | ((((a->d[i]) >> 40) & 2) << 1) | (((a->d[i]) >> 40) & 1)) << 16 | (((((a->d[i]) >> 36) & 8) << 3) | ((((a->d[i]) >> 36) & 4) << 2) | ((((a->d[i]) >> 36) & 2) << 1) | (((a->d[i]) >> 36) & 1)) << 8 | (((((a->d[i]) >> 32) & 8) << 3) | ((((a->d[i]) >> 32) & 4) << 2) | ((((a->d[i]) >> 32) & 2) << 1) | (((a->d[i]) >> 32) & 1)); | - | ||||||||||||||||||
254 | s->d[2 * i] = (((((a->d[i]) >> 28) & 8) << 3) | ((((a->d[i]) >> 28) & 4) << 2) | ((((a->d[i]) >> 28) & 2) << 1) | (((a->d[i]) >> 28) & 1)) << 56 | (((((a->d[i]) >> 24) & 8) << 3) | ((((a->d[i]) >> 24) & 4) << 2) | ((((a->d[i]) >> 24) & 2) << 1) | (((a->d[i]) >> 24) & 1)) << 48 | (((((a->d[i]) >> 20) & 8) << 3) | ((((a->d[i]) >> 20) & 4) << 2) | ((((a->d[i]) >> 20) & 2) << 1) | (((a->d[i]) >> 20) & 1)) << 40 | (((((a->d[i]) >> 16) & 8) << 3) | ((((a->d[i]) >> 16) & 4) << 2) | ((((a->d[i]) >> 16) & 2) << 1) | (((a->d[i]) >> 16) & 1)) << 32 | (((((a->d[i]) >> 12) & 8) << 3) | ((((a->d[i]) >> 12) & 4) << 2) | ((((a->d[i]) >> 12) & 2) << 1) | (((a->d[i]) >> 12) & 1)) << 24 | (((((a->d[i]) >> 8) & 8) << 3) | ((((a->d[i]) >> 8) & 4) << 2) | ((((a->d[i]) >> 8) & 2) << 1) | (((a->d[i]) >> 8) & 1)) << 16 | (((((a->d[i]) >> 4) & 8) << 3) | ((((a->d[i]) >> 4) & 4) << 2) | ((((a->d[i]) >> 4) & 2) << 1) | (((a->d[i]) >> 4) & 1)) << 8 | (((((a->d[i])) & 8) << 3) | ((((a->d[i])) & 4) << 2) | ((((a->d[i])) & 2) << 1) | (((a->d[i])) & 1)); | - | ||||||||||||||||||
255 | } executed 204697073 times by 1 test: end of block Executed by:
| 204697073 | ||||||||||||||||||
256 | - | |||||||||||||||||||
257 | s->top = 2 * a->top; | - | ||||||||||||||||||
258 | bn_correct_top(s); | - | ||||||||||||||||||
259 | if (!BN_GF2m_mod_arr(r, s, p)
| 0-35053540 | ||||||||||||||||||
260 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
261 | ; | - | ||||||||||||||||||
262 | ret = 1; | - | ||||||||||||||||||
263 | err: code before this statement executed 35053540 times by 1 test: err: Executed by:
| 35053540 | ||||||||||||||||||
264 | BN_CTX_end(ctx); | - | ||||||||||||||||||
265 | return executed 35053540 times by 1 test: ret;return ret; Executed by:
executed 35053540 times by 1 test: return ret; Executed by:
| 35053540 | ||||||||||||||||||
266 | } | - | ||||||||||||||||||
267 | - | |||||||||||||||||||
268 | - | |||||||||||||||||||
269 | - | |||||||||||||||||||
270 | - | |||||||||||||||||||
271 | - | |||||||||||||||||||
272 | - | |||||||||||||||||||
273 | - | |||||||||||||||||||
274 | int BN_GF2m_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) | - | ||||||||||||||||||
275 | { | - | ||||||||||||||||||
276 | int ret = 0; | - | ||||||||||||||||||
277 | const int max = BN_num_bits(p) + 1; | - | ||||||||||||||||||
278 | int *arr = | - | ||||||||||||||||||
279 | ((void *)0) | - | ||||||||||||||||||
280 | ; | - | ||||||||||||||||||
281 | - | |||||||||||||||||||
282 | ; | - | ||||||||||||||||||
283 | ; | - | ||||||||||||||||||
284 | if ((
| 0-495 | ||||||||||||||||||
285 | ((void *)0)
| 0-495 | ||||||||||||||||||
286 | ) | - | ||||||||||||||||||
287 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
288 | ret = BN_GF2m_poly2arr(p, arr, max); | - | ||||||||||||||||||
289 | if (!ret
| 0-495 | ||||||||||||||||||
290 | ERR_put_error(3,(136),(106),__FILE__,536); | - | ||||||||||||||||||
291 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
292 | } | - | ||||||||||||||||||
293 | ret = BN_GF2m_mod_sqr_arr(r, a, arr, ctx); | - | ||||||||||||||||||
294 | ; | - | ||||||||||||||||||
295 | err: code before this statement executed 495 times by 1 test: err: Executed by:
| 495 | ||||||||||||||||||
296 | CRYPTO_free(arr, __FILE__, 542); | - | ||||||||||||||||||
297 | return executed 495 times by 1 test: ret;return ret; Executed by:
executed 495 times by 1 test: return ret; Executed by:
| 495 | ||||||||||||||||||
298 | } | - | ||||||||||||||||||
299 | - | |||||||||||||||||||
300 | - | |||||||||||||||||||
301 | - | |||||||||||||||||||
302 | - | |||||||||||||||||||
303 | - | |||||||||||||||||||
304 | - | |||||||||||||||||||
305 | - | |||||||||||||||||||
306 | static int BN_GF2m_mod_inv_vartime(BIGNUM *r, const BIGNUM *a, | - | ||||||||||||||||||
307 | const BIGNUM *p, BN_CTX *ctx) | - | ||||||||||||||||||
308 | { | - | ||||||||||||||||||
309 | BIGNUM *b, *c = | - | ||||||||||||||||||
310 | ((void *)0) | - | ||||||||||||||||||
311 | , *u = | - | ||||||||||||||||||
312 | ((void *)0) | - | ||||||||||||||||||
313 | , *v = | - | ||||||||||||||||||
314 | ((void *)0) | - | ||||||||||||||||||
315 | , *tmp; | - | ||||||||||||||||||
316 | int ret = 0; | - | ||||||||||||||||||
317 | - | |||||||||||||||||||
318 | ; | - | ||||||||||||||||||
319 | ; | - | ||||||||||||||||||
320 | - | |||||||||||||||||||
321 | BN_CTX_start(ctx); | - | ||||||||||||||||||
322 | - | |||||||||||||||||||
323 | b = BN_CTX_get(ctx); | - | ||||||||||||||||||
324 | c = BN_CTX_get(ctx); | - | ||||||||||||||||||
325 | u = BN_CTX_get(ctx); | - | ||||||||||||||||||
326 | v = BN_CTX_get(ctx); | - | ||||||||||||||||||
327 | if (v ==
| 0-73387 | ||||||||||||||||||
328 | ((void *)0)
| 0-73387 | ||||||||||||||||||
329 | ) | - | ||||||||||||||||||
330 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
331 | - | |||||||||||||||||||
332 | if (!BN_GF2m_mod(u, a, p)
| 0-73387 | ||||||||||||||||||
333 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
334 | if (BN_is_zero(u)
| 76-73311 | ||||||||||||||||||
335 | goto executed 76 times by 1 test: err;goto err; Executed by:
executed 76 times by 1 test: goto err; Executed by:
| 76 | ||||||||||||||||||
336 | - | |||||||||||||||||||
337 | if (!BN_copy(v, p)
| 0-73311 | ||||||||||||||||||
338 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
339 | { | - | ||||||||||||||||||
340 | int i; | - | ||||||||||||||||||
341 | int ubits = BN_num_bits(u); | - | ||||||||||||||||||
342 | int vbits = BN_num_bits(v); | - | ||||||||||||||||||
343 | int top = p->top; | - | ||||||||||||||||||
344 | unsigned long *udp, *bdp, *vdp, *cdp; | - | ||||||||||||||||||
345 | - | |||||||||||||||||||
346 | if (!bn_wexpand(u, top)
| 0-73311 | ||||||||||||||||||
347 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
348 | udp = u->d; | - | ||||||||||||||||||
349 | for (i = u->top; i < top
| 1290-73311 | ||||||||||||||||||
350 | udp[i] = 0; executed 1290 times by 1 test: udp[i] = 0; Executed by:
| 1290 | ||||||||||||||||||
351 | u->top = top; | - | ||||||||||||||||||
352 | if (!bn_wexpand(b, top)
| 0-73311 | ||||||||||||||||||
353 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
354 | bdp = b->d; | - | ||||||||||||||||||
355 | bdp[0] = 1; | - | ||||||||||||||||||
356 | for (i = 1; i < top
| 73311-309743 | ||||||||||||||||||
357 | bdp[i] = 0; executed 309743 times by 1 test: bdp[i] = 0; Executed by:
| 309743 | ||||||||||||||||||
358 | b->top = top; | - | ||||||||||||||||||
359 | if (!bn_wexpand(c, top)
| 0-73311 | ||||||||||||||||||
360 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
361 | cdp = c->d; | - | ||||||||||||||||||
362 | for (i = 0; i < top
| 73311-383054 | ||||||||||||||||||
363 | cdp[i] = 0; executed 383054 times by 1 test: cdp[i] = 0; Executed by:
| 383054 | ||||||||||||||||||
364 | c->top = top; | - | ||||||||||||||||||
365 | vdp = v->d; | - | ||||||||||||||||||
366 | - | |||||||||||||||||||
367 | - | |||||||||||||||||||
368 | - | |||||||||||||||||||
369 | while (1) { | - | ||||||||||||||||||
370 | while (ubits
| 1-56610033 | ||||||||||||||||||
371 | unsigned long u0, u1, b0, b1, mask; | - | ||||||||||||||||||
372 | - | |||||||||||||||||||
373 | u0 = udp[0]; | - | ||||||||||||||||||
374 | b0 = bdp[0]; | - | ||||||||||||||||||
375 | mask = (unsigned long)0 - (b0 & 1); | - | ||||||||||||||||||
376 | b0 ^= p->d[0] & mask; | - | ||||||||||||||||||
377 | for (i = 0; i < top - 1
| 37712320-200342146 | ||||||||||||||||||
378 | u1 = udp[i + 1]; | - | ||||||||||||||||||
379 | udp[i] = ((u0 >> 1) | (u1 << ((8 * 8) - 1))) & (0xffffffffffffffffL); | - | ||||||||||||||||||
380 | u0 = u1; | - | ||||||||||||||||||
381 | b1 = bdp[i + 1] ^ (p->d[i + 1] & mask); | - | ||||||||||||||||||
382 | bdp[i] = ((b0 >> 1) | (b1 << ((8 * 8) - 1))) & (0xffffffffffffffffL); | - | ||||||||||||||||||
383 | b0 = b1; | - | ||||||||||||||||||
384 | } executed 200342146 times by 1 test: end of block Executed by:
| 200342146 | ||||||||||||||||||
385 | udp[i] = u0 >> 1; | - | ||||||||||||||||||
386 | bdp[i] = b0 >> 1; | - | ||||||||||||||||||
387 | ubits--; | - | ||||||||||||||||||
388 | } executed 37712320 times by 1 test: end of block Executed by:
| 37712320 | ||||||||||||||||||
389 | - | |||||||||||||||||||
390 | if (ubits <= (8 * 8)
| 3820696-15077018 | ||||||||||||||||||
391 | if (udp[0] == 0
| 1-3820695 | ||||||||||||||||||
392 | goto executed 1 time by 1 test: err;goto err; Executed by:
executed 1 time by 1 test: goto err; Executed by:
| 1 | ||||||||||||||||||
393 | if (udp[0] == 1
| 73310-3747385 | ||||||||||||||||||
394 | break; executed 73310 times by 1 test: break; Executed by:
| 73310 | ||||||||||||||||||
395 | } executed 3747385 times by 1 test: end of block Executed by:
| 3747385 | ||||||||||||||||||
396 | - | |||||||||||||||||||
397 | if (ubits < vbits
| 7566193-11258210 | ||||||||||||||||||
398 | i = ubits; | - | ||||||||||||||||||
399 | ubits = vbits; | - | ||||||||||||||||||
400 | vbits = i; | - | ||||||||||||||||||
401 | tmp = u; | - | ||||||||||||||||||
402 | u = v; | - | ||||||||||||||||||
403 | v = tmp; | - | ||||||||||||||||||
404 | tmp = b; | - | ||||||||||||||||||
405 | b = c; | - | ||||||||||||||||||
406 | c = tmp; | - | ||||||||||||||||||
407 | udp = vdp; | - | ||||||||||||||||||
408 | vdp = v->d; | - | ||||||||||||||||||
409 | bdp = cdp; | - | ||||||||||||||||||
410 | cdp = c->d; | - | ||||||||||||||||||
411 | } executed 7566193 times by 1 test: end of block Executed by:
| 7566193 | ||||||||||||||||||
412 | for (i = 0; i < top
| 18824403-118896530 | ||||||||||||||||||
413 | udp[i] ^= vdp[i]; | - | ||||||||||||||||||
414 | bdp[i] ^= cdp[i]; | - | ||||||||||||||||||
415 | } executed 118896530 times by 1 test: end of block Executed by:
| 118896530 | ||||||||||||||||||
416 | if (ubits == vbits
| 3761280-15063123 | ||||||||||||||||||
417 | unsigned long ul; | - | ||||||||||||||||||
418 | int utop = (ubits - 1) / (8 * 8); | - | ||||||||||||||||||
419 | - | |||||||||||||||||||
420 | while ((
| 1-3761279 | ||||||||||||||||||
421 | utop--; executed 103266 times by 1 test: utop--; Executed by:
| 103266 | ||||||||||||||||||
422 | ubits = utop * (8 * 8) + BN_num_bits_word(ul); | - | ||||||||||||||||||
423 | } executed 3761280 times by 1 test: end of block Executed by:
| 3761280 | ||||||||||||||||||
424 | } executed 18824403 times by 1 test: end of block Executed by:
| 18824403 | ||||||||||||||||||
425 | bn_correct_top(b); | - | ||||||||||||||||||
426 | } | - | ||||||||||||||||||
427 | - | |||||||||||||||||||
428 | - | |||||||||||||||||||
429 | if (!BN_copy(r, b)
| 0-73310 | ||||||||||||||||||
430 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
431 | ; | - | ||||||||||||||||||
432 | ret = 1; | - | ||||||||||||||||||
433 | - | |||||||||||||||||||
434 | err: code before this statement executed 73310 times by 1 test: err: Executed by:
| 73310 | ||||||||||||||||||
435 | - | |||||||||||||||||||
436 | - | |||||||||||||||||||
437 | - | |||||||||||||||||||
438 | - | |||||||||||||||||||
439 | - | |||||||||||||||||||
440 | - | |||||||||||||||||||
441 | BN_CTX_end(ctx); | - | ||||||||||||||||||
442 | return executed 73387 times by 1 test: ret;return ret; Executed by:
executed 73387 times by 1 test: return ret; Executed by:
| 73387 | ||||||||||||||||||
443 | } | - | ||||||||||||||||||
444 | - | |||||||||||||||||||
445 | - | |||||||||||||||||||
446 | - | |||||||||||||||||||
447 | - | |||||||||||||||||||
448 | - | |||||||||||||||||||
449 | - | |||||||||||||||||||
450 | int BN_GF2m_mod_inv(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) | - | ||||||||||||||||||
451 | { | - | ||||||||||||||||||
452 | BIGNUM *b = | - | ||||||||||||||||||
453 | ((void *)0) | - | ||||||||||||||||||
454 | ; | - | ||||||||||||||||||
455 | int ret = 0; | - | ||||||||||||||||||
456 | - | |||||||||||||||||||
457 | BN_CTX_start(ctx); | - | ||||||||||||||||||
458 | if ((
| 0-73387 | ||||||||||||||||||
459 | ((void *)0)
| 0-73387 | ||||||||||||||||||
460 | ) | - | ||||||||||||||||||
461 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
462 | - | |||||||||||||||||||
463 | - | |||||||||||||||||||
464 | do { | - | ||||||||||||||||||
465 | if (!BN_priv_rand(b, BN_num_bits(p) - 1,
| 0-73387 | ||||||||||||||||||
466 | -1, 0)
| 0-73387 | ||||||||||||||||||
467 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
468 | } executed 73387 times by 1 test: while (BN_is_zero(b)end of block Executed by:
| 0-73387 | ||||||||||||||||||
469 | - | |||||||||||||||||||
470 | - | |||||||||||||||||||
471 | if (!BN_GF2m_mod_mul(r, a, b, p, ctx)
| 0-73387 | ||||||||||||||||||
472 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
473 | - | |||||||||||||||||||
474 | - | |||||||||||||||||||
475 | if (!BN_GF2m_mod_inv_vartime(r, r, p, ctx)
| 77-73310 | ||||||||||||||||||
476 | goto executed 77 times by 1 test: err;goto err; Executed by:
executed 77 times by 1 test: goto err; Executed by:
| 77 | ||||||||||||||||||
477 | - | |||||||||||||||||||
478 | - | |||||||||||||||||||
479 | if (!BN_GF2m_mod_mul(r, r, b, p, ctx)
| 0-73310 | ||||||||||||||||||
480 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
481 | - | |||||||||||||||||||
482 | ret = 1; | - | ||||||||||||||||||
483 | - | |||||||||||||||||||
484 | err: code before this statement executed 73310 times by 1 test: err: Executed by:
| 73310 | ||||||||||||||||||
485 | BN_CTX_end(ctx); | - | ||||||||||||||||||
486 | return executed 73387 times by 1 test: ret;return ret; Executed by:
executed 73387 times by 1 test: return ret; Executed by:
| 73387 | ||||||||||||||||||
487 | } | - | ||||||||||||||||||
488 | - | |||||||||||||||||||
489 | - | |||||||||||||||||||
490 | - | |||||||||||||||||||
491 | - | |||||||||||||||||||
492 | - | |||||||||||||||||||
493 | - | |||||||||||||||||||
494 | - | |||||||||||||||||||
495 | int BN_GF2m_mod_inv_arr(BIGNUM *r, const BIGNUM *xx, const int p[], | - | ||||||||||||||||||
496 | BN_CTX *ctx) | - | ||||||||||||||||||
497 | { | - | ||||||||||||||||||
498 | BIGNUM *field; | - | ||||||||||||||||||
499 | int ret = 0; | - | ||||||||||||||||||
500 | - | |||||||||||||||||||
501 | ; | - | ||||||||||||||||||
502 | BN_CTX_start(ctx); | - | ||||||||||||||||||
503 | if ((
| 0 | ||||||||||||||||||
504 | ((void *)0)
| 0 | ||||||||||||||||||
505 | ) | - | ||||||||||||||||||
506 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
507 | if (!BN_GF2m_arr2poly(p, field)
| 0 | ||||||||||||||||||
508 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
509 | - | |||||||||||||||||||
510 | ret = BN_GF2m_mod_inv(r, xx, field, ctx); | - | ||||||||||||||||||
511 | ; | - | ||||||||||||||||||
512 | - | |||||||||||||||||||
513 | err: code before this statement never executed: err: | 0 | ||||||||||||||||||
514 | BN_CTX_end(ctx); | - | ||||||||||||||||||
515 | return never executed: ret;return ret; never executed: return ret; | 0 | ||||||||||||||||||
516 | } | - | ||||||||||||||||||
517 | - | |||||||||||||||||||
518 | - | |||||||||||||||||||
519 | - | |||||||||||||||||||
520 | - | |||||||||||||||||||
521 | - | |||||||||||||||||||
522 | int BN_GF2m_mod_div(BIGNUM *r, const BIGNUM *y, const BIGNUM *x, | - | ||||||||||||||||||
523 | const BIGNUM *p, BN_CTX *ctx) | - | ||||||||||||||||||
524 | { | - | ||||||||||||||||||
525 | BIGNUM *xinv = | - | ||||||||||||||||||
526 | ((void *)0) | - | ||||||||||||||||||
527 | ; | - | ||||||||||||||||||
528 | int ret = 0; | - | ||||||||||||||||||
529 | - | |||||||||||||||||||
530 | ; | - | ||||||||||||||||||
531 | ; | - | ||||||||||||||||||
532 | ; | - | ||||||||||||||||||
533 | - | |||||||||||||||||||
534 | BN_CTX_start(ctx); | - | ||||||||||||||||||
535 | xinv = BN_CTX_get(ctx); | - | ||||||||||||||||||
536 | if (xinv ==
| 0-71565 | ||||||||||||||||||
537 | ((void *)0)
| 0-71565 | ||||||||||||||||||
538 | ) | - | ||||||||||||||||||
539 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
540 | - | |||||||||||||||||||
541 | if (!BN_GF2m_mod_inv(xinv, x, p, ctx)
| 77-71488 | ||||||||||||||||||
542 | goto executed 77 times by 1 test: err;goto err; Executed by:
executed 77 times by 1 test: goto err; Executed by:
| 77 | ||||||||||||||||||
543 | if (!BN_GF2m_mod_mul(r, y, xinv, p, ctx)
| 0-71488 | ||||||||||||||||||
544 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
545 | ; | - | ||||||||||||||||||
546 | ret = 1; | - | ||||||||||||||||||
547 | - | |||||||||||||||||||
548 | err: code before this statement executed 71488 times by 1 test: err: Executed by:
| 71488 | ||||||||||||||||||
549 | BN_CTX_end(ctx); | - | ||||||||||||||||||
550 | return executed 71565 times by 1 test: ret;return ret; Executed by:
executed 71565 times by 1 test: return ret; Executed by:
| 71565 | ||||||||||||||||||
551 | } | - | ||||||||||||||||||
552 | - | |||||||||||||||||||
553 | - | |||||||||||||||||||
554 | - | |||||||||||||||||||
555 | - | |||||||||||||||||||
556 | - | |||||||||||||||||||
557 | - | |||||||||||||||||||
558 | - | |||||||||||||||||||
559 | int BN_GF2m_mod_div_arr(BIGNUM *r, const BIGNUM *yy, const BIGNUM *xx, | - | ||||||||||||||||||
560 | const int p[], BN_CTX *ctx) | - | ||||||||||||||||||
561 | { | - | ||||||||||||||||||
562 | BIGNUM *field; | - | ||||||||||||||||||
563 | int ret = 0; | - | ||||||||||||||||||
564 | - | |||||||||||||||||||
565 | ; | - | ||||||||||||||||||
566 | ; | - | ||||||||||||||||||
567 | - | |||||||||||||||||||
568 | BN_CTX_start(ctx); | - | ||||||||||||||||||
569 | if ((
| 0 | ||||||||||||||||||
570 | ((void *)0)
| 0 | ||||||||||||||||||
571 | ) | - | ||||||||||||||||||
572 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
573 | if (!BN_GF2m_arr2poly(p, field)
| 0 | ||||||||||||||||||
574 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
575 | - | |||||||||||||||||||
576 | ret = BN_GF2m_mod_div(r, yy, xx, field, ctx); | - | ||||||||||||||||||
577 | ; | - | ||||||||||||||||||
578 | - | |||||||||||||||||||
579 | err: code before this statement never executed: err: | 0 | ||||||||||||||||||
580 | BN_CTX_end(ctx); | - | ||||||||||||||||||
581 | return never executed: ret;return ret; never executed: return ret; | 0 | ||||||||||||||||||
582 | } | - | ||||||||||||||||||
583 | - | |||||||||||||||||||
584 | - | |||||||||||||||||||
585 | - | |||||||||||||||||||
586 | - | |||||||||||||||||||
587 | - | |||||||||||||||||||
588 | - | |||||||||||||||||||
589 | int BN_GF2m_mod_exp_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, | - | ||||||||||||||||||
590 | const int p[], BN_CTX *ctx) | - | ||||||||||||||||||
591 | { | - | ||||||||||||||||||
592 | int ret = 0, i, n; | - | ||||||||||||||||||
593 | BIGNUM *u; | - | ||||||||||||||||||
594 | - | |||||||||||||||||||
595 | ; | - | ||||||||||||||||||
596 | ; | - | ||||||||||||||||||
597 | - | |||||||||||||||||||
598 | if (BN_is_zero(b)
| 0-1911 | ||||||||||||||||||
599 | return never executed: (BN_set_word((r),1));return (BN_set_word((r),1)); never executed: return (BN_set_word((r),1)); | 0 | ||||||||||||||||||
600 | - | |||||||||||||||||||
601 | if (BN_abs_is_word(b, 1)
| 0-1911 | ||||||||||||||||||
602 | return never executed: (BN_copy(r, a) != return (BN_copy(r, a) != ((void *)0) ); never executed: return (BN_copy(r, a) != ((void *)0) ); | 0 | ||||||||||||||||||
603 | ((void *)0) never executed: return (BN_copy(r, a) != ((void *)0) ); | 0 | ||||||||||||||||||
604 | ); never executed: return (BN_copy(r, a) != ((void *)0) ); | 0 | ||||||||||||||||||
605 | - | |||||||||||||||||||
606 | BN_CTX_start(ctx); | - | ||||||||||||||||||
607 | if ((
| 0-1911 | ||||||||||||||||||
608 | ((void *)0)
| 0-1911 | ||||||||||||||||||
609 | ) | - | ||||||||||||||||||
610 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
611 | - | |||||||||||||||||||
612 | if (!BN_GF2m_mod_arr(u, a, p)
| 0-1911 | ||||||||||||||||||
613 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
614 | - | |||||||||||||||||||
615 | n = BN_num_bits(b) - 1; | - | ||||||||||||||||||
616 | for (i = n - 1; i >= 0
| 1911-469957 | ||||||||||||||||||
617 | if (!BN_GF2m_mod_sqr_arr(u, u, p, ctx)
| 0-469957 | ||||||||||||||||||
618 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
619 | if (BN_is_bit_set(b, i)
| 156042-313915 | ||||||||||||||||||
620 | if (!BN_GF2m_mod_mul_arr(u, u, a, p, ctx)
| 0-156042 | ||||||||||||||||||
621 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
622 | } executed 156042 times by 1 test: end of block Executed by:
| 156042 | ||||||||||||||||||
623 | } executed 469957 times by 1 test: end of block Executed by:
| 469957 | ||||||||||||||||||
624 | if (!BN_copy(r, u)
| 0-1911 | ||||||||||||||||||
625 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
626 | ; | - | ||||||||||||||||||
627 | ret = 1; | - | ||||||||||||||||||
628 | err: code before this statement executed 1911 times by 1 test: err: Executed by:
| 1911 | ||||||||||||||||||
629 | BN_CTX_end(ctx); | - | ||||||||||||||||||
630 | return executed 1911 times by 1 test: ret;return ret; Executed by:
executed 1911 times by 1 test: return ret; Executed by:
| 1911 | ||||||||||||||||||
631 | } | - | ||||||||||||||||||
632 | - | |||||||||||||||||||
633 | - | |||||||||||||||||||
634 | - | |||||||||||||||||||
635 | - | |||||||||||||||||||
636 | - | |||||||||||||||||||
637 | - | |||||||||||||||||||
638 | - | |||||||||||||||||||
639 | int BN_GF2m_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, | - | ||||||||||||||||||
640 | const BIGNUM *p, BN_CTX *ctx) | - | ||||||||||||||||||
641 | { | - | ||||||||||||||||||
642 | int ret = 0; | - | ||||||||||||||||||
643 | const int max = BN_num_bits(p) + 1; | - | ||||||||||||||||||
644 | int *arr = | - | ||||||||||||||||||
645 | ((void *)0) | - | ||||||||||||||||||
646 | ; | - | ||||||||||||||||||
647 | ; | - | ||||||||||||||||||
648 | ; | - | ||||||||||||||||||
649 | ; | - | ||||||||||||||||||
650 | if ((
| 0-600 | ||||||||||||||||||
651 | ((void *)0)
| 0-600 | ||||||||||||||||||
652 | ) | - | ||||||||||||||||||
653 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
654 | ret = BN_GF2m_poly2arr(p, arr, max); | - | ||||||||||||||||||
655 | if (!ret
| 0-600 | ||||||||||||||||||
656 | ERR_put_error(3,(132),(106),__FILE__,910); | - | ||||||||||||||||||
657 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
658 | } | - | ||||||||||||||||||
659 | ret = BN_GF2m_mod_exp_arr(r, a, b, arr, ctx); | - | ||||||||||||||||||
660 | ; | - | ||||||||||||||||||
661 | err: code before this statement executed 600 times by 1 test: err: Executed by:
| 600 | ||||||||||||||||||
662 | CRYPTO_free(arr, __FILE__, 916); | - | ||||||||||||||||||
663 | return executed 600 times by 1 test: ret;return ret; Executed by:
executed 600 times by 1 test: return ret; Executed by:
| 600 | ||||||||||||||||||
664 | } | - | ||||||||||||||||||
665 | - | |||||||||||||||||||
666 | - | |||||||||||||||||||
667 | - | |||||||||||||||||||
668 | - | |||||||||||||||||||
669 | - | |||||||||||||||||||
670 | int BN_GF2m_mod_sqrt_arr(BIGNUM *r, const BIGNUM *a, const int p[], | - | ||||||||||||||||||
671 | BN_CTX *ctx) | - | ||||||||||||||||||
672 | { | - | ||||||||||||||||||
673 | int ret = 0; | - | ||||||||||||||||||
674 | BIGNUM *u; | - | ||||||||||||||||||
675 | - | |||||||||||||||||||
676 | ; | - | ||||||||||||||||||
677 | - | |||||||||||||||||||
678 | if (!p[0]
| 0-1311 | ||||||||||||||||||
679 | - | |||||||||||||||||||
680 | (BN_set_word((r),0)); | - | ||||||||||||||||||
681 | return never executed: 1;return 1; never executed: return 1; | 0 | ||||||||||||||||||
682 | } | - | ||||||||||||||||||
683 | - | |||||||||||||||||||
684 | BN_CTX_start(ctx); | - | ||||||||||||||||||
685 | if ((
| 0-1311 | ||||||||||||||||||
686 | ((void *)0)
| 0-1311 | ||||||||||||||||||
687 | ) | - | ||||||||||||||||||
688 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
689 | - | |||||||||||||||||||
690 | if (!BN_set_bit(u, p[0] - 1)
| 0-1311 | ||||||||||||||||||
691 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
692 | ret = BN_GF2m_mod_exp_arr(r, a, u, p, ctx); | - | ||||||||||||||||||
693 | ; | - | ||||||||||||||||||
694 | - | |||||||||||||||||||
695 | err: code before this statement executed 1311 times by 1 test: err: Executed by:
| 1311 | ||||||||||||||||||
696 | BN_CTX_end(ctx); | - | ||||||||||||||||||
697 | return executed 1311 times by 1 test: ret;return ret; Executed by:
executed 1311 times by 1 test: return ret; Executed by:
| 1311 | ||||||||||||||||||
698 | } | - | ||||||||||||||||||
699 | - | |||||||||||||||||||
700 | - | |||||||||||||||||||
701 | - | |||||||||||||||||||
702 | - | |||||||||||||||||||
703 | - | |||||||||||||||||||
704 | - | |||||||||||||||||||
705 | - | |||||||||||||||||||
706 | int BN_GF2m_mod_sqrt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) | - | ||||||||||||||||||
707 | { | - | ||||||||||||||||||
708 | int ret = 0; | - | ||||||||||||||||||
709 | const int max = BN_num_bits(p) + 1; | - | ||||||||||||||||||
710 | int *arr = | - | ||||||||||||||||||
711 | ((void *)0) | - | ||||||||||||||||||
712 | ; | - | ||||||||||||||||||
713 | ; | - | ||||||||||||||||||
714 | ; | - | ||||||||||||||||||
715 | if ((
| 0-200 | ||||||||||||||||||
716 | ((void *)0)
| 0-200 | ||||||||||||||||||
717 | ) | - | ||||||||||||||||||
718 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
719 | ret = BN_GF2m_poly2arr(p, arr, max); | - | ||||||||||||||||||
720 | if (!ret
| 0-200 | ||||||||||||||||||
721 | ERR_put_error(3,(137),(106),__FILE__,969); | - | ||||||||||||||||||
722 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
723 | } | - | ||||||||||||||||||
724 | ret = BN_GF2m_mod_sqrt_arr(r, a, arr, ctx); | - | ||||||||||||||||||
725 | ; | - | ||||||||||||||||||
726 | err: code before this statement executed 200 times by 1 test: err: Executed by:
| 200 | ||||||||||||||||||
727 | CRYPTO_free(arr, __FILE__, 975); | - | ||||||||||||||||||
728 | return executed 200 times by 1 test: ret;return ret; Executed by:
executed 200 times by 1 test: return ret; Executed by:
| 200 | ||||||||||||||||||
729 | } | - | ||||||||||||||||||
730 | - | |||||||||||||||||||
731 | - | |||||||||||||||||||
732 | - | |||||||||||||||||||
733 | - | |||||||||||||||||||
734 | - | |||||||||||||||||||
735 | int BN_GF2m_mod_solve_quad_arr(BIGNUM *r, const BIGNUM *a_, const int p[], | - | ||||||||||||||||||
736 | BN_CTX *ctx) | - | ||||||||||||||||||
737 | { | - | ||||||||||||||||||
738 | int ret = 0, count = 0, j; | - | ||||||||||||||||||
739 | BIGNUM *a, *z, *rho, *w, *w2, *tmp; | - | ||||||||||||||||||
740 | - | |||||||||||||||||||
741 | ; | - | ||||||||||||||||||
742 | - | |||||||||||||||||||
743 | if (!p[0]
| 0-5134 | ||||||||||||||||||
744 | - | |||||||||||||||||||
745 | (BN_set_word((r),0)); | - | ||||||||||||||||||
746 | return never executed: 1;return 1; never executed: return 1; | 0 | ||||||||||||||||||
747 | } | - | ||||||||||||||||||
748 | - | |||||||||||||||||||
749 | BN_CTX_start(ctx); | - | ||||||||||||||||||
750 | a = BN_CTX_get(ctx); | - | ||||||||||||||||||
751 | z = BN_CTX_get(ctx); | - | ||||||||||||||||||
752 | w = BN_CTX_get(ctx); | - | ||||||||||||||||||
753 | if (w ==
| 0-5134 | ||||||||||||||||||
754 | ((void *)0)
| 0-5134 | ||||||||||||||||||
755 | ) | - | ||||||||||||||||||
756 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
757 | - | |||||||||||||||||||
758 | if (!BN_GF2m_mod_arr(a, a_, p)
| 0-5134 | ||||||||||||||||||
759 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
760 | - | |||||||||||||||||||
761 | if (BN_is_zero(a)
| 98-5036 | ||||||||||||||||||
762 | (BN_set_word((r),0)); | - | ||||||||||||||||||
763 | ret = 1; | - | ||||||||||||||||||
764 | goto executed 98 times by 1 test: err;goto err; Executed by:
executed 98 times by 1 test: goto err; Executed by:
| 98 | ||||||||||||||||||
765 | } | - | ||||||||||||||||||
766 | - | |||||||||||||||||||
767 | if (p[0] & 0x1
| 1945-3091 | ||||||||||||||||||
768 | - | |||||||||||||||||||
769 | if (!BN_copy(z, a)
| 0-3091 | ||||||||||||||||||
770 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
771 | for (j = 1; j <= (p[0] - 1) / 2
| 3091-235273 | ||||||||||||||||||
772 | if (!BN_GF2m_mod_sqr_arr(z, z, p, ctx)
| 0-235273 | ||||||||||||||||||
773 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
774 | if (!BN_GF2m_mod_sqr_arr(z, z, p, ctx)
| 0-235273 | ||||||||||||||||||
775 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
776 | if (!BN_GF2m_add(z, z, a)
| 0-235273 | ||||||||||||||||||
777 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
778 | } executed 235273 times by 1 test: end of block Executed by:
| 235273 | ||||||||||||||||||
779 | - | |||||||||||||||||||
780 | } executed 3091 times by 1 test: else {end of block Executed by:
| 3091 | ||||||||||||||||||
781 | - | |||||||||||||||||||
782 | rho = BN_CTX_get(ctx); | - | ||||||||||||||||||
783 | w2 = BN_CTX_get(ctx); | - | ||||||||||||||||||
784 | tmp = BN_CTX_get(ctx); | - | ||||||||||||||||||
785 | if (tmp ==
| 0-1945 | ||||||||||||||||||
786 | ((void *)0)
| 0-1945 | ||||||||||||||||||
787 | ) | - | ||||||||||||||||||
788 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
789 | do { | - | ||||||||||||||||||
790 | if (!BN_priv_rand(rho, p[0], 0, 0)
| 0-42664 | ||||||||||||||||||
791 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
792 | if (!BN_GF2m_mod_arr(rho, rho, p)
| 0-42664 | ||||||||||||||||||
793 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
794 | (BN_set_word((z),0)); | - | ||||||||||||||||||
795 | if (!BN_copy(w, rho)
| 0-42664 | ||||||||||||||||||
796 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
797 | for (j = 1; j <= p[0] - 1
| 42664-15583288 | ||||||||||||||||||
798 | if (!BN_GF2m_mod_sqr_arr(z, z, p, ctx)
| 0-15583288 | ||||||||||||||||||
799 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
800 | if (!BN_GF2m_mod_sqr_arr(w2, w, p, ctx)
| 0-15583288 | ||||||||||||||||||
801 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
802 | if (!BN_GF2m_mod_mul_arr(tmp, w2, a, p, ctx)
| 0-15583288 | ||||||||||||||||||
803 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
804 | if (!BN_GF2m_add(z, z, tmp)
| 0-15583288 | ||||||||||||||||||
805 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
806 | if (!BN_GF2m_add(w, w2, rho)
| 0-15583288 | ||||||||||||||||||
807 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
808 | } executed 15583288 times by 1 test: end of block Executed by:
| 15583288 | ||||||||||||||||||
809 | count++; | - | ||||||||||||||||||
810 | } executed 42664 times by 1 test: while (BN_is_zero(w)end of block Executed by:
| 831-42664 | ||||||||||||||||||
811 | if (BN_is_zero(w)
| 831-1114 | ||||||||||||||||||
812 | ERR_put_error(3,(135),(113),__FILE__,1056); | - | ||||||||||||||||||
813 | goto executed 831 times by 1 test: err;goto err; Executed by:
executed 831 times by 1 test: goto err; Executed by:
| 831 | ||||||||||||||||||
814 | } | - | ||||||||||||||||||
815 | } executed 1114 times by 1 test: end of block Executed by:
| 1114 | ||||||||||||||||||
816 | - | |||||||||||||||||||
817 | if (!BN_GF2m_mod_sqr_arr(w, z, p, ctx)
| 0-4205 | ||||||||||||||||||
818 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
819 | if (!BN_GF2m_add(w, z, w)
| 0-4205 | ||||||||||||||||||
820 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
821 | if (BN_ucmp((w), (a))
| 1588-2617 | ||||||||||||||||||
822 | ERR_put_error(3,(135),(116),__FILE__,1066); | - | ||||||||||||||||||
823 | goto executed 1588 times by 1 test: err;goto err; Executed by:
executed 1588 times by 1 test: goto err; Executed by:
| 1588 | ||||||||||||||||||
824 | } | - | ||||||||||||||||||
825 | - | |||||||||||||||||||
826 | if (!BN_copy(r, z)
| 0-2617 | ||||||||||||||||||
827 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
828 | ; | - | ||||||||||||||||||
829 | - | |||||||||||||||||||
830 | ret = 1; | - | ||||||||||||||||||
831 | - | |||||||||||||||||||
832 | err: code before this statement executed 2617 times by 1 test: err: Executed by:
| 2617 | ||||||||||||||||||
833 | BN_CTX_end(ctx); | - | ||||||||||||||||||
834 | return executed 5134 times by 1 test: ret;return ret; Executed by:
executed 5134 times by 1 test: return ret; Executed by:
| 5134 | ||||||||||||||||||
835 | } | - | ||||||||||||||||||
836 | - | |||||||||||||||||||
837 | - | |||||||||||||||||||
838 | - | |||||||||||||||||||
839 | - | |||||||||||||||||||
840 | - | |||||||||||||||||||
841 | - | |||||||||||||||||||
842 | - | |||||||||||||||||||
843 | int BN_GF2m_mod_solve_quad(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | - | ||||||||||||||||||
844 | BN_CTX *ctx) | - | ||||||||||||||||||
845 | { | - | ||||||||||||||||||
846 | int ret = 0; | - | ||||||||||||||||||
847 | const int max = BN_num_bits(p) + 1; | - | ||||||||||||||||||
848 | int *arr = | - | ||||||||||||||||||
849 | ((void *)0) | - | ||||||||||||||||||
850 | ; | - | ||||||||||||||||||
851 | ; | - | ||||||||||||||||||
852 | ; | - | ||||||||||||||||||
853 | if ((
| 0-200 | ||||||||||||||||||
854 | ((void *)0)
| 0-200 | ||||||||||||||||||
855 | ) | - | ||||||||||||||||||
856 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
857 | ret = BN_GF2m_poly2arr(p, arr, max); | - | ||||||||||||||||||
858 | if (!ret
| 0-200 | ||||||||||||||||||
859 | ERR_put_error(3,(134),(106),__FILE__,1099); | - | ||||||||||||||||||
860 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
861 | } | - | ||||||||||||||||||
862 | ret = BN_GF2m_mod_solve_quad_arr(r, a, arr, ctx); | - | ||||||||||||||||||
863 | ; | - | ||||||||||||||||||
864 | err: code before this statement executed 200 times by 1 test: err: Executed by:
| 200 | ||||||||||||||||||
865 | CRYPTO_free(arr, __FILE__, 1105); | - | ||||||||||||||||||
866 | return executed 200 times by 1 test: ret;return ret; Executed by:
executed 200 times by 1 test: return ret; Executed by:
| 200 | ||||||||||||||||||
867 | } | - | ||||||||||||||||||
868 | int BN_GF2m_poly2arr(const BIGNUM *a, int p[], int max) | - | ||||||||||||||||||
869 | { | - | ||||||||||||||||||
870 | int i, j, k = 0; | - | ||||||||||||||||||
871 | unsigned long mask; | - | ||||||||||||||||||
872 | - | |||||||||||||||||||
873 | if (BN_is_zero(a)
| 0-304793 | ||||||||||||||||||
874 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
875 | - | |||||||||||||||||||
876 | for (i = a->top - 1; i >= 0
| 304793-1572388 | ||||||||||||||||||
877 | if (!a->d[i]
| 712610-859778 | ||||||||||||||||||
878 | - | |||||||||||||||||||
879 | continue; executed 859778 times by 1 test: continue; Executed by:
| 859778 | ||||||||||||||||||
880 | mask = ((unsigned long)1 << ((8 * 8) - 1)); | - | ||||||||||||||||||
881 | for (j = (8 * 8) - 1; j >= 0
| 712610-45607040 | ||||||||||||||||||
882 | if (a->d[i] & mask
| 1226623-44380417 | ||||||||||||||||||
883 | if (k < max
| 0-1226623 | ||||||||||||||||||
884 | p[k] = (8 * 8) * i + j; executed 1226623 times by 1 test: p[k] = (8 * 8) * i + j; Executed by:
| 1226623 | ||||||||||||||||||
885 | k++; | - | ||||||||||||||||||
886 | } executed 1226623 times by 1 test: end of block Executed by:
| 1226623 | ||||||||||||||||||
887 | mask >>= 1; | - | ||||||||||||||||||
888 | } executed 45607040 times by 1 test: end of block Executed by:
| 45607040 | ||||||||||||||||||
889 | } executed 712610 times by 1 test: end of block Executed by:
| 712610 | ||||||||||||||||||
890 | - | |||||||||||||||||||
891 | if (k < max
| 0-304793 | ||||||||||||||||||
892 | p[k] = -1; | - | ||||||||||||||||||
893 | k++; | - | ||||||||||||||||||
894 | } executed 304793 times by 1 test: end of block Executed by:
| 304793 | ||||||||||||||||||
895 | - | |||||||||||||||||||
896 | return executed 304793 times by 1 test: k;return k; Executed by:
executed 304793 times by 1 test: return k; Executed by:
| 304793 | ||||||||||||||||||
897 | } | - | ||||||||||||||||||
898 | - | |||||||||||||||||||
899 | - | |||||||||||||||||||
900 | - | |||||||||||||||||||
901 | - | |||||||||||||||||||
902 | - | |||||||||||||||||||
903 | int BN_GF2m_arr2poly(const int p[], BIGNUM *a) | - | ||||||||||||||||||
904 | { | - | ||||||||||||||||||
905 | int i; | - | ||||||||||||||||||
906 | - | |||||||||||||||||||
907 | ; | - | ||||||||||||||||||
908 | (BN_set_word((a),0)); | - | ||||||||||||||||||
909 | for (i = 0; p[i] != -1
| 16-64 | ||||||||||||||||||
910 | if (BN_set_bit(a, p[i]) == 0
| 0-64 | ||||||||||||||||||
911 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
912 | } executed 64 times by 1 test: end of block Executed by:
| 64 | ||||||||||||||||||
913 | ; | - | ||||||||||||||||||
914 | - | |||||||||||||||||||
915 | return executed 16 times by 1 test: 1;return 1; Executed by:
executed 16 times by 1 test: return 1; Executed by:
| 16 | ||||||||||||||||||
916 | } | - | ||||||||||||||||||
Switch to Source code | Preprocessed file |