Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/ec/ec2_smpl.c |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /* $OpenBSD: ec2_smpl.c,v 1.20 2018/07/16 17:32:39 tb Exp $ */ | - | ||||||||||||
2 | /* ==================================================================== | - | ||||||||||||
3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | - | ||||||||||||
4 | * | - | ||||||||||||
5 | * The Elliptic Curve Public-Key Crypto Library (ECC Code) included | - | ||||||||||||
6 | * herein is developed by SUN MICROSYSTEMS, INC., and is contributed | - | ||||||||||||
7 | * to the OpenSSL project. | - | ||||||||||||
8 | * | - | ||||||||||||
9 | * The ECC Code is licensed pursuant to the OpenSSL open source | - | ||||||||||||
10 | * license provided below. | - | ||||||||||||
11 | * | - | ||||||||||||
12 | * The software is originally written by Sheueling Chang Shantz and | - | ||||||||||||
13 | * Douglas Stebila of Sun Microsystems Laboratories. | - | ||||||||||||
14 | * | - | ||||||||||||
15 | */ | - | ||||||||||||
16 | /* ==================================================================== | - | ||||||||||||
17 | * Copyright (c) 1998-2005 The OpenSSL Project. All rights reserved. | - | ||||||||||||
18 | * | - | ||||||||||||
19 | * Redistribution and use in source and binary forms, with or without | - | ||||||||||||
20 | * modification, are permitted provided that the following conditions | - | ||||||||||||
21 | * are met: | - | ||||||||||||
22 | * | - | ||||||||||||
23 | * 1. Redistributions of source code must retain the above copyright | - | ||||||||||||
24 | * notice, this list of conditions and the following disclaimer. | - | ||||||||||||
25 | * | - | ||||||||||||
26 | * 2. Redistributions in binary form must reproduce the above copyright | - | ||||||||||||
27 | * notice, this list of conditions and the following disclaimer in | - | ||||||||||||
28 | * the documentation and/or other materials provided with the | - | ||||||||||||
29 | * distribution. | - | ||||||||||||
30 | * | - | ||||||||||||
31 | * 3. All advertising materials mentioning features or use of this | - | ||||||||||||
32 | * software must display the following acknowledgment: | - | ||||||||||||
33 | * "This product includes software developed by the OpenSSL Project | - | ||||||||||||
34 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | - | ||||||||||||
35 | * | - | ||||||||||||
36 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | - | ||||||||||||
37 | * endorse or promote products derived from this software without | - | ||||||||||||
38 | * prior written permission. For written permission, please contact | - | ||||||||||||
39 | * openssl-core@openssl.org. | - | ||||||||||||
40 | * | - | ||||||||||||
41 | * 5. Products derived from this software may not be called "OpenSSL" | - | ||||||||||||
42 | * nor may "OpenSSL" appear in their names without prior written | - | ||||||||||||
43 | * permission of the OpenSSL Project. | - | ||||||||||||
44 | * | - | ||||||||||||
45 | * 6. Redistributions of any form whatsoever must retain the following | - | ||||||||||||
46 | * acknowledgment: | - | ||||||||||||
47 | * "This product includes software developed by the OpenSSL Project | - | ||||||||||||
48 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | - | ||||||||||||
49 | * | - | ||||||||||||
50 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | - | ||||||||||||
51 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | - | ||||||||||||
52 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | - | ||||||||||||
53 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | - | ||||||||||||
54 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | - | ||||||||||||
55 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | - | ||||||||||||
56 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | - | ||||||||||||
57 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | - | ||||||||||||
58 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | - | ||||||||||||
59 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | - | ||||||||||||
60 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | - | ||||||||||||
61 | * OF THE POSSIBILITY OF SUCH DAMAGE. | - | ||||||||||||
62 | * ==================================================================== | - | ||||||||||||
63 | * | - | ||||||||||||
64 | * This product includes cryptographic software written by Eric Young | - | ||||||||||||
65 | * (eay@cryptsoft.com). This product includes software written by Tim | - | ||||||||||||
66 | * Hudson (tjh@cryptsoft.com). | - | ||||||||||||
67 | * | - | ||||||||||||
68 | */ | - | ||||||||||||
69 | - | |||||||||||||
70 | #include <openssl/opensslconf.h> | - | ||||||||||||
71 | - | |||||||||||||
72 | #include <openssl/err.h> | - | ||||||||||||
73 | - | |||||||||||||
74 | #include "ec_lcl.h" | - | ||||||||||||
75 | - | |||||||||||||
76 | #ifndef OPENSSL_NO_EC2M | - | ||||||||||||
77 | - | |||||||||||||
78 | const EC_METHOD * | - | ||||||||||||
79 | EC_GF2m_simple_method(void) | - | ||||||||||||
80 | { | - | ||||||||||||
81 | static const EC_METHOD ret = { | - | ||||||||||||
82 | .flags = EC_FLAGS_DEFAULT_OCT, | - | ||||||||||||
83 | .field_type = NID_X9_62_characteristic_two_field, | - | ||||||||||||
84 | .group_init = ec_GF2m_simple_group_init, | - | ||||||||||||
85 | .group_finish = ec_GF2m_simple_group_finish, | - | ||||||||||||
86 | .group_clear_finish = ec_GF2m_simple_group_clear_finish, | - | ||||||||||||
87 | .group_copy = ec_GF2m_simple_group_copy, | - | ||||||||||||
88 | .group_set_curve = ec_GF2m_simple_group_set_curve, | - | ||||||||||||
89 | .group_get_curve = ec_GF2m_simple_group_get_curve, | - | ||||||||||||
90 | .group_get_degree = ec_GF2m_simple_group_get_degree, | - | ||||||||||||
91 | .group_check_discriminant = | - | ||||||||||||
92 | ec_GF2m_simple_group_check_discriminant, | - | ||||||||||||
93 | .point_init = ec_GF2m_simple_point_init, | - | ||||||||||||
94 | .point_finish = ec_GF2m_simple_point_finish, | - | ||||||||||||
95 | .point_clear_finish = ec_GF2m_simple_point_clear_finish, | - | ||||||||||||
96 | .point_copy = ec_GF2m_simple_point_copy, | - | ||||||||||||
97 | .point_set_to_infinity = ec_GF2m_simple_point_set_to_infinity, | - | ||||||||||||
98 | .point_set_affine_coordinates = | - | ||||||||||||
99 | ec_GF2m_simple_point_set_affine_coordinates, | - | ||||||||||||
100 | .point_get_affine_coordinates = | - | ||||||||||||
101 | ec_GF2m_simple_point_get_affine_coordinates, | - | ||||||||||||
102 | .add = ec_GF2m_simple_add, | - | ||||||||||||
103 | .dbl = ec_GF2m_simple_dbl, | - | ||||||||||||
104 | .invert = ec_GF2m_simple_invert, | - | ||||||||||||
105 | .is_at_infinity = ec_GF2m_simple_is_at_infinity, | - | ||||||||||||
106 | .is_on_curve = ec_GF2m_simple_is_on_curve, | - | ||||||||||||
107 | .point_cmp = ec_GF2m_simple_cmp, | - | ||||||||||||
108 | .make_affine = ec_GF2m_simple_make_affine, | - | ||||||||||||
109 | .points_make_affine = ec_GF2m_simple_points_make_affine, | - | ||||||||||||
110 | .mul_generator_ct = ec_GFp_simple_mul_generator_ct, | - | ||||||||||||
111 | .mul_single_ct = ec_GFp_simple_mul_single_ct, | - | ||||||||||||
112 | .mul_double_nonct = ec_GFp_simple_mul_double_nonct, | - | ||||||||||||
113 | .precompute_mult = ec_GF2m_precompute_mult, | - | ||||||||||||
114 | .have_precompute_mult = ec_GF2m_have_precompute_mult, | - | ||||||||||||
115 | .field_mul = ec_GF2m_simple_field_mul, | - | ||||||||||||
116 | .field_sqr = ec_GF2m_simple_field_sqr, | - | ||||||||||||
117 | .field_div = ec_GF2m_simple_field_div, | - | ||||||||||||
118 | }; | - | ||||||||||||
119 | - | |||||||||||||
120 | return &ret; executed 138 times by 3 tests: return &ret; Executed by:
| 138 | ||||||||||||
121 | } | - | ||||||||||||
122 | - | |||||||||||||
123 | - | |||||||||||||
124 | /* Initialize a GF(2^m)-based EC_GROUP structure. | - | ||||||||||||
125 | * Note that all other members are handled by EC_GROUP_new. | - | ||||||||||||
126 | */ | - | ||||||||||||
127 | int | - | ||||||||||||
128 | ec_GF2m_simple_group_init(EC_GROUP * group) | - | ||||||||||||
129 | { | - | ||||||||||||
130 | BN_init(&group->field); | - | ||||||||||||
131 | BN_init(&group->a); | - | ||||||||||||
132 | BN_init(&group->b); | - | ||||||||||||
133 | return 1; executed 224 times by 3 tests: return 1; Executed by:
| 224 | ||||||||||||
134 | } | - | ||||||||||||
135 | - | |||||||||||||
136 | - | |||||||||||||
137 | /* Free a GF(2^m)-based EC_GROUP structure. | - | ||||||||||||
138 | * Note that all other members are handled by EC_GROUP_free. | - | ||||||||||||
139 | */ | - | ||||||||||||
140 | void | - | ||||||||||||
141 | ec_GF2m_simple_group_finish(EC_GROUP * group) | - | ||||||||||||
142 | { | - | ||||||||||||
143 | BN_free(&group->field); | - | ||||||||||||
144 | BN_free(&group->a); | - | ||||||||||||
145 | BN_free(&group->b); | - | ||||||||||||
146 | } executed 224 times by 3 tests: end of block Executed by:
| 224 | ||||||||||||
147 | - | |||||||||||||
148 | - | |||||||||||||
149 | /* Clear and free a GF(2^m)-based EC_GROUP structure. | - | ||||||||||||
150 | * Note that all other members are handled by EC_GROUP_clear_free. | - | ||||||||||||
151 | */ | - | ||||||||||||
152 | void | - | ||||||||||||
153 | ec_GF2m_simple_group_clear_finish(EC_GROUP * group) | - | ||||||||||||
154 | { | - | ||||||||||||
155 | BN_clear_free(&group->field); | - | ||||||||||||
156 | BN_clear_free(&group->a); | - | ||||||||||||
157 | BN_clear_free(&group->b); | - | ||||||||||||
158 | group->poly[0] = 0; | - | ||||||||||||
159 | group->poly[1] = 0; | - | ||||||||||||
160 | group->poly[2] = 0; | - | ||||||||||||
161 | group->poly[3] = 0; | - | ||||||||||||
162 | group->poly[4] = 0; | - | ||||||||||||
163 | group->poly[5] = -1; | - | ||||||||||||
164 | } never executed: end of block | 0 | ||||||||||||
165 | - | |||||||||||||
166 | - | |||||||||||||
167 | /* Copy a GF(2^m)-based EC_GROUP structure. | - | ||||||||||||
168 | * Note that all other members are handled by EC_GROUP_copy. | - | ||||||||||||
169 | */ | - | ||||||||||||
170 | int | - | ||||||||||||
171 | ec_GF2m_simple_group_copy(EC_GROUP * dest, const EC_GROUP * src) | - | ||||||||||||
172 | { | - | ||||||||||||
173 | int i; | - | ||||||||||||
174 | - | |||||||||||||
175 | if (!BN_copy(&dest->field, &src->field))
| 0-86 | ||||||||||||
176 | return 0; never executed: return 0; | 0 | ||||||||||||
177 | if (!BN_copy(&dest->a, &src->a))
| 0-86 | ||||||||||||
178 | return 0; never executed: return 0; | 0 | ||||||||||||
179 | if (!BN_copy(&dest->b, &src->b))
| 0-86 | ||||||||||||
180 | return 0; never executed: return 0; | 0 | ||||||||||||
181 | dest->poly[0] = src->poly[0]; | - | ||||||||||||
182 | dest->poly[1] = src->poly[1]; | - | ||||||||||||
183 | dest->poly[2] = src->poly[2]; | - | ||||||||||||
184 | dest->poly[3] = src->poly[3]; | - | ||||||||||||
185 | dest->poly[4] = src->poly[4]; | - | ||||||||||||
186 | dest->poly[5] = src->poly[5]; | - | ||||||||||||
187 | if (bn_wexpand(&dest->a, (int) (dest->poly[0] + BN_BITS2 - 1) / BN_BITS2) == NULL)
| 0-86 | ||||||||||||
188 | return 0; never executed: return 0; | 0 | ||||||||||||
189 | if (bn_wexpand(&dest->b, (int) (dest->poly[0] + BN_BITS2 - 1) / BN_BITS2) == NULL)
| 0-86 | ||||||||||||
190 | return 0; never executed: return 0; | 0 | ||||||||||||
191 | for (i = dest->a.top; i < dest->a.dmax; i++)
| 86-190 | ||||||||||||
192 | dest->a.d[i] = 0; executed 190 times by 2 tests: dest->a.d[i] = 0; Executed by:
| 190 | ||||||||||||
193 | for (i = dest->b.top; i < dest->b.dmax; i++)
| 86-92 | ||||||||||||
194 | dest->b.d[i] = 0; executed 92 times by 2 tests: dest->b.d[i] = 0; Executed by:
| 92 | ||||||||||||
195 | return 1; executed 86 times by 2 tests: return 1; Executed by:
| 86 | ||||||||||||
196 | } | - | ||||||||||||
197 | - | |||||||||||||
198 | - | |||||||||||||
199 | /* Set the curve parameters of an EC_GROUP structure. */ | - | ||||||||||||
200 | int | - | ||||||||||||
201 | ec_GF2m_simple_group_set_curve(EC_GROUP * group, | - | ||||||||||||
202 | const BIGNUM * p, const BIGNUM * a, const BIGNUM * b, BN_CTX * ctx) | - | ||||||||||||
203 | { | - | ||||||||||||
204 | int ret = 0, i; | - | ||||||||||||
205 | - | |||||||||||||
206 | /* group->field */ | - | ||||||||||||
207 | if (!BN_copy(&group->field, p))
| 0-148 | ||||||||||||
208 | goto err; never executed: goto err; | 0 | ||||||||||||
209 | i = BN_GF2m_poly2arr(&group->field, group->poly, 6) - 1; | - | ||||||||||||
210 | if ((i != 5) && (i != 3)) {
| 0-75 | ||||||||||||
211 | ECerror(EC_R_UNSUPPORTED_FIELD); | - | ||||||||||||
212 | goto err; never executed: goto err; | 0 | ||||||||||||
213 | } | - | ||||||||||||
214 | /* group->a */ | - | ||||||||||||
215 | if (!BN_GF2m_mod_arr(&group->a, a, group->poly))
| 0-148 | ||||||||||||
216 | goto err; never executed: goto err; | 0 | ||||||||||||
217 | if (bn_wexpand(&group->a, (int) (group->poly[0] + BN_BITS2 - 1) / BN_BITS2) == NULL)
| 0-148 | ||||||||||||
218 | goto err; never executed: goto err; | 0 | ||||||||||||
219 | for (i = group->a.top; i < group->a.dmax; i++)
| 148-365 | ||||||||||||
220 | group->a.d[i] = 0; executed 365 times by 3 tests: group->a.d[i] = 0; Executed by:
| 365 | ||||||||||||
221 | - | |||||||||||||
222 | /* group->b */ | - | ||||||||||||
223 | if (!BN_GF2m_mod_arr(&group->b, b, group->poly))
| 0-148 | ||||||||||||
224 | goto err; never executed: goto err; | 0 | ||||||||||||
225 | if (bn_wexpand(&group->b, (int) (group->poly[0] + BN_BITS2 - 1) / BN_BITS2) == NULL)
| 0-148 | ||||||||||||
226 | goto err; never executed: goto err; | 0 | ||||||||||||
227 | for (i = group->b.top; i < group->b.dmax; i++)
| 148-176 | ||||||||||||
228 | group->b.d[i] = 0; executed 176 times by 3 tests: group->b.d[i] = 0; Executed by:
| 176 | ||||||||||||
229 | - | |||||||||||||
230 | ret = 1; | - | ||||||||||||
231 | err: code before this statement executed 148 times by 3 tests: err: Executed by:
| 148 | ||||||||||||
232 | return ret; executed 148 times by 3 tests: return ret; Executed by:
| 148 | ||||||||||||
233 | } | - | ||||||||||||
234 | - | |||||||||||||
235 | - | |||||||||||||
236 | /* Get the curve parameters of an EC_GROUP structure. | - | ||||||||||||
237 | * If p, a, or b are NULL then there values will not be set but the method will return with success. | - | ||||||||||||
238 | */ | - | ||||||||||||
239 | int | - | ||||||||||||
240 | ec_GF2m_simple_group_get_curve(const EC_GROUP *group, | - | ||||||||||||
241 | BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx) | - | ||||||||||||
242 | { | - | ||||||||||||
243 | int ret = 0; | - | ||||||||||||
244 | - | |||||||||||||
245 | if (p != NULL) {
| 0-1 | ||||||||||||
246 | if (!BN_copy(p, &group->field))
| 0-1 | ||||||||||||
247 | return 0; never executed: return 0; | 0 | ||||||||||||
248 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||
249 | if (a != NULL) {
| 0-1 | ||||||||||||
250 | if (!BN_copy(a, &group->a))
| 0-1 | ||||||||||||
251 | goto err; never executed: goto err; | 0 | ||||||||||||
252 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||
253 | if (b != NULL) {
| 0-1 | ||||||||||||
254 | if (!BN_copy(b, &group->b))
| 0-1 | ||||||||||||
255 | goto err; never executed: goto err; | 0 | ||||||||||||
256 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||
257 | ret = 1; | - | ||||||||||||
258 | - | |||||||||||||
259 | err: code before this statement executed 1 time by 1 test: err: Executed by:
| 1 | ||||||||||||
260 | return ret; executed 1 time by 1 test: return ret; Executed by:
| 1 | ||||||||||||
261 | } | - | ||||||||||||
262 | - | |||||||||||||
263 | - | |||||||||||||
264 | /* Gets the degree of the field. For a curve over GF(2^m) this is the value m. */ | - | ||||||||||||
265 | int | - | ||||||||||||
266 | ec_GF2m_simple_group_get_degree(const EC_GROUP * group) | - | ||||||||||||
267 | { | - | ||||||||||||
268 | return BN_num_bits(&group->field) - 1; executed 73 times by 3 tests: return BN_num_bits(&group->field) - 1; Executed by:
| 73 | ||||||||||||
269 | } | - | ||||||||||||
270 | - | |||||||||||||
271 | - | |||||||||||||
272 | /* Checks the discriminant of the curve. | - | ||||||||||||
273 | * y^2 + x*y = x^3 + a*x^2 + b is an elliptic curve <=> b != 0 (mod p) | - | ||||||||||||
274 | */ | - | ||||||||||||
275 | int | - | ||||||||||||
276 | ec_GF2m_simple_group_check_discriminant(const EC_GROUP * group, BN_CTX * ctx) | - | ||||||||||||
277 | { | - | ||||||||||||
278 | int ret = 0; | - | ||||||||||||
279 | BIGNUM *b; | - | ||||||||||||
280 | BN_CTX *new_ctx = NULL; | - | ||||||||||||
281 | - | |||||||||||||
282 | if (ctx == NULL) {
| 0-42 | ||||||||||||
283 | ctx = new_ctx = BN_CTX_new(); | - | ||||||||||||
284 | if (ctx == NULL) {
| 0 | ||||||||||||
285 | ECerror(ERR_R_MALLOC_FAILURE); | - | ||||||||||||
286 | goto err; never executed: goto err; | 0 | ||||||||||||
287 | } | - | ||||||||||||
288 | } never executed: end of block | 0 | ||||||||||||
289 | BN_CTX_start(ctx); | - | ||||||||||||
290 | if ((b = BN_CTX_get(ctx)) == NULL)
| 0-42 | ||||||||||||
291 | goto err; never executed: goto err; | 0 | ||||||||||||
292 | - | |||||||||||||
293 | if (!BN_GF2m_mod_arr(b, &group->b, group->poly))
| 0-42 | ||||||||||||
294 | goto err; never executed: goto err; | 0 | ||||||||||||
295 | - | |||||||||||||
296 | /* | - | ||||||||||||
297 | * check the discriminant: y^2 + x*y = x^3 + a*x^2 + b is an elliptic | - | ||||||||||||
298 | * curve <=> b != 0 (mod p) | - | ||||||||||||
299 | */ | - | ||||||||||||
300 | if (BN_is_zero(b))
| 0-42 | ||||||||||||
301 | goto err; never executed: goto err; | 0 | ||||||||||||
302 | - | |||||||||||||
303 | ret = 1; | - | ||||||||||||
304 | - | |||||||||||||
305 | err: code before this statement executed 42 times by 1 test: err: Executed by:
| 42 | ||||||||||||
306 | if (ctx != NULL)
| 0-42 | ||||||||||||
307 | BN_CTX_end(ctx); executed 42 times by 1 test: BN_CTX_end(ctx); Executed by:
| 42 | ||||||||||||
308 | BN_CTX_free(new_ctx); | - | ||||||||||||
309 | return ret; executed 42 times by 1 test: return ret; Executed by:
| 42 | ||||||||||||
310 | } | - | ||||||||||||
311 | - | |||||||||||||
312 | - | |||||||||||||
313 | /* Initializes an EC_POINT. */ | - | ||||||||||||
314 | int | - | ||||||||||||
315 | ec_GF2m_simple_point_init(EC_POINT * point) | - | ||||||||||||
316 | { | - | ||||||||||||
317 | BN_init(&point->X); | - | ||||||||||||
318 | BN_init(&point->Y); | - | ||||||||||||
319 | BN_init(&point->Z); | - | ||||||||||||
320 | return 1; executed 6253 times by 3 tests: return 1; Executed by:
| 6253 | ||||||||||||
321 | } | - | ||||||||||||
322 | - | |||||||||||||
323 | - | |||||||||||||
324 | /* Frees an EC_POINT. */ | - | ||||||||||||
325 | void | - | ||||||||||||
326 | ec_GF2m_simple_point_finish(EC_POINT * point) | - | ||||||||||||
327 | { | - | ||||||||||||
328 | BN_free(&point->X); | - | ||||||||||||
329 | BN_free(&point->Y); | - | ||||||||||||
330 | BN_free(&point->Z); | - | ||||||||||||
331 | } executed 4621 times by 3 tests: end of block Executed by:
| 4621 | ||||||||||||
332 | - | |||||||||||||
333 | - | |||||||||||||
334 | /* Clears and frees an EC_POINT. */ | - | ||||||||||||
335 | void | - | ||||||||||||
336 | ec_GF2m_simple_point_clear_finish(EC_POINT * point) | - | ||||||||||||
337 | { | - | ||||||||||||
338 | BN_clear_free(&point->X); | - | ||||||||||||
339 | BN_clear_free(&point->Y); | - | ||||||||||||
340 | BN_clear_free(&point->Z); | - | ||||||||||||
341 | point->Z_is_one = 0; | - | ||||||||||||
342 | } executed 1632 times by 1 test: end of block Executed by:
| 1632 | ||||||||||||
343 | - | |||||||||||||
344 | - | |||||||||||||
345 | /* Copy the contents of one EC_POINT into another. Assumes dest is initialized. */ | - | ||||||||||||
346 | int | - | ||||||||||||
347 | ec_GF2m_simple_point_copy(EC_POINT * dest, const EC_POINT * src) | - | ||||||||||||
348 | { | - | ||||||||||||
349 | if (!BN_copy(&dest->X, &src->X))
| 0-1784 | ||||||||||||
350 | return 0; never executed: return 0; | 0 | ||||||||||||
351 | if (!BN_copy(&dest->Y, &src->Y))
| 0-1784 | ||||||||||||
352 | return 0; never executed: return 0; | 0 | ||||||||||||
353 | if (!BN_copy(&dest->Z, &src->Z))
| 0-1784 | ||||||||||||
354 | return 0; never executed: return 0; | 0 | ||||||||||||
355 | dest->Z_is_one = src->Z_is_one; | - | ||||||||||||
356 | - | |||||||||||||
357 | return 1; executed 1784 times by 3 tests: return 1; Executed by:
| 1784 | ||||||||||||
358 | } | - | ||||||||||||
359 | - | |||||||||||||
360 | - | |||||||||||||
361 | /* Set an EC_POINT to the point at infinity. | - | ||||||||||||
362 | * A point at infinity is represented by having Z=0. | - | ||||||||||||
363 | */ | - | ||||||||||||
364 | int | - | ||||||||||||
365 | ec_GF2m_simple_point_set_to_infinity(const EC_GROUP * group, EC_POINT * point) | - | ||||||||||||
366 | { | - | ||||||||||||
367 | point->Z_is_one = 0; | - | ||||||||||||
368 | BN_zero(&point->Z); | - | ||||||||||||
369 | return 1; executed 101 times by 2 tests: return 1; Executed by:
| 101 | ||||||||||||
370 | } | - | ||||||||||||
371 | - | |||||||||||||
372 | - | |||||||||||||
373 | /* Set the coordinates of an EC_POINT using affine coordinates. | - | ||||||||||||
374 | * Note that the simple implementation only uses affine coordinates. | - | ||||||||||||
375 | */ | - | ||||||||||||
376 | int | - | ||||||||||||
377 | ec_GF2m_simple_point_set_affine_coordinates(const EC_GROUP * group, EC_POINT * point, | - | ||||||||||||
378 | const BIGNUM * x, const BIGNUM * y, BN_CTX * ctx) | - | ||||||||||||
379 | { | - | ||||||||||||
380 | int ret = 0; | - | ||||||||||||
381 | if (x == NULL || y == NULL) {
| 0-215026 | ||||||||||||
382 | ECerror(ERR_R_PASSED_NULL_PARAMETER); | - | ||||||||||||
383 | return 0; never executed: return 0; | 0 | ||||||||||||
384 | } | - | ||||||||||||
385 | if (!BN_copy(&point->X, x))
| 0-215026 | ||||||||||||
386 | goto err; never executed: goto err; | 0 | ||||||||||||
387 | BN_set_negative(&point->X, 0); | - | ||||||||||||
388 | if (!BN_copy(&point->Y, y))
| 0-215026 | ||||||||||||
389 | goto err; never executed: goto err; | 0 | ||||||||||||
390 | BN_set_negative(&point->Y, 0); | - | ||||||||||||
391 | if (!BN_copy(&point->Z, BN_value_one()))
| 0-215026 | ||||||||||||
392 | goto err; never executed: goto err; | 0 | ||||||||||||
393 | BN_set_negative(&point->Z, 0); | - | ||||||||||||
394 | point->Z_is_one = 1; | - | ||||||||||||
395 | ret = 1; | - | ||||||||||||
396 | - | |||||||||||||
397 | err: code before this statement executed 215026 times by 3 tests: err: Executed by:
| 215026 | ||||||||||||
398 | return ret; executed 215026 times by 3 tests: return ret; Executed by:
| 215026 | ||||||||||||
399 | } | - | ||||||||||||
400 | - | |||||||||||||
401 | - | |||||||||||||
402 | /* Gets the affine coordinates of an EC_POINT. | - | ||||||||||||
403 | * Note that the simple implementation only uses affine coordinates. | - | ||||||||||||
404 | */ | - | ||||||||||||
405 | int | - | ||||||||||||
406 | ec_GF2m_simple_point_get_affine_coordinates(const EC_GROUP *group, | - | ||||||||||||
407 | const EC_POINT *point, BIGNUM *x, BIGNUM *y, BN_CTX *ctx) | - | ||||||||||||
408 | { | - | ||||||||||||
409 | int ret = 0; | - | ||||||||||||
410 | - | |||||||||||||
411 | if (EC_POINT_is_at_infinity(group, point) > 0) {
| 0-251 | ||||||||||||
412 | ECerror(EC_R_POINT_AT_INFINITY); | - | ||||||||||||
413 | return 0; never executed: return 0; | 0 | ||||||||||||
414 | } | - | ||||||||||||
415 | if (BN_cmp(&point->Z, BN_value_one())) {
| 0-251 | ||||||||||||
416 | ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | - | ||||||||||||
417 | return 0; never executed: return 0; | 0 | ||||||||||||
418 | } | - | ||||||||||||
419 | if (x != NULL) {
| 0-251 | ||||||||||||
420 | if (!BN_copy(x, &point->X))
| 0-251 | ||||||||||||
421 | goto err; never executed: goto err; | 0 | ||||||||||||
422 | BN_set_negative(x, 0); | - | ||||||||||||
423 | } executed 251 times by 3 tests: end of block Executed by:
| 251 | ||||||||||||
424 | if (y != NULL) {
| 48-203 | ||||||||||||
425 | if (!BN_copy(y, &point->Y))
| 0-48 | ||||||||||||
426 | goto err; never executed: goto err; | 0 | ||||||||||||
427 | BN_set_negative(y, 0); | - | ||||||||||||
428 | } executed 48 times by 2 tests: end of block Executed by:
| 48 | ||||||||||||
429 | ret = 1; | - | ||||||||||||
430 | - | |||||||||||||
431 | err: code before this statement executed 251 times by 3 tests: err: Executed by:
| 251 | ||||||||||||
432 | return ret; executed 251 times by 3 tests: return ret; Executed by:
| 251 | ||||||||||||
433 | } | - | ||||||||||||
434 | - | |||||||||||||
435 | /* Computes a + b and stores the result in r. r could be a or b, a could be b. | - | ||||||||||||
436 | * Uses algorithm A.10.2 of IEEE P1363. | - | ||||||||||||
437 | */ | - | ||||||||||||
438 | int | - | ||||||||||||
439 | ec_GF2m_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, | - | ||||||||||||
440 | const EC_POINT *b, BN_CTX *ctx) | - | ||||||||||||
441 | { | - | ||||||||||||
442 | BN_CTX *new_ctx = NULL; | - | ||||||||||||
443 | BIGNUM *x0, *y0, *x1, *y1, *x2, *y2, *s, *t; | - | ||||||||||||
444 | int ret = 0; | - | ||||||||||||
445 | - | |||||||||||||
446 | if (EC_POINT_is_at_infinity(group, a) > 0) {
| 19976-214976 | ||||||||||||
447 | if (!EC_POINT_copy(r, b))
| 0-19976 | ||||||||||||
448 | return 0; never executed: return 0; | 0 | ||||||||||||
449 | return 1; executed 19976 times by 1 test: return 1; Executed by:
| 19976 | ||||||||||||
450 | } | - | ||||||||||||
451 | if (EC_POINT_is_at_infinity(group, b) > 0) {
| 0-214976 | ||||||||||||
452 | if (!EC_POINT_copy(r, a))
| 0 | ||||||||||||
453 | return 0; never executed: return 0; | 0 | ||||||||||||
454 | return 1; never executed: return 1; | 0 | ||||||||||||
455 | } | - | ||||||||||||
456 | if (ctx == NULL) {
| 0-214976 | ||||||||||||
457 | ctx = new_ctx = BN_CTX_new(); | - | ||||||||||||
458 | if (ctx == NULL)
| 0 | ||||||||||||
459 | return 0; never executed: return 0; | 0 | ||||||||||||
460 | } never executed: end of block | 0 | ||||||||||||
461 | BN_CTX_start(ctx); | - | ||||||||||||
462 | if ((x0 = BN_CTX_get(ctx)) == NULL)
| 0-214976 | ||||||||||||
463 | goto err; never executed: goto err; | 0 | ||||||||||||
464 | if ((y0 = BN_CTX_get(ctx)) == NULL)
| 0-214976 | ||||||||||||
465 | goto err; never executed: goto err; | 0 | ||||||||||||
466 | if ((x1 = BN_CTX_get(ctx)) == NULL)
| 0-214976 | ||||||||||||
467 | goto err; never executed: goto err; | 0 | ||||||||||||
468 | if ((y1 = BN_CTX_get(ctx)) == NULL)
| 0-214976 | ||||||||||||
469 | goto err; never executed: goto err; | 0 | ||||||||||||
470 | if ((x2 = BN_CTX_get(ctx)) == NULL)
| 0-214976 | ||||||||||||
471 | goto err; never executed: goto err; | 0 | ||||||||||||
472 | if ((y2 = BN_CTX_get(ctx)) == NULL)
| 0-214976 | ||||||||||||
473 | goto err; never executed: goto err; | 0 | ||||||||||||
474 | if ((s = BN_CTX_get(ctx)) == NULL)
| 0-214976 | ||||||||||||
475 | goto err; never executed: goto err; | 0 | ||||||||||||
476 | if ((t = BN_CTX_get(ctx)) == NULL)
| 0-214976 | ||||||||||||
477 | goto err; never executed: goto err; | 0 | ||||||||||||
478 | - | |||||||||||||
479 | if (a->Z_is_one) {
| 0-214976 | ||||||||||||
480 | if (!BN_copy(x0, &a->X))
| 0-214976 | ||||||||||||
481 | goto err; never executed: goto err; | 0 | ||||||||||||
482 | if (!BN_copy(y0, &a->Y))
| 0-214976 | ||||||||||||
483 | goto err; never executed: goto err; | 0 | ||||||||||||
484 | } else { executed 214976 times by 3 tests: end of block Executed by:
| 214976 | ||||||||||||
485 | if (!EC_POINT_get_affine_coordinates_GF2m(group, a, x0, y0, ctx))
| 0 | ||||||||||||
486 | goto err; never executed: goto err; | 0 | ||||||||||||
487 | } never executed: end of block | 0 | ||||||||||||
488 | if (b->Z_is_one) {
| 0-214976 | ||||||||||||
489 | if (!BN_copy(x1, &b->X))
| 0-214976 | ||||||||||||
490 | goto err; never executed: goto err; | 0 | ||||||||||||
491 | if (!BN_copy(y1, &b->Y))
| 0-214976 | ||||||||||||
492 | goto err; never executed: goto err; | 0 | ||||||||||||
493 | } else { executed 214976 times by 3 tests: end of block Executed by:
| 214976 | ||||||||||||
494 | if (!EC_POINT_get_affine_coordinates_GF2m(group, b, x1, y1, ctx))
| 0 | ||||||||||||
495 | goto err; never executed: goto err; | 0 | ||||||||||||
496 | } never executed: end of block | 0 | ||||||||||||
497 | - | |||||||||||||
498 | - | |||||||||||||
499 | if (BN_GF2m_cmp(x0, x1)) {
| 94219-120757 | ||||||||||||
500 | if (!BN_GF2m_add(t, x0, x1))
| 0-94219 | ||||||||||||
501 | goto err; never executed: goto err; | 0 | ||||||||||||
502 | if (!BN_GF2m_add(s, y0, y1))
| 0-94219 | ||||||||||||
503 | goto err; never executed: goto err; | 0 | ||||||||||||
504 | if (!group->meth->field_div(group, s, s, t, ctx))
| 0-94219 | ||||||||||||
505 | goto err; never executed: goto err; | 0 | ||||||||||||
506 | if (!group->meth->field_sqr(group, x2, s, ctx))
| 0-94219 | ||||||||||||
507 | goto err; never executed: goto err; | 0 | ||||||||||||
508 | if (!BN_GF2m_add(x2, x2, &group->a))
| 0-94219 | ||||||||||||
509 | goto err; never executed: goto err; | 0 | ||||||||||||
510 | if (!BN_GF2m_add(x2, x2, s))
| 0-94219 | ||||||||||||
511 | goto err; never executed: goto err; | 0 | ||||||||||||
512 | if (!BN_GF2m_add(x2, x2, t))
| 0-94219 | ||||||||||||
513 | goto err; never executed: goto err; | 0 | ||||||||||||
514 | } else { executed 94219 times by 3 tests: end of block Executed by:
| 94219 | ||||||||||||
515 | if (BN_GF2m_cmp(y0, y1) || BN_is_zero(x1)) {
| 2-120660 | ||||||||||||
516 | if (!EC_POINT_set_to_infinity(group, r))
| 0-99 | ||||||||||||
517 | goto err; never executed: goto err; | 0 | ||||||||||||
518 | ret = 1; | - | ||||||||||||
519 | goto err; executed 99 times by 2 tests: goto err; Executed by:
| 99 | ||||||||||||
520 | } | - | ||||||||||||
521 | if (!group->meth->field_div(group, s, y1, x1, ctx))
| 0-120658 | ||||||||||||
522 | goto err; never executed: goto err; | 0 | ||||||||||||
523 | if (!BN_GF2m_add(s, s, x1))
| 0-120658 | ||||||||||||
524 | goto err; never executed: goto err; | 0 | ||||||||||||
525 | - | |||||||||||||
526 | if (!group->meth->field_sqr(group, x2, s, ctx))
| 0-120658 | ||||||||||||
527 | goto err; never executed: goto err; | 0 | ||||||||||||
528 | if (!BN_GF2m_add(x2, x2, s))
| 0-120658 | ||||||||||||
529 | goto err; never executed: goto err; | 0 | ||||||||||||
530 | if (!BN_GF2m_add(x2, x2, &group->a))
| 0-120658 | ||||||||||||
531 | goto err; never executed: goto err; | 0 | ||||||||||||
532 | } executed 120658 times by 3 tests: end of block Executed by:
| 120658 | ||||||||||||
533 | - | |||||||||||||
534 | if (!BN_GF2m_add(y2, x1, x2))
| 0-214877 | ||||||||||||
535 | goto err; never executed: goto err; | 0 | ||||||||||||
536 | if (!group->meth->field_mul(group, y2, y2, s, ctx))
| 0-214877 | ||||||||||||
537 | goto err; never executed: goto err; | 0 | ||||||||||||
538 | if (!BN_GF2m_add(y2, y2, x2))
| 0-214877 | ||||||||||||
539 | goto err; never executed: goto err; | 0 | ||||||||||||
540 | if (!BN_GF2m_add(y2, y2, y1))
| 0-214877 | ||||||||||||
541 | goto err; never executed: goto err; | 0 | ||||||||||||
542 | - | |||||||||||||
543 | if (!EC_POINT_set_affine_coordinates_GF2m(group, r, x2, y2, ctx))
| 0-214877 | ||||||||||||
544 | goto err; never executed: goto err; | 0 | ||||||||||||
545 | - | |||||||||||||
546 | ret = 1; | - | ||||||||||||
547 | - | |||||||||||||
548 | err: code before this statement executed 214877 times by 3 tests: err: Executed by:
| 214877 | ||||||||||||
549 | BN_CTX_end(ctx); | - | ||||||||||||
550 | BN_CTX_free(new_ctx); | - | ||||||||||||
551 | return ret; executed 214976 times by 3 tests: return ret; Executed by:
| 214976 | ||||||||||||
552 | } | - | ||||||||||||
553 | - | |||||||||||||
554 | - | |||||||||||||
555 | /* Computes 2 * a and stores the result in r. r could be a. | - | ||||||||||||
556 | * Uses algorithm A.10.2 of IEEE P1363. | - | ||||||||||||
557 | */ | - | ||||||||||||
558 | int | - | ||||||||||||
559 | ec_GF2m_simple_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, | - | ||||||||||||
560 | BN_CTX *ctx) | - | ||||||||||||
561 | { | - | ||||||||||||
562 | return ec_GF2m_simple_add(group, r, a, a, ctx); executed 130661 times by 3 tests: return ec_GF2m_simple_add(group, r, a, a, ctx); Executed by:
| 130661 | ||||||||||||
563 | } | - | ||||||||||||
564 | - | |||||||||||||
565 | int | - | ||||||||||||
566 | ec_GF2m_simple_invert(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx) | - | ||||||||||||
567 | { | - | ||||||||||||
568 | if (EC_POINT_is_at_infinity(group, point) > 0 || BN_is_zero(&point->Y))
| 0-8044 | ||||||||||||
569 | /* point is its own inverse */ | - | ||||||||||||
570 | return 1; never executed: return 1; | 0 | ||||||||||||
571 | - | |||||||||||||
572 | if (!EC_POINT_make_affine(group, point, ctx))
| 0-8044 | ||||||||||||
573 | return 0; never executed: return 0; | 0 | ||||||||||||
574 | return BN_GF2m_add(&point->Y, &point->X, &point->Y); executed 8044 times by 2 tests: return BN_GF2m_add(&point->Y, &point->X, &point->Y); Executed by:
| 8044 | ||||||||||||
575 | } | - | ||||||||||||
576 | - | |||||||||||||
577 | - | |||||||||||||
578 | /* Indicates whether the given point is the point at infinity. */ | - | ||||||||||||
579 | int | - | ||||||||||||
580 | ec_GF2m_simple_is_at_infinity(const EC_GROUP *group, const EC_POINT *point) | - | ||||||||||||
581 | { | - | ||||||||||||
582 | return BN_is_zero(&point->Z); executed 458616 times by 3 tests: return ((&point->Z)->top == 0); Executed by:
| 458616 | ||||||||||||
583 | } | - | ||||||||||||
584 | - | |||||||||||||
585 | - | |||||||||||||
586 | /* Determines whether the given EC_POINT is an actual point on the curve defined | - | ||||||||||||
587 | * in the EC_GROUP. A point is valid if it satisfies the Weierstrass equation: | - | ||||||||||||
588 | * y^2 + x*y = x^3 + a*x^2 + b. | - | ||||||||||||
589 | */ | - | ||||||||||||
590 | int | - | ||||||||||||
591 | ec_GF2m_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX *ctx) | - | ||||||||||||
592 | { | - | ||||||||||||
593 | int ret = -1; | - | ||||||||||||
594 | BN_CTX *new_ctx = NULL; | - | ||||||||||||
595 | BIGNUM *lh, *y2; | - | ||||||||||||
596 | int (*field_mul) (const EC_GROUP *, BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *); | - | ||||||||||||
597 | int (*field_sqr) (const EC_GROUP *, BIGNUM *, const BIGNUM *, BN_CTX *); | - | ||||||||||||
598 | - | |||||||||||||
599 | if (EC_POINT_is_at_infinity(group, point) > 0)
| 0-109 | ||||||||||||
600 | return 1; never executed: return 1; | 0 | ||||||||||||
601 | - | |||||||||||||
602 | field_mul = group->meth->field_mul; | - | ||||||||||||
603 | field_sqr = group->meth->field_sqr; | - | ||||||||||||
604 | - | |||||||||||||
605 | /* only support affine coordinates */ | - | ||||||||||||
606 | if (!point->Z_is_one)
| 0-109 | ||||||||||||
607 | return -1; never executed: return -1; | 0 | ||||||||||||
608 | - | |||||||||||||
609 | if (ctx == NULL) {
| 0-109 | ||||||||||||
610 | ctx = new_ctx = BN_CTX_new(); | - | ||||||||||||
611 | if (ctx == NULL)
| 0 | ||||||||||||
612 | return -1; never executed: return -1; | 0 | ||||||||||||
613 | } never executed: end of block | 0 | ||||||||||||
614 | BN_CTX_start(ctx); | - | ||||||||||||
615 | if ((y2 = BN_CTX_get(ctx)) == NULL)
| 0-109 | ||||||||||||
616 | goto err; never executed: goto err; | 0 | ||||||||||||
617 | if ((lh = BN_CTX_get(ctx)) == NULL)
| 0-109 | ||||||||||||
618 | goto err; never executed: goto err; | 0 | ||||||||||||
619 | - | |||||||||||||
620 | /* | - | ||||||||||||
621 | * We have a curve defined by a Weierstrass equation y^2 + x*y = x^3 | - | ||||||||||||
622 | * + a*x^2 + b. <=> x^3 + a*x^2 + x*y + b + y^2 = 0 <=> ((x + a) * x | - | ||||||||||||
623 | * + y ) * x + b + y^2 = 0 | - | ||||||||||||
624 | */ | - | ||||||||||||
625 | if (!BN_GF2m_add(lh, &point->X, &group->a))
| 0-109 | ||||||||||||
626 | goto err; never executed: goto err; | 0 | ||||||||||||
627 | if (!field_mul(group, lh, lh, &point->X, ctx))
| 0-109 | ||||||||||||
628 | goto err; never executed: goto err; | 0 | ||||||||||||
629 | if (!BN_GF2m_add(lh, lh, &point->Y))
| 0-109 | ||||||||||||
630 | goto err; never executed: goto err; | 0 | ||||||||||||
631 | if (!field_mul(group, lh, lh, &point->X, ctx))
| 0-109 | ||||||||||||
632 | goto err; never executed: goto err; | 0 | ||||||||||||
633 | if (!BN_GF2m_add(lh, lh, &group->b))
| 0-109 | ||||||||||||
634 | goto err; never executed: goto err; | 0 | ||||||||||||
635 | if (!field_sqr(group, y2, &point->Y, ctx))
| 0-109 | ||||||||||||
636 | goto err; never executed: goto err; | 0 | ||||||||||||
637 | if (!BN_GF2m_add(lh, lh, y2))
| 0-109 | ||||||||||||
638 | goto err; never executed: goto err; | 0 | ||||||||||||
639 | ret = BN_is_zero(lh); | - | ||||||||||||
640 | err: code before this statement executed 109 times by 3 tests: err: Executed by:
| 109 | ||||||||||||
641 | if (ctx)
| 0-109 | ||||||||||||
642 | BN_CTX_end(ctx); executed 109 times by 3 tests: BN_CTX_end(ctx); Executed by:
| 109 | ||||||||||||
643 | BN_CTX_free(new_ctx); | - | ||||||||||||
644 | return ret; executed 109 times by 3 tests: return ret; Executed by:
| 109 | ||||||||||||
645 | } | - | ||||||||||||
646 | - | |||||||||||||
647 | - | |||||||||||||
648 | /* Indicates whether two points are equal. | - | ||||||||||||
649 | * Return values: | - | ||||||||||||
650 | * -1 error | - | ||||||||||||
651 | * 0 equal (in affine coordinates) | - | ||||||||||||
652 | * 1 not equal | - | ||||||||||||
653 | */ | - | ||||||||||||
654 | int | - | ||||||||||||
655 | ec_GF2m_simple_cmp(const EC_GROUP *group, const EC_POINT *a, | - | ||||||||||||
656 | const EC_POINT *b, BN_CTX *ctx) | - | ||||||||||||
657 | { | - | ||||||||||||
658 | BIGNUM *aX, *aY, *bX, *bY; | - | ||||||||||||
659 | BN_CTX *new_ctx = NULL; | - | ||||||||||||
660 | int ret = -1; | - | ||||||||||||
661 | - | |||||||||||||
662 | if (EC_POINT_is_at_infinity(group, a) > 0) {
| 30-36 | ||||||||||||
663 | return EC_POINT_is_at_infinity(group, b) > 0 ? 0 : 1; executed 30 times by 1 test: return EC_POINT_is_at_infinity(group, b) > 0 ? 0 : 1; Executed by:
| 0-30 | ||||||||||||
664 | } | - | ||||||||||||
665 | if (EC_POINT_is_at_infinity(group, b) > 0)
| 0-36 | ||||||||||||
666 | return 1; never executed: return 1; | 0 | ||||||||||||
667 | - | |||||||||||||
668 | if (a->Z_is_one && b->Z_is_one) {
| 0-36 | ||||||||||||
669 | return ((BN_cmp(&a->X, &b->X) == 0) && BN_cmp(&a->Y, &b->Y) == 0) ? 0 : 1; executed 36 times by 2 tests: return ((BN_cmp(&a->X, &b->X) == 0) && BN_cmp(&a->Y, &b->Y) == 0) ? 0 : 1; Executed by:
| 0-36 | ||||||||||||
670 | } | - | ||||||||||||
671 | if (ctx == NULL) {
| 0 | ||||||||||||
672 | ctx = new_ctx = BN_CTX_new(); | - | ||||||||||||
673 | if (ctx == NULL)
| 0 | ||||||||||||
674 | return -1; never executed: return -1; | 0 | ||||||||||||
675 | } never executed: end of block | 0 | ||||||||||||
676 | BN_CTX_start(ctx); | - | ||||||||||||
677 | if ((aX = BN_CTX_get(ctx)) == NULL)
| 0 | ||||||||||||
678 | goto err; never executed: goto err; | 0 | ||||||||||||
679 | if ((aY = BN_CTX_get(ctx)) == NULL)
| 0 | ||||||||||||
680 | goto err; never executed: goto err; | 0 | ||||||||||||
681 | if ((bX = BN_CTX_get(ctx)) == NULL)
| 0 | ||||||||||||
682 | goto err; never executed: goto err; | 0 | ||||||||||||
683 | if ((bY = BN_CTX_get(ctx)) == NULL)
| 0 | ||||||||||||
684 | goto err; never executed: goto err; | 0 | ||||||||||||
685 | - | |||||||||||||
686 | if (!EC_POINT_get_affine_coordinates_GF2m(group, a, aX, aY, ctx))
| 0 | ||||||||||||
687 | goto err; never executed: goto err; | 0 | ||||||||||||
688 | if (!EC_POINT_get_affine_coordinates_GF2m(group, b, bX, bY, ctx))
| 0 | ||||||||||||
689 | goto err; never executed: goto err; | 0 | ||||||||||||
690 | ret = ((BN_cmp(aX, bX) == 0) && BN_cmp(aY, bY) == 0) ? 0 : 1;
| 0 | ||||||||||||
691 | - | |||||||||||||
692 | err: code before this statement never executed: err: | 0 | ||||||||||||
693 | if (ctx)
| 0 | ||||||||||||
694 | BN_CTX_end(ctx); never executed: BN_CTX_end(ctx); | 0 | ||||||||||||
695 | BN_CTX_free(new_ctx); | - | ||||||||||||
696 | return ret; never executed: return ret; | 0 | ||||||||||||
697 | } | - | ||||||||||||
698 | - | |||||||||||||
699 | - | |||||||||||||
700 | /* Forces the given EC_POINT to internally use affine coordinates. */ | - | ||||||||||||
701 | int | - | ||||||||||||
702 | ec_GF2m_simple_make_affine(const EC_GROUP * group, EC_POINT * point, BN_CTX * ctx) | - | ||||||||||||
703 | { | - | ||||||||||||
704 | BN_CTX *new_ctx = NULL; | - | ||||||||||||
705 | BIGNUM *x, *y; | - | ||||||||||||
706 | int ret = 0; | - | ||||||||||||
707 | - | |||||||||||||
708 | if (point->Z_is_one || EC_POINT_is_at_infinity(group, point) > 0)
| 0-13036 | ||||||||||||
709 | return 1; executed 13036 times by 2 tests: return 1; Executed by:
| 13036 | ||||||||||||
710 | - | |||||||||||||
711 | if (ctx == NULL) {
| 0 | ||||||||||||
712 | ctx = new_ctx = BN_CTX_new(); | - | ||||||||||||
713 | if (ctx == NULL)
| 0 | ||||||||||||
714 | return 0; never executed: return 0; | 0 | ||||||||||||
715 | } never executed: end of block | 0 | ||||||||||||
716 | BN_CTX_start(ctx); | - | ||||||||||||
717 | if ((x = BN_CTX_get(ctx)) == NULL)
| 0 | ||||||||||||
718 | goto err; never executed: goto err; | 0 | ||||||||||||
719 | if ((y = BN_CTX_get(ctx)) == NULL)
| 0 | ||||||||||||
720 | goto err; never executed: goto err; | 0 | ||||||||||||
721 | - | |||||||||||||
722 | if (!EC_POINT_get_affine_coordinates_GF2m(group, point, x, y, ctx))
| 0 | ||||||||||||
723 | goto err; never executed: goto err; | 0 | ||||||||||||
724 | if (!BN_copy(&point->X, x))
| 0 | ||||||||||||
725 | goto err; never executed: goto err; | 0 | ||||||||||||
726 | if (!BN_copy(&point->Y, y))
| 0 | ||||||||||||
727 | goto err; never executed: goto err; | 0 | ||||||||||||
728 | if (!BN_one(&point->Z))
| 0 | ||||||||||||
729 | goto err; never executed: goto err; | 0 | ||||||||||||
730 | - | |||||||||||||
731 | ret = 1; | - | ||||||||||||
732 | - | |||||||||||||
733 | err: code before this statement never executed: err: | 0 | ||||||||||||
734 | if (ctx)
| 0 | ||||||||||||
735 | BN_CTX_end(ctx); never executed: BN_CTX_end(ctx); | 0 | ||||||||||||
736 | BN_CTX_free(new_ctx); | - | ||||||||||||
737 | return ret; never executed: return ret; | 0 | ||||||||||||
738 | } | - | ||||||||||||
739 | - | |||||||||||||
740 | - | |||||||||||||
741 | /* Forces each of the EC_POINTs in the given array to use affine coordinates. */ | - | ||||||||||||
742 | int | - | ||||||||||||
743 | ec_GF2m_simple_points_make_affine(const EC_GROUP *group, size_t num, | - | ||||||||||||
744 | EC_POINT *points[], BN_CTX *ctx) | - | ||||||||||||
745 | { | - | ||||||||||||
746 | size_t i; | - | ||||||||||||
747 | - | |||||||||||||
748 | for (i = 0; i < num; i++) {
| 179-4992 | ||||||||||||
749 | if (!group->meth->make_affine(group, points[i], ctx))
| 0-4992 | ||||||||||||
750 | return 0; never executed: return 0; | 0 | ||||||||||||
751 | } executed 4992 times by 2 tests: end of block Executed by:
| 4992 | ||||||||||||
752 | - | |||||||||||||
753 | return 1; executed 179 times by 2 tests: return 1; Executed by:
| 179 | ||||||||||||
754 | } | - | ||||||||||||
755 | - | |||||||||||||
756 | - | |||||||||||||
757 | /* Wrapper to simple binary polynomial field multiplication implementation. */ | - | ||||||||||||
758 | int | - | ||||||||||||
759 | ec_GF2m_simple_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, | - | ||||||||||||
760 | const BIGNUM *b, BN_CTX *ctx) | - | ||||||||||||
761 | { | - | ||||||||||||
762 | return BN_GF2m_mod_mul_arr(r, a, b, group->poly, ctx); executed 215095 times by 3 tests: return BN_GF2m_mod_mul_arr(r, a, b, group->poly, ctx); Executed by:
| 215095 | ||||||||||||
763 | } | - | ||||||||||||
764 | - | |||||||||||||
765 | - | |||||||||||||
766 | /* Wrapper to simple binary polynomial field squaring implementation. */ | - | ||||||||||||
767 | int | - | ||||||||||||
768 | ec_GF2m_simple_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, | - | ||||||||||||
769 | BN_CTX *ctx) | - | ||||||||||||
770 | { | - | ||||||||||||
771 | return BN_GF2m_mod_sqr_arr(r, a, group->poly, ctx); executed 214986 times by 3 tests: return BN_GF2m_mod_sqr_arr(r, a, group->poly, ctx); Executed by:
| 214986 | ||||||||||||
772 | } | - | ||||||||||||
773 | - | |||||||||||||
774 | - | |||||||||||||
775 | /* Wrapper to simple binary polynomial field division implementation. */ | - | ||||||||||||
776 | int | - | ||||||||||||
777 | ec_GF2m_simple_field_div(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, | - | ||||||||||||
778 | const BIGNUM *b, BN_CTX *ctx) | - | ||||||||||||
779 | { | - | ||||||||||||
780 | return BN_GF2m_mod_div(r, a, b, &group->field, ctx); executed 214877 times by 3 tests: return BN_GF2m_mod_div(r, a, b, &group->field, ctx); Executed by:
| 214877 | ||||||||||||
781 | } | - | ||||||||||||
782 | - | |||||||||||||
783 | #endif | - | ||||||||||||
Source code | Switch to Preprocessed file |