Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/ec/ecp_mont.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||
---|---|---|---|---|---|---|---|---|
1 | - | |||||||
2 | - | |||||||
3 | - | |||||||
4 | const EC_METHOD * | - | ||||||
5 | EC_GFp_mont_method(void) | - | ||||||
6 | { | - | ||||||
7 | static const EC_METHOD ret = { | - | ||||||
8 | .flags = 0x1, | - | ||||||
9 | .field_type = 406, | - | ||||||
10 | .group_init = ec_GFp_mont_group_init, | - | ||||||
11 | .group_finish = ec_GFp_mont_group_finish, | - | ||||||
12 | .group_clear_finish = ec_GFp_mont_group_clear_finish, | - | ||||||
13 | .group_copy = ec_GFp_mont_group_copy, | - | ||||||
14 | .group_set_curve = ec_GFp_mont_group_set_curve, | - | ||||||
15 | .group_get_curve = ec_GFp_simple_group_get_curve, | - | ||||||
16 | .group_get_degree = ec_GFp_simple_group_get_degree, | - | ||||||
17 | .group_check_discriminant = | - | ||||||
18 | ec_GFp_simple_group_check_discriminant, | - | ||||||
19 | .point_init = ec_GFp_simple_point_init, | - | ||||||
20 | .point_finish = ec_GFp_simple_point_finish, | - | ||||||
21 | .point_clear_finish = ec_GFp_simple_point_clear_finish, | - | ||||||
22 | .point_copy = ec_GFp_simple_point_copy, | - | ||||||
23 | .point_set_to_infinity = ec_GFp_simple_point_set_to_infinity, | - | ||||||
24 | .point_set_Jprojective_coordinates_GFp = | - | ||||||
25 | ec_GFp_simple_set_Jprojective_coordinates_GFp, | - | ||||||
26 | .point_get_Jprojective_coordinates_GFp = | - | ||||||
27 | ec_GFp_simple_get_Jprojective_coordinates_GFp, | - | ||||||
28 | .point_set_affine_coordinates = | - | ||||||
29 | ec_GFp_simple_point_set_affine_coordinates, | - | ||||||
30 | .point_get_affine_coordinates = | - | ||||||
31 | ec_GFp_simple_point_get_affine_coordinates, | - | ||||||
32 | .add = ec_GFp_simple_add, | - | ||||||
33 | .dbl = ec_GFp_simple_dbl, | - | ||||||
34 | .invert = ec_GFp_simple_invert, | - | ||||||
35 | .is_at_infinity = ec_GFp_simple_is_at_infinity, | - | ||||||
36 | .is_on_curve = ec_GFp_simple_is_on_curve, | - | ||||||
37 | .point_cmp = ec_GFp_simple_cmp, | - | ||||||
38 | .make_affine = ec_GFp_simple_make_affine, | - | ||||||
39 | .points_make_affine = ec_GFp_simple_points_make_affine, | - | ||||||
40 | .mul_generator_ct = ec_GFp_simple_mul_generator_ct, | - | ||||||
41 | .mul_single_ct = ec_GFp_simple_mul_single_ct, | - | ||||||
42 | .mul_double_nonct = ec_GFp_simple_mul_double_nonct, | - | ||||||
43 | .field_mul = ec_GFp_mont_field_mul, | - | ||||||
44 | .field_sqr = ec_GFp_mont_field_sqr, | - | ||||||
45 | .field_encode = ec_GFp_mont_field_encode, | - | ||||||
46 | .field_decode = ec_GFp_mont_field_decode, | - | ||||||
47 | .field_set_to_one = ec_GFp_mont_field_set_to_one | - | ||||||
48 | }; | - | ||||||
49 | - | |||||||
50 | return executed 250 times by 4 tests: &ret;return &ret; Executed by:
executed 250 times by 4 tests: return &ret; Executed by:
| 250 | ||||||
51 | } | - | ||||||
52 | - | |||||||
53 | - | |||||||
54 | int | - | ||||||
55 | ec_GFp_mont_group_init(EC_GROUP * group) | - | ||||||
56 | { | - | ||||||
57 | int ok; | - | ||||||
58 | - | |||||||
59 | ok = ec_GFp_simple_group_init(group); | - | ||||||
60 | group->field_data1 = | - | ||||||
61 | ((void *)0) | - | ||||||
62 | ; | - | ||||||
63 | group->field_data2 = | - | ||||||
64 | ((void *)0) | - | ||||||
65 | ; | - | ||||||
66 | return executed 393 times by 4 tests: ok;return ok; Executed by:
executed 393 times by 4 tests: return ok; Executed by:
| 393 | ||||||
67 | } | - | ||||||
68 | - | |||||||
69 | - | |||||||
70 | void | - | ||||||
71 | ec_GFp_mont_group_finish(EC_GROUP * group) | - | ||||||
72 | { | - | ||||||
73 | BN_MONT_CTX_free(group->field_data1); | - | ||||||
74 | group->field_data1 = | - | ||||||
75 | ((void *)0) | - | ||||||
76 | ; | - | ||||||
77 | BN_free(group->field_data2); | - | ||||||
78 | group->field_data2 = | - | ||||||
79 | ((void *)0) | - | ||||||
80 | ; | - | ||||||
81 | ec_GFp_simple_group_finish(group); | - | ||||||
82 | } executed 393 times by 4 tests: end of block Executed by:
| 393 | ||||||
83 | - | |||||||
84 | - | |||||||
85 | void | - | ||||||
86 | ec_GFp_mont_group_clear_finish(EC_GROUP * group) | - | ||||||
87 | { | - | ||||||
88 | BN_MONT_CTX_free(group->field_data1); | - | ||||||
89 | group->field_data1 = | - | ||||||
90 | ((void *)0) | - | ||||||
91 | ; | - | ||||||
92 | BN_clear_free(group->field_data2); | - | ||||||
93 | group->field_data2 = | - | ||||||
94 | ((void *)0) | - | ||||||
95 | ; | - | ||||||
96 | ec_GFp_simple_group_clear_finish(group); | - | ||||||
97 | } never executed: end of block | 0 | ||||||
98 | - | |||||||
99 | - | |||||||
100 | int | - | ||||||
101 | ec_GFp_mont_group_copy(EC_GROUP * dest, const EC_GROUP * src) | - | ||||||
102 | { | - | ||||||
103 | BN_MONT_CTX_free(dest->field_data1); | - | ||||||
104 | dest->field_data1 = | - | ||||||
105 | ((void *)0) | - | ||||||
106 | ; | - | ||||||
107 | BN_clear_free(dest->field_data2); | - | ||||||
108 | dest->field_data2 = | - | ||||||
109 | ((void *)0) | - | ||||||
110 | ; | - | ||||||
111 | - | |||||||
112 | if (!ec_GFp_simple_group_copy(dest, src)
| 0-143 | ||||||
113 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||
114 | - | |||||||
115 | if (src->field_data1 !=
| 0-143 | ||||||
116 | ((void *)0)
| 0-143 | ||||||
117 | ) { | - | ||||||
118 | dest->field_data1 = BN_MONT_CTX_new(); | - | ||||||
119 | if (dest->field_data1 ==
| 0-143 | ||||||
120 | ((void *)0)
| 0-143 | ||||||
121 | ) | - | ||||||
122 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||
123 | if (!BN_MONT_CTX_copy(dest->field_data1, src->field_data1)
| 0-143 | ||||||
124 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||
125 | } executed 143 times by 3 tests: end of block Executed by:
| 143 | ||||||
126 | if (src->field_data2 !=
| 0-143 | ||||||
127 | ((void *)0)
| 0-143 | ||||||
128 | ) { | - | ||||||
129 | dest->field_data2 = BN_dup(src->field_data2); | - | ||||||
130 | if (dest->field_data2 ==
| 0-143 | ||||||
131 | ((void *)0)
| 0-143 | ||||||
132 | ) | - | ||||||
133 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||
134 | } executed 143 times by 3 tests: end of block Executed by:
| 143 | ||||||
135 | return executed 143 times by 3 tests: 1;return 1; Executed by:
executed 143 times by 3 tests: return 1; Executed by:
| 143 | ||||||
136 | - | |||||||
137 | err: | - | ||||||
138 | if (dest->field_data1 !=
| 0 | ||||||
139 | ((void *)0)
| 0 | ||||||
140 | ) { | - | ||||||
141 | BN_MONT_CTX_free(dest->field_data1); | - | ||||||
142 | dest->field_data1 = | - | ||||||
143 | ((void *)0) | - | ||||||
144 | ; | - | ||||||
145 | } never executed: end of block | 0 | ||||||
146 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||
147 | } | - | ||||||
148 | - | |||||||
149 | - | |||||||
150 | int | - | ||||||
151 | ec_GFp_mont_group_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, | - | ||||||
152 | const BIGNUM *b, BN_CTX *ctx) | - | ||||||
153 | { | - | ||||||
154 | BN_CTX *new_ctx = | - | ||||||
155 | ((void *)0) | - | ||||||
156 | ; | - | ||||||
157 | BN_MONT_CTX *mont = | - | ||||||
158 | ((void *)0) | - | ||||||
159 | ; | - | ||||||
160 | BIGNUM *one = | - | ||||||
161 | ((void *)0) | - | ||||||
162 | ; | - | ||||||
163 | int ret = 0; | - | ||||||
164 | - | |||||||
165 | BN_MONT_CTX_free(group->field_data1); | - | ||||||
166 | group->field_data1 = | - | ||||||
167 | ((void *)0) | - | ||||||
168 | ; | - | ||||||
169 | BN_free(group->field_data2); | - | ||||||
170 | group->field_data2 = | - | ||||||
171 | ((void *)0) | - | ||||||
172 | ; | - | ||||||
173 | if (ctx ==
| 0-256 | ||||||
174 | ((void *)0)
| 0-256 | ||||||
175 | ) { | - | ||||||
176 | ctx = new_ctx = BN_CTX_new(); | - | ||||||
177 | if (ctx ==
| 0 | ||||||
178 | ((void *)0)
| 0 | ||||||
179 | ) | - | ||||||
180 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||
181 | } never executed: end of block | 0 | ||||||
182 | mont = BN_MONT_CTX_new(); | - | ||||||
183 | if (mont ==
| 0-256 | ||||||
184 | ((void *)0)
| 0-256 | ||||||
185 | ) | - | ||||||
186 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||
187 | if (!BN_MONT_CTX_set(mont, p, ctx)
| 0-256 | ||||||
188 | ERR_put_error(16,(0xfff),(3),__FILE__,209); | - | ||||||
189 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||
190 | } | - | ||||||
191 | one = BN_new(); | - | ||||||
192 | if (one ==
| 0-256 | ||||||
193 | ((void *)0)
| 0-256 | ||||||
194 | ) | - | ||||||
195 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||
196 | if (!BN_mod_mul_montgomery( (one),(BN_value_one()),&((mont)->RR),(mont),(ctx))
| 0-256 | ||||||
197 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||
198 | - | |||||||
199 | group->field_data1 = mont; | - | ||||||
200 | mont = | - | ||||||
201 | ((void *)0) | - | ||||||
202 | ; | - | ||||||
203 | group->field_data2 = one; | - | ||||||
204 | one = | - | ||||||
205 | ((void *)0) | - | ||||||
206 | ; | - | ||||||
207 | - | |||||||
208 | ret = ec_GFp_simple_group_set_curve(group, p, a, b, ctx); | - | ||||||
209 | - | |||||||
210 | if (!ret
| 0-256 | ||||||
211 | BN_MONT_CTX_free(group->field_data1); | - | ||||||
212 | group->field_data1 = | - | ||||||
213 | ((void *)0) | - | ||||||
214 | ; | - | ||||||
215 | BN_free(group->field_data2); | - | ||||||
216 | group->field_data2 = | - | ||||||
217 | ((void *)0) | - | ||||||
218 | ; | - | ||||||
219 | } never executed: end of block | 0 | ||||||
220 | err: code before this statement executed 256 times by 4 tests: err: Executed by:
| 256 | ||||||
221 | BN_CTX_free(new_ctx); | - | ||||||
222 | BN_MONT_CTX_free(mont); | - | ||||||
223 | BN_free(one); | - | ||||||
224 | return executed 256 times by 4 tests: ret;return ret; Executed by:
executed 256 times by 4 tests: return ret; Executed by:
| 256 | ||||||
225 | } | - | ||||||
226 | - | |||||||
227 | - | |||||||
228 | int | - | ||||||
229 | ec_GFp_mont_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, | - | ||||||
230 | const BIGNUM *b, BN_CTX *ctx) | - | ||||||
231 | { | - | ||||||
232 | if (group->field_data1 ==
| 0-2126344 | ||||||
233 | ((void *)0)
| 0-2126344 | ||||||
234 | ) { | - | ||||||
235 | ERR_put_error(16,(0xfff),(111),__FILE__,244); | - | ||||||
236 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||
237 | } | - | ||||||
238 | return executed 2126344 times by 4 tests: BN_mod_mul_montgomery(r, a, b, group->field_data1, ctx);return BN_mod_mul_montgomery(r, a, b, group->field_data1, ctx); Executed by:
executed 2126344 times by 4 tests: return BN_mod_mul_montgomery(r, a, b, group->field_data1, ctx); Executed by:
| 2126344 | ||||||
239 | } | - | ||||||
240 | - | |||||||
241 | - | |||||||
242 | int | - | ||||||
243 | ec_GFp_mont_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, | - | ||||||
244 | BN_CTX *ctx) | - | ||||||
245 | { | - | ||||||
246 | if (group->field_data1 ==
| 0-1232339 | ||||||
247 | ((void *)0)
| 0-1232339 | ||||||
248 | ) { | - | ||||||
249 | ERR_put_error(16,(0xfff),(111),__FILE__,256); | - | ||||||
250 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||
251 | } | - | ||||||
252 | return executed 1232339 times by 4 tests: BN_mod_mul_montgomery(r, a, a, group->field_data1, ctx);return BN_mod_mul_montgomery(r, a, a, group->field_data1, ctx); Executed by:
executed 1232339 times by 4 tests: return BN_mod_mul_montgomery(r, a, a, group->field_data1, ctx); Executed by:
| 1232339 | ||||||
253 | } | - | ||||||
254 | - | |||||||
255 | - | |||||||
256 | int | - | ||||||
257 | ec_GFp_mont_field_encode(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, | - | ||||||
258 | BN_CTX *ctx) | - | ||||||
259 | { | - | ||||||
260 | if (group->field_data1 ==
| 0-1542 | ||||||
261 | ((void *)0)
| 0-1542 | ||||||
262 | ) { | - | ||||||
263 | ERR_put_error(16,(0xfff),(111),__FILE__,268); | - | ||||||
264 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||
265 | } | - | ||||||
266 | return executed 1542 times by 4 tests: BN_mod_mul_montgomery( (r),(a),&(((BN_MONT_CTX *) group->field_data1)->RR),((BN_MONT_CTX *) group->field_data1),(ctx));return BN_mod_mul_montgomery( (r),(a),&(((BN_MONT_CTX *) group->field_data1)->RR),((BN_MONT_CTX *) group->field_data1),(ctx)); Executed by:
executed 1542 times by 4 tests: return BN_mod_mul_montgomery( (r),(a),&(((BN_MONT_CTX *) group->field_data1)->RR),((BN_MONT_CTX *) group->field_data1),(ctx)); Executed by:
| 1542 | ||||||
267 | } | - | ||||||
268 | - | |||||||
269 | - | |||||||
270 | int | - | ||||||
271 | ec_GFp_mont_field_decode(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, | - | ||||||
272 | BN_CTX *ctx) | - | ||||||
273 | { | - | ||||||
274 | if (group->field_data1 ==
| 0-515 | ||||||
275 | ((void *)0)
| 0-515 | ||||||
276 | ) { | - | ||||||
277 | ERR_put_error(16,(0xfff),(111),__FILE__,280); | - | ||||||
278 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||
279 | } | - | ||||||
280 | return executed 515 times by 4 tests: BN_from_montgomery(r, a, group->field_data1, ctx);return BN_from_montgomery(r, a, group->field_data1, ctx); Executed by:
executed 515 times by 4 tests: return BN_from_montgomery(r, a, group->field_data1, ctx); Executed by:
| 515 | ||||||
281 | } | - | ||||||
282 | - | |||||||
283 | - | |||||||
284 | int | - | ||||||
285 | ec_GFp_mont_field_set_to_one(const EC_GROUP *group, BIGNUM *r, BN_CTX *ctx) | - | ||||||
286 | { | - | ||||||
287 | if (group->field_data2 ==
| 0-2385 | ||||||
288 | ((void *)0)
| 0-2385 | ||||||
289 | ) { | - | ||||||
290 | ERR_put_error(16,(0xfff),(111),__FILE__,291); | - | ||||||
291 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||
292 | } | - | ||||||
293 | if (!BN_copy(r, group->field_data2)
| 0-2385 | ||||||
294 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||
295 | return executed 2385 times by 4 tests: 1;return 1; Executed by:
executed 2385 times by 4 tests: return 1; Executed by:
| 2385 | ||||||
296 | } | - | ||||||
Switch to Source code | Preprocessed file |