• Home
  • Raw
  • Download

Lines Matching refs:group

91 int ec_GFp_simple_group_init(EC_GROUP *group) {  in ec_GFp_simple_group_init()  argument
92 BN_init(&group->field); in ec_GFp_simple_group_init()
93 BN_init(&group->a); in ec_GFp_simple_group_init()
94 BN_init(&group->b); in ec_GFp_simple_group_init()
95 BN_init(&group->one); in ec_GFp_simple_group_init()
96 group->a_is_minus3 = 0; in ec_GFp_simple_group_init()
100 void ec_GFp_simple_group_finish(EC_GROUP *group) { in ec_GFp_simple_group_finish() argument
101 BN_free(&group->field); in ec_GFp_simple_group_finish()
102 BN_free(&group->a); in ec_GFp_simple_group_finish()
103 BN_free(&group->b); in ec_GFp_simple_group_finish()
104 BN_free(&group->one); in ec_GFp_simple_group_finish()
107 int ec_GFp_simple_group_set_curve(EC_GROUP *group, const BIGNUM *p, in ec_GFp_simple_group_set_curve() argument
134 if (!BN_copy(&group->field, p)) { in ec_GFp_simple_group_set_curve()
137 BN_set_negative(&group->field, 0); in ec_GFp_simple_group_set_curve()
143 if (group->meth->field_encode) { in ec_GFp_simple_group_set_curve()
144 if (!group->meth->field_encode(group, &group->a, tmp_a, ctx)) { in ec_GFp_simple_group_set_curve()
147 } else if (!BN_copy(&group->a, tmp_a)) { in ec_GFp_simple_group_set_curve()
152 if (!BN_nnmod(&group->b, b, p, ctx)) { in ec_GFp_simple_group_set_curve()
155 if (group->meth->field_encode && in ec_GFp_simple_group_set_curve()
156 !group->meth->field_encode(group, &group->b, &group->b, ctx)) { in ec_GFp_simple_group_set_curve()
164 group->a_is_minus3 = (0 == BN_cmp(tmp_a, &group->field)); in ec_GFp_simple_group_set_curve()
166 if (group->meth->field_encode != NULL) { in ec_GFp_simple_group_set_curve()
167 if (!group->meth->field_encode(group, &group->one, BN_value_one(), ctx)) { in ec_GFp_simple_group_set_curve()
170 } else if (!BN_copy(&group->one, BN_value_one())) { in ec_GFp_simple_group_set_curve()
182 int ec_GFp_simple_group_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, in ec_GFp_simple_group_get_curve() argument
187 if (p != NULL && !BN_copy(p, &group->field)) { in ec_GFp_simple_group_get_curve()
192 if (group->meth->field_decode) { in ec_GFp_simple_group_get_curve()
199 if (a != NULL && !group->meth->field_decode(group, a, &group->a, ctx)) { in ec_GFp_simple_group_get_curve()
202 if (b != NULL && !group->meth->field_decode(group, b, &group->b, ctx)) { in ec_GFp_simple_group_get_curve()
206 if (a != NULL && !BN_copy(a, &group->a)) { in ec_GFp_simple_group_get_curve()
209 if (b != NULL && !BN_copy(b, &group->b)) { in ec_GFp_simple_group_get_curve()
222 unsigned ec_GFp_simple_group_get_degree(const EC_GROUP *group) { in ec_GFp_simple_group_get_degree() argument
223 return BN_num_bits(&group->field); in ec_GFp_simple_group_get_degree()
250 int ec_GFp_simple_point_set_to_infinity(const EC_GROUP *group, in ec_GFp_simple_point_set_to_infinity() argument
256 static int set_Jprojective_coordinate_GFp(const EC_GROUP *group, BIGNUM *out, in set_Jprojective_coordinate_GFp() argument
262 BN_cmp(in, &group->field) >= 0) { in set_Jprojective_coordinate_GFp()
266 if (group->meth->field_encode) { in set_Jprojective_coordinate_GFp()
267 return group->meth->field_encode(group, out, in, ctx); in set_Jprojective_coordinate_GFp()
272 int ec_GFp_simple_point_set_affine_coordinates(const EC_GROUP *group, in ec_GFp_simple_point_set_affine_coordinates() argument
290 if (!set_Jprojective_coordinate_GFp(group, &point->X, x, ctx) || in ec_GFp_simple_point_set_affine_coordinates()
291 !set_Jprojective_coordinate_GFp(group, &point->Y, y, ctx) || in ec_GFp_simple_point_set_affine_coordinates()
292 !BN_copy(&point->Z, &group->one)) { in ec_GFp_simple_point_set_affine_coordinates()
303 int ec_GFp_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, in ec_GFp_simple_add() argument
314 return EC_POINT_dbl(group, r, a, ctx); in ec_GFp_simple_add()
316 if (EC_POINT_is_at_infinity(group, a)) { in ec_GFp_simple_add()
319 if (EC_POINT_is_at_infinity(group, b)) { in ec_GFp_simple_add()
323 field_mul = group->meth->field_mul; in ec_GFp_simple_add()
324 field_sqr = group->meth->field_sqr; in ec_GFp_simple_add()
325 p = &group->field; in ec_GFp_simple_add()
351 int b_Z_is_one = BN_cmp(&b->Z, &group->one) == 0; in ec_GFp_simple_add()
360 if (!field_sqr(group, n0, &b->Z, ctx) || in ec_GFp_simple_add()
361 !field_mul(group, n1, &a->X, n0, ctx)) { in ec_GFp_simple_add()
366 if (!field_mul(group, n0, n0, &b->Z, ctx) || in ec_GFp_simple_add()
367 !field_mul(group, n2, &a->Y, n0, ctx)) { in ec_GFp_simple_add()
374 int a_Z_is_one = BN_cmp(&a->Z, &group->one) == 0; in ec_GFp_simple_add()
382 if (!field_sqr(group, n0, &a->Z, ctx) || in ec_GFp_simple_add()
383 !field_mul(group, n3, &b->X, n0, ctx)) { in ec_GFp_simple_add()
388 if (!field_mul(group, n0, n0, &a->Z, ctx) || in ec_GFp_simple_add()
389 !field_mul(group, n4, &b->Y, n0, ctx)) { in ec_GFp_simple_add()
407 ret = EC_POINT_dbl(group, r, a, ctx); in ec_GFp_simple_add()
440 } else if (!field_mul(group, n0, &a->Z, &b->Z, ctx)) { in ec_GFp_simple_add()
443 if (!field_mul(group, &r->Z, n0, n5, ctx)) { in ec_GFp_simple_add()
451 if (!field_sqr(group, n0, n6, ctx) || in ec_GFp_simple_add()
452 !field_sqr(group, n4, n5, ctx) || in ec_GFp_simple_add()
453 !field_mul(group, n3, n1, n4, ctx) || in ec_GFp_simple_add()
467 if (!field_mul(group, n0, n0, n6, ctx) || in ec_GFp_simple_add()
468 !field_mul(group, n5, n4, n5, ctx)) { in ec_GFp_simple_add()
471 if (!field_mul(group, n1, n2, n5, ctx) || in ec_GFp_simple_add()
495 int ec_GFp_simple_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, in ec_GFp_simple_dbl() argument
505 if (EC_POINT_is_at_infinity(group, a)) { in ec_GFp_simple_dbl()
510 field_mul = group->meth->field_mul; in ec_GFp_simple_dbl()
511 field_sqr = group->meth->field_sqr; in ec_GFp_simple_dbl()
512 p = &group->field; in ec_GFp_simple_dbl()
535 if (BN_cmp(&a->Z, &group->one) == 0) { in ec_GFp_simple_dbl()
536 if (!field_sqr(group, n0, &a->X, ctx) || in ec_GFp_simple_dbl()
539 !BN_mod_add_quick(n1, n0, &group->a, p)) { in ec_GFp_simple_dbl()
543 } else if (group->a_is_minus3) { in ec_GFp_simple_dbl()
544 if (!field_sqr(group, n1, &a->Z, ctx) || in ec_GFp_simple_dbl()
547 !field_mul(group, n1, n0, n2, ctx) || in ec_GFp_simple_dbl()
555 if (!field_sqr(group, n0, &a->X, ctx) || in ec_GFp_simple_dbl()
558 !field_sqr(group, n1, &a->Z, ctx) || in ec_GFp_simple_dbl()
559 !field_sqr(group, n1, n1, ctx) || in ec_GFp_simple_dbl()
560 !field_mul(group, n1, n1, &group->a, ctx) || in ec_GFp_simple_dbl()
568 if (BN_cmp(&a->Z, &group->one) == 0) { in ec_GFp_simple_dbl()
572 } else if (!field_mul(group, n0, &a->Y, &a->Z, ctx)) { in ec_GFp_simple_dbl()
581 if (!field_sqr(group, n3, &a->Y, ctx) || in ec_GFp_simple_dbl()
582 !field_mul(group, n2, &a->X, n3, ctx) || in ec_GFp_simple_dbl()
590 !field_sqr(group, &r->X, n1, ctx) || in ec_GFp_simple_dbl()
597 if (!field_sqr(group, n0, n3, ctx) || in ec_GFp_simple_dbl()
605 !field_mul(group, n0, n1, n0, ctx) || in ec_GFp_simple_dbl()
619 int ec_GFp_simple_invert(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx) { in ec_GFp_simple_invert() argument
620 if (EC_POINT_is_at_infinity(group, point) || BN_is_zero(&point->Y)) { in ec_GFp_simple_invert()
625 return BN_usub(&point->Y, &group->field, &point->Y); in ec_GFp_simple_invert()
628 int ec_GFp_simple_is_at_infinity(const EC_GROUP *group, const EC_POINT *point) { in ec_GFp_simple_is_at_infinity() argument
632 int ec_GFp_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point, in ec_GFp_simple_is_on_curve() argument
642 if (EC_POINT_is_at_infinity(group, point)) { in ec_GFp_simple_is_on_curve()
646 field_mul = group->meth->field_mul; in ec_GFp_simple_is_on_curve()
647 field_sqr = group->meth->field_sqr; in ec_GFp_simple_is_on_curve()
648 p = &group->field; in ec_GFp_simple_is_on_curve()
676 if (!field_sqr(group, rh, &point->X, ctx)) { in ec_GFp_simple_is_on_curve()
680 if (BN_cmp(&point->Z, &group->one) != 0) { in ec_GFp_simple_is_on_curve()
681 if (!field_sqr(group, tmp, &point->Z, ctx) || in ec_GFp_simple_is_on_curve()
682 !field_sqr(group, Z4, tmp, ctx) || in ec_GFp_simple_is_on_curve()
683 !field_mul(group, Z6, Z4, tmp, ctx)) { in ec_GFp_simple_is_on_curve()
688 if (group->a_is_minus3) { in ec_GFp_simple_is_on_curve()
692 !field_mul(group, rh, rh, &point->X, ctx)) { in ec_GFp_simple_is_on_curve()
696 if (!field_mul(group, tmp, Z4, &group->a, ctx) || in ec_GFp_simple_is_on_curve()
698 !field_mul(group, rh, rh, &point->X, ctx)) { in ec_GFp_simple_is_on_curve()
704 if (!field_mul(group, tmp, &group->b, Z6, ctx) || in ec_GFp_simple_is_on_curve()
710 if (!BN_mod_add_quick(rh, rh, &group->a, p) || in ec_GFp_simple_is_on_curve()
711 !field_mul(group, rh, rh, &point->X, ctx)) { in ec_GFp_simple_is_on_curve()
715 if (!BN_mod_add_quick(rh, rh, &group->b, p)) { in ec_GFp_simple_is_on_curve()
721 if (!field_sqr(group, tmp, &point->Y, ctx)) { in ec_GFp_simple_is_on_curve()
733 int ec_GFp_simple_cmp(const EC_GROUP *group, const EC_POINT *a, in ec_GFp_simple_cmp() argument
748 if (ec_GFp_simple_is_at_infinity(group, a)) { in ec_GFp_simple_cmp()
749 return ec_GFp_simple_is_at_infinity(group, b) ? 0 : 1; in ec_GFp_simple_cmp()
752 if (ec_GFp_simple_is_at_infinity(group, b)) { in ec_GFp_simple_cmp()
756 int a_Z_is_one = BN_cmp(&a->Z, &group->one) == 0; in ec_GFp_simple_cmp()
757 int b_Z_is_one = BN_cmp(&b->Z, &group->one) == 0; in ec_GFp_simple_cmp()
763 field_mul = group->meth->field_mul; in ec_GFp_simple_cmp()
764 field_sqr = group->meth->field_sqr; in ec_GFp_simple_cmp()
788 if (!field_sqr(group, Zb23, &b->Z, ctx) || in ec_GFp_simple_cmp()
789 !field_mul(group, tmp1, &a->X, Zb23, ctx)) { in ec_GFp_simple_cmp()
797 if (!field_sqr(group, Za23, &a->Z, ctx) || in ec_GFp_simple_cmp()
798 !field_mul(group, tmp2, &b->X, Za23, ctx)) { in ec_GFp_simple_cmp()
814 if (!field_mul(group, Zb23, Zb23, &b->Z, ctx) || in ec_GFp_simple_cmp()
815 !field_mul(group, tmp1, &a->Y, Zb23, ctx)) { in ec_GFp_simple_cmp()
823 if (!field_mul(group, Za23, Za23, &a->Z, ctx) || in ec_GFp_simple_cmp()
824 !field_mul(group, tmp2, &b->Y, Za23, ctx)) { in ec_GFp_simple_cmp()
847 int ec_GFp_simple_make_affine(const EC_GROUP *group, EC_POINT *point, in ec_GFp_simple_make_affine() argument
853 if (BN_cmp(&point->Z, &group->one) == 0 || in ec_GFp_simple_make_affine()
854 EC_POINT_is_at_infinity(group, point)) { in ec_GFp_simple_make_affine()
872 if (!EC_POINT_get_affine_coordinates_GFp(group, point, x, y, ctx) || in ec_GFp_simple_make_affine()
873 !EC_POINT_set_affine_coordinates_GFp(group, point, x, y, ctx)) { in ec_GFp_simple_make_affine()
876 if (BN_cmp(&point->Z, &group->one) != 0) { in ec_GFp_simple_make_affine()
889 int ec_GFp_simple_points_make_affine(const EC_GROUP *group, size_t num, in ec_GFp_simple_points_make_affine() argument
934 if (BN_copy(prod_Z[0], &group->one) == NULL) { in ec_GFp_simple_points_make_affine()
941 if (!group->meth->field_mul(group, prod_Z[i], prod_Z[i - 1], in ec_GFp_simple_points_make_affine()
960 if (!BN_mod_inverse_odd(tmp, &no_inverse, prod_Z[num - 1], &group->field, in ec_GFp_simple_points_make_affine()
966 if (group->meth->field_encode != NULL) { in ec_GFp_simple_points_make_affine()
970 if (!group->meth->field_encode(group, tmp, tmp, ctx) || in ec_GFp_simple_points_make_affine()
971 !group->meth->field_encode(group, tmp, tmp, ctx)) { in ec_GFp_simple_points_make_affine()
985 if (!group->meth->field_mul(group, tmp_Z, prod_Z[i - 1], tmp, ctx) || in ec_GFp_simple_points_make_affine()
987 !group->meth->field_mul(group, tmp, tmp, &points[i]->Z, ctx) || in ec_GFp_simple_points_make_affine()
1005 if (!group->meth->field_sqr(group, tmp, &p->Z, ctx) || in ec_GFp_simple_points_make_affine()
1006 !group->meth->field_mul(group, &p->X, &p->X, tmp, ctx) || in ec_GFp_simple_points_make_affine()
1007 !group->meth->field_mul(group, tmp, tmp, &p->Z, ctx) || in ec_GFp_simple_points_make_affine()
1008 !group->meth->field_mul(group, &p->Y, &p->Y, tmp, ctx)) { in ec_GFp_simple_points_make_affine()
1012 if (BN_copy(&p->Z, &group->one) == NULL) { in ec_GFp_simple_points_make_affine()
1036 int ec_GFp_simple_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, in ec_GFp_simple_field_mul() argument
1038 return BN_mod_mul(r, a, b, &group->field, ctx); in ec_GFp_simple_field_mul()
1041 int ec_GFp_simple_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, in ec_GFp_simple_field_sqr() argument
1043 return BN_mod_sqr(r, a, &group->field, ctx); in ec_GFp_simple_field_sqr()