]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/ec/ec_lib.c
fix #include position
[thirdparty/openssl.git] / crypto / ec / ec_lib.c
CommitLineData
65e81670
BM
1/* crypto/ec/ec_lib.c */
2/* ====================================================================
4d94ae00 3 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
65e81670
BM
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
c4b36ff4
BM
56#include <string.h>
57
0657bf9c 58#include <openssl/err.h>
bb62a8b0 59#include <openssl/opensslv.h>
0657bf9c 60
65e81670 61#include "ec_lcl.h"
0657bf9c 62
bb62a8b0
BM
63static const char EC_version[] = "EC" OPENSSL_VERSION_PTEXT;
64
0657bf9c
BM
65
66/* functions for EC_GROUP objects */
67
68EC_GROUP *EC_GROUP_new(const EC_METHOD *meth)
69 {
70 EC_GROUP *ret;
71
72 if (meth == NULL)
73 {
74 ECerr(EC_F_EC_GROUP_NEW, ERR_R_PASSED_NULL_PARAMETER);
75 return NULL;
76 }
77 if (meth->group_init == 0)
78 {
79 ECerr(EC_F_EC_GROUP_NEW, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
80 return NULL;
81 }
82
83 ret = OPENSSL_malloc(sizeof *ret);
84 if (ret == NULL)
85 {
86 ECerr(EC_F_EC_GROUP_NEW, ERR_R_MALLOC_FAILURE);
87 return NULL;
88 }
89
90 ret->meth = meth;
df9cc153
BM
91
92 ret->extra_data = NULL;
93 ret->extra_data_dup_func = 0;
94 ret->extra_data_free_func = 0;
95 ret->extra_data_clear_free_func = 0;
945e15a2
BM
96
97 ret->nid = 0;
98
0657bf9c
BM
99 if (!meth->group_init(ret))
100 {
101 OPENSSL_free(ret);
102 return NULL;
103 }
104
105 return ret;
106 }
107
108
0657bf9c
BM
109void EC_GROUP_free(EC_GROUP *group)
110 {
111 if (group->meth->group_finish != 0)
112 group->meth->group_finish(group);
df9cc153
BM
113
114 EC_GROUP_free_extra_data(group);
115
0657bf9c
BM
116 OPENSSL_free(group);
117 }
118
119
120void EC_GROUP_clear_free(EC_GROUP *group)
121 {
122 if (group->meth->group_clear_finish != 0)
123 group->meth->group_clear_finish(group);
124 else if (group->meth != NULL && group->meth->group_finish != 0)
125 group->meth->group_finish(group);
df9cc153
BM
126
127 EC_GROUP_clear_free_extra_data(group);
128
c4b36ff4 129 memset(group, 0, sizeof *group);
0657bf9c
BM
130 OPENSSL_free(group);
131 }
132
133
134int EC_GROUP_copy(EC_GROUP *dest, const EC_GROUP *src)
135 {
136 if (dest->meth->group_copy == 0)
137 {
138 ECerr(EC_F_EC_GROUP_COPY, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
139 return 0;
140 }
141 if (dest->meth != src->meth)
142 {
143 ECerr(EC_F_EC_GROUP_COPY, EC_R_INCOMPATIBLE_OBJECTS);
144 return 0;
145 }
1d5bd6cf
BM
146 if (dest == src)
147 return 1;
0657bf9c 148
df9cc153
BM
149 EC_GROUP_clear_free_extra_data(dest);
150 if (src->extra_data_dup_func)
151 {
152 if (src->extra_data != NULL)
153 {
154 dest->extra_data = src->extra_data_dup_func(src->extra_data);
155 if (dest->extra_data == NULL)
156 return 0;
157 }
158
159 dest->extra_data_dup_func = src->extra_data_dup_func;
160 dest->extra_data_free_func = src->extra_data_free_func;
161 dest->extra_data_clear_free_func = src->extra_data_clear_free_func;
162 }
163
0657bf9c
BM
164 return dest->meth->group_copy(dest, src);
165 }
166
167
48fe4d62
BM
168const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *group)
169 {
170 return group->meth;
171 }
172
173
bb62a8b0
BM
174int EC_GROUP_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
175 {
176 if (group->meth->group_set_curve_GFp == 0)
177 {
178 ECerr(EC_F_EC_GROUP_SET_CURVE_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
179 return 0;
180 }
181 return group->meth->group_set_curve_GFp(group, p, a, b, ctx);
182 }
183
184
48fe4d62 185int EC_GROUP_get_curve_GFp(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)
bb62a8b0
BM
186 {
187 if (group->meth->group_get_curve_GFp == 0)
188 {
189 ECerr(EC_F_EC_GROUP_GET_CURVE_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
190 return 0;
191 }
192 return group->meth->group_get_curve_GFp(group, p, a, b, ctx);
193 }
194
195
0657bf9c
BM
196int EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator, const BIGNUM *order, const BIGNUM *cofactor)
197 {
198 if (group->meth->group_set_generator == 0)
199 {
200 ECerr(EC_F_EC_GROUP_SET_GENERATOR, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
201 return 0;
202 }
203 return group->meth->group_set_generator(group, generator, order, cofactor);
204 }
205
206
48fe4d62
BM
207EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *group)
208 {
209 if (group->meth->group_get0_generator == 0)
210 {
211 ECerr(EC_F_EC_GROUP_GET0_GENERATOR, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
212 return 0;
213 }
214 return group->meth->group_get0_generator(group);
215 }
216
217
218int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx)
219 {
220 if (group->meth->group_get_order == 0)
221 {
222 ECerr(EC_F_EC_GROUP_GET_ORDER, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
223 return 0;
224 }
225 return group->meth->group_get_order(group, order, ctx);
226 }
227
228
229int EC_GROUP_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor, BN_CTX *ctx)
230 {
231 if (group->meth->group_get_cofactor == 0)
232 {
233 ECerr(EC_F_EC_GROUP_GET_COFACTOR, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
234 return 0;
235 }
236 return group->meth->group_get_cofactor(group, cofactor, ctx);
237 }
238
239
df9cc153
BM
240/* this has 'package' visibility */
241int EC_GROUP_set_extra_data(EC_GROUP *group, void *extra_data, void *(*extra_data_dup_func)(void *),
242 void (*extra_data_free_func)(void *), void (*extra_data_clear_free_func)(void *))
243 {
244 if ((group->extra_data != NULL)
245 || (group->extra_data_dup_func != 0)
246 || (group->extra_data_free_func != 0)
247 || (group->extra_data_clear_free_func != 0))
248 {
249 ECerr(EC_F_EC_GROUP_SET_EXTRA_DATA, EC_R_SLOT_FULL);
250 return 0;
251 }
252
253 group->extra_data = extra_data;
254 group->extra_data_dup_func = extra_data_dup_func;
255 group->extra_data_free_func = extra_data_free_func;
256 group->extra_data_clear_free_func = extra_data_clear_free_func;
257 return 1;
258 }
259
260
261/* this has 'package' visibility */
48fe4d62 262void *EC_GROUP_get_extra_data(const EC_GROUP *group, void *(*extra_data_dup_func)(void *),
df9cc153
BM
263 void (*extra_data_free_func)(void *), void (*extra_data_clear_free_func)(void *))
264 {
265 if ((group->extra_data_dup_func != extra_data_dup_func)
266 || (group->extra_data_free_func != extra_data_free_func)
267 || (group->extra_data_clear_free_func != extra_data_clear_free_func))
268 {
269 ECerr(EC_F_EC_GROUP_GET_EXTRA_DATA, EC_R_NO_SUCH_EXTRA_DATA);
270 return NULL;
271 }
272
273 return group->extra_data;
274 }
275
276
277/* this has 'package' visibility */
278void EC_GROUP_free_extra_data(EC_GROUP *group)
279 {
280 if (group->extra_data_free_func)
281 group->extra_data_free_func(group->extra_data);
282 group->extra_data = NULL;
283 group->extra_data_dup_func = 0;
284 group->extra_data_free_func = 0;
285 group->extra_data_clear_free_func = 0;
286 }
287
288
289/* this has 'package' visibility */
290void EC_GROUP_clear_free_extra_data(EC_GROUP *group)
291 {
292 if (group->extra_data_clear_free_func)
293 group->extra_data_clear_free_func(group->extra_data);
294 else if (group->extra_data_free_func)
295 group->extra_data_free_func(group->extra_data);
296 group->extra_data = NULL;
297 group->extra_data_dup_func = 0;
298 group->extra_data_free_func = 0;
299 group->extra_data_clear_free_func = 0;
300 }
301
945e15a2 302void EC_GROUP_set_nid(EC_GROUP *group, int nid)
45fb7379 303 {
945e15a2 304 group->nid = nid;
45fb7379 305 }
945e15a2
BM
306
307int EC_GROUP_get_nid(const EC_GROUP *group)
45fb7379 308 {
945e15a2 309 return group->nid;
45fb7379 310 }
945e15a2 311
df9cc153 312
0657bf9c
BM
313
314/* functions for EC_POINT objects */
315
316EC_POINT *EC_POINT_new(const EC_GROUP *group)
317 {
318 EC_POINT *ret;
319
320 if (group == NULL)
321 {
322 ECerr(EC_F_EC_POINT_NEW, ERR_R_PASSED_NULL_PARAMETER);
323 return NULL;
324 }
325 if (group->meth->point_init == 0)
326 {
327 ECerr(EC_F_EC_POINT_NEW, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
328 return NULL;
329 }
330
331 ret = OPENSSL_malloc(sizeof *ret);
332 if (ret == NULL)
333 {
334 ECerr(EC_F_EC_POINT_NEW, ERR_R_MALLOC_FAILURE);
335 return NULL;
336 }
337
338 ret->meth = group->meth;
339
340 if (!ret->meth->point_init(ret))
341 {
342 OPENSSL_free(ret);
343 return NULL;
344 }
345
346 return ret;
347 }
348
349
350void EC_POINT_free(EC_POINT *point)
351 {
352 if (point->meth->point_finish != 0)
353 point->meth->point_finish(point);
354 OPENSSL_free(point);
355 }
356
357
358void EC_POINT_clear_free(EC_POINT *point)
359 {
360 if (point->meth->point_clear_finish != 0)
361 point->meth->point_clear_finish(point);
362 else if (point->meth != NULL && point->meth->point_finish != 0)
363 point->meth->point_finish(point);
f418f8c1 364 memset(point, 0, sizeof *point);
0657bf9c
BM
365 OPENSSL_free(point);
366 }
367
368
369int EC_POINT_copy(EC_POINT *dest, const EC_POINT *src)
370 {
371 if (dest->meth->point_copy == 0)
372 {
373 ECerr(EC_F_EC_POINT_COPY, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
374 return 0;
375 }
376 if (dest->meth != src->meth)
377 {
378 ECerr(EC_F_EC_POINT_COPY, EC_R_INCOMPATIBLE_OBJECTS);
379 return 0;
380 }
91f29a38
BM
381 if (dest == src)
382 return 1;
0657bf9c
BM
383 return dest->meth->point_copy(dest, src);
384 }
385
386
48fe4d62
BM
387const EC_METHOD *EC_POINT_method_of(const EC_POINT *point)
388 {
389 return point->meth;
390 }
391
392
226cc7de
BM
393int EC_POINT_set_to_infinity(const EC_GROUP *group, EC_POINT *point)
394 {
395 if (group->meth->point_set_to_infinity == 0)
396 {
397 ECerr(EC_F_EC_POINT_SET_TO_INFINITY, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
398 return 0;
399 }
400 if (group->meth != point->meth)
401 {
402 ECerr(EC_F_EC_POINT_SET_TO_INFINITY, EC_R_INCOMPATIBLE_OBJECTS);
403 return 0;
404 }
405 return group->meth->point_set_to_infinity(group, point);
406 }
407
408
1d5bd6cf
BM
409int EC_POINT_set_Jprojective_coordinates_GFp(const EC_GROUP *group, EC_POINT *point,
410 const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *ctx)
411 {
412 if (group->meth->point_set_Jprojective_coordinates_GFp == 0)
413 {
414 ECerr(EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
415 return 0;
416 }
417 if (group->meth != point->meth)
418 {
419 ECerr(EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GFP, EC_R_INCOMPATIBLE_OBJECTS);
420 return 0;
421 }
422 return group->meth->point_set_Jprojective_coordinates_GFp(group, point, x, y, z, ctx);
423 }
424
425
426int EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *group, const EC_POINT *point,
427 BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *ctx)
428 {
429 if (group->meth->point_get_Jprojective_coordinates_GFp == 0)
430 {
431 ECerr(EC_F_EC_POINT_GET_JPROJECTIVE_COORDINATES_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
432 return 0;
433 }
434 if (group->meth != point->meth)
435 {
436 ECerr(EC_F_EC_POINT_GET_JPROJECTIVE_COORDINATES_GFP, EC_R_INCOMPATIBLE_OBJECTS);
437 return 0;
438 }
439 return group->meth->point_get_Jprojective_coordinates_GFp(group, point, x, y, z, ctx);
440 }
441
442
226cc7de
BM
443int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *group, EC_POINT *point,
444 const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx)
445 {
446 if (group->meth->point_set_affine_coordinates_GFp == 0)
447 {
448 ECerr(EC_F_EC_POINT_SET_AFFINE_COORDINATES_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
449 return 0;
450 }
451 if (group->meth != point->meth)
452 {
453 ECerr(EC_F_EC_POINT_SET_AFFINE_COORDINATES_GFP, EC_R_INCOMPATIBLE_OBJECTS);
454 return 0;
455 }
456 return group->meth->point_set_affine_coordinates_GFp(group, point, x, y, ctx);
457 }
458
459
460int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group, const EC_POINT *point,
461 BIGNUM *x, BIGNUM *y, BN_CTX *ctx)
462 {
463 if (group->meth->point_get_affine_coordinates_GFp == 0)
464 {
465 ECerr(EC_F_EC_POINT_GET_AFFINE_COORDINATES_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
466 return 0;
467 }
468 if (group->meth != point->meth)
469 {
470 ECerr(EC_F_EC_POINT_GET_AFFINE_COORDINATES_GFP, EC_R_INCOMPATIBLE_OBJECTS);
471 return 0;
472 }
473 return group->meth->point_get_affine_coordinates_GFp(group, point, x, y, ctx);
474 }
475
476
1d5bd6cf
BM
477int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *group, EC_POINT *point,
478 const BIGNUM *x, int y_bit, BN_CTX *ctx)
479 {
480 if (group->meth->point_set_compressed_coordinates_GFp == 0)
481 {
482 ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
483 return 0;
484 }
485 if (group->meth != point->meth)
486 {
487 ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP, EC_R_INCOMPATIBLE_OBJECTS);
488 return 0;
489 }
490 return group->meth->point_set_compressed_coordinates_GFp(group, point, x, y_bit, ctx);
491 }
0657bf9c
BM
492
493
494size_t EC_POINT_point2oct(const EC_GROUP *group, const EC_POINT *point, point_conversion_form_t form,
495 unsigned char *buf, size_t len, BN_CTX *ctx)
496 {
497 if (group->meth->point2oct == 0)
498 {
499 ECerr(EC_F_EC_POINT_POINT2OCT, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
500 return 0;
501 }
502 if (group->meth != point->meth)
503 {
504 ECerr(EC_F_EC_POINT_POINT2OCT, EC_R_INCOMPATIBLE_OBJECTS);
505 return 0;
506 }
507 return group->meth->point2oct(group, point, form, buf, len, ctx);
508 }
509
510
511int EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *point,
512 const unsigned char *buf, size_t len, BN_CTX *ctx)
513 {
514 if (group->meth->oct2point == 0)
515 {
516 ECerr(EC_F_EC_POINT_OCT2POINT, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
517 return 0;
518 }
519 if (group->meth != point->meth)
520 {
521 ECerr(EC_F_EC_POINT_OCT2POINT, EC_R_INCOMPATIBLE_OBJECTS);
522 return 0;
523 }
524 return group->meth->oct2point(group, point, buf, len, ctx);
525 }
526
527
528int EC_POINT_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx)
529 {
530 if (group->meth->add == 0)
531 {
532 ECerr(EC_F_EC_POINT_ADD, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
533 return 0;
534 }
535 if ((group->meth != r->meth) || (r->meth != a->meth) || (a->meth != b->meth))
536 {
537 ECerr(EC_F_EC_POINT_ADD, EC_R_INCOMPATIBLE_OBJECTS);
538 return 0;
539 }
540 return group->meth->add(group, r, a, b, ctx);
541 }
542
543
544int EC_POINT_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, BN_CTX *ctx)
545 {
546 if (group->meth->dbl == 0)
547 {
548 ECerr(EC_F_EC_POINT_DBL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
549 return 0;
550 }
551 if ((group->meth != r->meth) || (r->meth != a->meth))
552 {
553 ECerr(EC_F_EC_POINT_DBL, EC_R_INCOMPATIBLE_OBJECTS);
554 return 0;
555 }
556 return group->meth->dbl(group, r, a, ctx);
557 }
558
559
1d5bd6cf
BM
560int EC_POINT_invert(const EC_GROUP *group, EC_POINT *a, BN_CTX *ctx)
561 {
562 if (group->meth->dbl == 0)
563 {
564 ECerr(EC_F_EC_POINT_DBL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
565 return 0;
566 }
567 if (group->meth != a->meth)
568 {
569 ECerr(EC_F_EC_POINT_DBL, EC_R_INCOMPATIBLE_OBJECTS);
570 return 0;
571 }
572 return group->meth->invert(group, a, ctx);
573 }
574
575
0657bf9c
BM
576int EC_POINT_is_at_infinity(const EC_GROUP *group, const EC_POINT *point)
577 {
578 if (group->meth->is_at_infinity == 0)
579 {
580 ECerr(EC_F_EC_POINT_IS_AT_INFINITY, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
581 return 0;
582 }
583 if (group->meth != point->meth)
584 {
585 ECerr(EC_F_EC_POINT_IS_AT_INFINITY, EC_R_INCOMPATIBLE_OBJECTS);
586 return 0;
587 }
588 return group->meth->is_at_infinity(group, point);
589 }
590
591
592int EC_POINT_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX *ctx)
593 {
594 if (group->meth->is_on_curve == 0)
595 {
596 ECerr(EC_F_EC_POINT_IS_ON_CURVE, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
597 return 0;
598 }
599 if (group->meth != point->meth)
600 {
601 ECerr(EC_F_EC_POINT_IS_ON_CURVE, EC_R_INCOMPATIBLE_OBJECTS);
602 return 0;
603 }
604 return group->meth->is_on_curve(group, point, ctx);
605 }
606
607
1d5bd6cf
BM
608int EC_POINT_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx)
609 {
610 if (group->meth->point_cmp == 0)
611 {
612 ECerr(EC_F_EC_POINT_CMP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
613 return 0;
614 }
615 if ((group->meth != a->meth) || (a->meth != b->meth))
616 {
617 ECerr(EC_F_EC_POINT_CMP, EC_R_INCOMPATIBLE_OBJECTS);
618 return 0;
619 }
620 return group->meth->point_cmp(group, a, b, ctx);
621 }
622
623
e869d4bd 624int EC_POINT_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx)
0657bf9c
BM
625 {
626 if (group->meth->make_affine == 0)
627 {
628 ECerr(EC_F_EC_POINT_MAKE_AFFINE, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
629 return 0;
630 }
631 if (group->meth != point->meth)
632 {
633 ECerr(EC_F_EC_POINT_MAKE_AFFINE, EC_R_INCOMPATIBLE_OBJECTS);
634 return 0;
635 }
636 return group->meth->make_affine(group, point, ctx);
637 }
48fe4d62
BM
638
639
640int EC_POINTs_make_affine(const EC_GROUP *group, size_t num, EC_POINT *points[], BN_CTX *ctx)
641 {
642 size_t i;
643
644 if (group->meth->points_make_affine == 0)
645 {
646 ECerr(EC_F_EC_POINTS_MAKE_AFFINE, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
647 return 0;
648 }
649 for (i = 0; i < num; i++)
650 {
651 if (group->meth != points[i]->meth)
652 {
653 ECerr(EC_F_EC_POINTS_MAKE_AFFINE, EC_R_INCOMPATIBLE_OBJECTS);
654 return 0;
655 }
656 }
657 return group->meth->points_make_affine(group, num, points, ctx);
658 }