Lines Matching refs:group
22 int ec_GF2m_simple_group_init(EC_GROUP *group) in ec_GF2m_simple_group_init() argument
24 group->field = BN_new(); in ec_GF2m_simple_group_init()
25 group->a = BN_new(); in ec_GF2m_simple_group_init()
26 group->b = BN_new(); in ec_GF2m_simple_group_init()
28 if (group->field == NULL || group->a == NULL || group->b == NULL) { in ec_GF2m_simple_group_init()
29 BN_free(group->field); in ec_GF2m_simple_group_init()
30 BN_free(group->a); in ec_GF2m_simple_group_init()
31 BN_free(group->b); in ec_GF2m_simple_group_init()
41 void ec_GF2m_simple_group_finish(EC_GROUP *group) in ec_GF2m_simple_group_finish() argument
43 BN_free(group->field); in ec_GF2m_simple_group_finish()
44 BN_free(group->a); in ec_GF2m_simple_group_finish()
45 BN_free(group->b); in ec_GF2m_simple_group_finish()
52 void ec_GF2m_simple_group_clear_finish(EC_GROUP *group) in ec_GF2m_simple_group_clear_finish() argument
54 BN_clear_free(group->field); in ec_GF2m_simple_group_clear_finish()
55 BN_clear_free(group->a); in ec_GF2m_simple_group_clear_finish()
56 BN_clear_free(group->b); in ec_GF2m_simple_group_clear_finish()
57 group->poly[0] = 0; in ec_GF2m_simple_group_clear_finish()
58 group->poly[1] = 0; in ec_GF2m_simple_group_clear_finish()
59 group->poly[2] = 0; in ec_GF2m_simple_group_clear_finish()
60 group->poly[3] = 0; in ec_GF2m_simple_group_clear_finish()
61 group->poly[4] = 0; in ec_GF2m_simple_group_clear_finish()
62 group->poly[5] = -1; in ec_GF2m_simple_group_clear_finish()
95 int ec_GF2m_simple_group_set_curve(EC_GROUP *group, in ec_GF2m_simple_group_set_curve() argument
102 if (!BN_copy(group->field, p)) in ec_GF2m_simple_group_set_curve()
104 i = BN_GF2m_poly2arr(group->field, group->poly, 6) - 1; in ec_GF2m_simple_group_set_curve()
111 if (!BN_GF2m_mod_arr(group->a, a, group->poly)) in ec_GF2m_simple_group_set_curve()
113 if (bn_wexpand(group->a, (int)(group->poly[0] + BN_BITS2 - 1) / BN_BITS2) in ec_GF2m_simple_group_set_curve()
116 bn_set_all_zero(group->a); in ec_GF2m_simple_group_set_curve()
119 if (!BN_GF2m_mod_arr(group->b, b, group->poly)) in ec_GF2m_simple_group_set_curve()
121 if (bn_wexpand(group->b, (int)(group->poly[0] + BN_BITS2 - 1) / BN_BITS2) in ec_GF2m_simple_group_set_curve()
124 bn_set_all_zero(group->b); in ec_GF2m_simple_group_set_curve()
135 int ec_GF2m_simple_group_get_curve(const EC_GROUP *group, BIGNUM *p, in ec_GF2m_simple_group_get_curve() argument
141 if (!BN_copy(p, group->field)) in ec_GF2m_simple_group_get_curve()
146 if (!BN_copy(a, group->a)) in ec_GF2m_simple_group_get_curve()
151 if (!BN_copy(b, group->b)) in ec_GF2m_simple_group_get_curve()
165 int ec_GF2m_simple_group_get_degree(const EC_GROUP *group) in ec_GF2m_simple_group_get_degree() argument
167 return BN_num_bits(group->field) - 1; in ec_GF2m_simple_group_get_degree()
174 int ec_GF2m_simple_group_check_discriminant(const EC_GROUP *group, in ec_GF2m_simple_group_check_discriminant() argument
194 if (!BN_GF2m_mod_arr(b, group->b, group->poly)) in ec_GF2m_simple_group_check_discriminant()
267 int ec_GF2m_simple_point_set_to_infinity(const EC_GROUP *group, in ec_GF2m_simple_point_set_to_infinity() argument
279 int ec_GF2m_simple_point_set_affine_coordinates(const EC_GROUP *group, in ec_GF2m_simple_point_set_affine_coordinates() argument
311 int ec_GF2m_simple_point_get_affine_coordinates(const EC_GROUP *group, in ec_GF2m_simple_point_get_affine_coordinates() argument
318 if (EC_POINT_is_at_infinity(group, point)) { in ec_GF2m_simple_point_get_affine_coordinates()
349 int ec_GF2m_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, in ec_GF2m_simple_add() argument
356 if (EC_POINT_is_at_infinity(group, a)) { in ec_GF2m_simple_add()
362 if (EC_POINT_is_at_infinity(group, b)) { in ec_GF2m_simple_add()
392 if (!EC_POINT_get_affine_coordinates(group, a, x0, y0, ctx)) in ec_GF2m_simple_add()
401 if (!EC_POINT_get_affine_coordinates(group, b, x1, y1, ctx)) in ec_GF2m_simple_add()
410 if (!group->meth->field_div(group, s, s, t, ctx)) in ec_GF2m_simple_add()
412 if (!group->meth->field_sqr(group, x2, s, ctx)) in ec_GF2m_simple_add()
414 if (!BN_GF2m_add(x2, x2, group->a)) in ec_GF2m_simple_add()
422 if (!EC_POINT_set_to_infinity(group, r)) in ec_GF2m_simple_add()
427 if (!group->meth->field_div(group, s, y1, x1, ctx)) in ec_GF2m_simple_add()
432 if (!group->meth->field_sqr(group, x2, s, ctx)) in ec_GF2m_simple_add()
436 if (!BN_GF2m_add(x2, x2, group->a)) in ec_GF2m_simple_add()
442 if (!group->meth->field_mul(group, y2, y2, s, ctx)) in ec_GF2m_simple_add()
449 if (!EC_POINT_set_affine_coordinates(group, r, x2, y2, ctx)) in ec_GF2m_simple_add()
464 int ec_GF2m_simple_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, in ec_GF2m_simple_dbl() argument
467 return ec_GF2m_simple_add(group, r, a, a, ctx); in ec_GF2m_simple_dbl()
470 int ec_GF2m_simple_invert(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx) in ec_GF2m_simple_invert() argument
472 if (EC_POINT_is_at_infinity(group, point) || BN_is_zero(point->Y)) in ec_GF2m_simple_invert()
476 if (!EC_POINT_make_affine(group, point, ctx)) in ec_GF2m_simple_invert()
482 int ec_GF2m_simple_is_at_infinity(const EC_GROUP *group, in ec_GF2m_simple_is_at_infinity() argument
493 int ec_GF2m_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point, in ec_GF2m_simple_is_on_curve() argument
503 if (EC_POINT_is_at_infinity(group, point)) in ec_GF2m_simple_is_on_curve()
506 field_mul = group->meth->field_mul; in ec_GF2m_simple_is_on_curve()
507 field_sqr = group->meth->field_sqr; in ec_GF2m_simple_is_on_curve()
531 if (!BN_GF2m_add(lh, point->X, group->a)) in ec_GF2m_simple_is_on_curve()
533 if (!field_mul(group, lh, lh, point->X, ctx)) in ec_GF2m_simple_is_on_curve()
537 if (!field_mul(group, lh, lh, point->X, ctx)) in ec_GF2m_simple_is_on_curve()
539 if (!BN_GF2m_add(lh, lh, group->b)) in ec_GF2m_simple_is_on_curve()
541 if (!field_sqr(group, y2, point->Y, ctx)) in ec_GF2m_simple_is_on_curve()
560 int ec_GF2m_simple_cmp(const EC_GROUP *group, const EC_POINT *a, in ec_GF2m_simple_cmp() argument
567 if (EC_POINT_is_at_infinity(group, a)) { in ec_GF2m_simple_cmp()
568 return EC_POINT_is_at_infinity(group, b) ? 0 : 1; in ec_GF2m_simple_cmp()
571 if (EC_POINT_is_at_infinity(group, b)) in ec_GF2m_simple_cmp()
592 if (!EC_POINT_get_affine_coordinates(group, a, aX, aY, ctx)) in ec_GF2m_simple_cmp()
594 if (!EC_POINT_get_affine_coordinates(group, b, bX, bY, ctx)) in ec_GF2m_simple_cmp()
605 int ec_GF2m_simple_make_affine(const EC_GROUP *group, EC_POINT *point, in ec_GF2m_simple_make_affine() argument
612 if (point->Z_is_one || EC_POINT_is_at_infinity(group, point)) in ec_GF2m_simple_make_affine()
627 if (!EC_POINT_get_affine_coordinates(group, point, x, y, ctx)) in ec_GF2m_simple_make_affine()
648 int ec_GF2m_simple_points_make_affine(const EC_GROUP *group, size_t num, in ec_GF2m_simple_points_make_affine() argument
654 if (!group->meth->make_affine(group, points[i], ctx)) in ec_GF2m_simple_points_make_affine()
662 int ec_GF2m_simple_field_mul(const EC_GROUP *group, BIGNUM *r, in ec_GF2m_simple_field_mul() argument
665 return BN_GF2m_mod_mul_arr(r, a, b, group->poly, ctx); in ec_GF2m_simple_field_mul()
669 int ec_GF2m_simple_field_sqr(const EC_GROUP *group, BIGNUM *r, in ec_GF2m_simple_field_sqr() argument
672 return BN_GF2m_mod_sqr_arr(r, a, group->poly, ctx); in ec_GF2m_simple_field_sqr()
676 int ec_GF2m_simple_field_div(const EC_GROUP *group, BIGNUM *r, in ec_GF2m_simple_field_div() argument
679 return BN_GF2m_mod_div(r, a, b, group->field, ctx); in ec_GF2m_simple_field_div()
689 int ec_GF2m_simple_ladder_pre(const EC_GROUP *group, in ec_GF2m_simple_ladder_pre() argument
699 if (!BN_priv_rand(s->Z, BN_num_bits(group->field) - 1, in ec_GF2m_simple_ladder_pre()
707 if ((group->meth->field_encode != NULL in ec_GF2m_simple_ladder_pre()
708 && !group->meth->field_encode(group, s->Z, s->Z, ctx)) in ec_GF2m_simple_ladder_pre()
709 || !group->meth->field_mul(group, s->X, p->X, s->Z, ctx)) in ec_GF2m_simple_ladder_pre()
714 if (!BN_priv_rand(r->Y, BN_num_bits(group->field) - 1, in ec_GF2m_simple_ladder_pre()
721 if ((group->meth->field_encode != NULL in ec_GF2m_simple_ladder_pre()
722 && !group->meth->field_encode(group, r->Y, r->Y, ctx)) in ec_GF2m_simple_ladder_pre()
723 || !group->meth->field_sqr(group, r->Z, p->X, ctx) in ec_GF2m_simple_ladder_pre()
724 || !group->meth->field_sqr(group, r->X, r->Z, ctx) in ec_GF2m_simple_ladder_pre()
725 || !BN_GF2m_add(r->X, r->X, group->b) in ec_GF2m_simple_ladder_pre()
726 || !group->meth->field_mul(group, r->Z, r->Z, r->Y, ctx) in ec_GF2m_simple_ladder_pre()
727 || !group->meth->field_mul(group, r->X, r->X, r->Y, ctx)) in ec_GF2m_simple_ladder_pre()
742 int ec_GF2m_simple_ladder_step(const EC_GROUP *group, in ec_GF2m_simple_ladder_step() argument
746 if (!group->meth->field_mul(group, r->Y, r->Z, s->X, ctx) in ec_GF2m_simple_ladder_step()
747 || !group->meth->field_mul(group, s->X, r->X, s->Z, ctx) in ec_GF2m_simple_ladder_step()
748 || !group->meth->field_sqr(group, s->Y, r->Z, ctx) in ec_GF2m_simple_ladder_step()
749 || !group->meth->field_sqr(group, r->Z, r->X, ctx) in ec_GF2m_simple_ladder_step()
751 || !group->meth->field_sqr(group, s->Z, s->Z, ctx) in ec_GF2m_simple_ladder_step()
752 || !group->meth->field_mul(group, s->X, r->Y, s->X, ctx) in ec_GF2m_simple_ladder_step()
753 || !group->meth->field_mul(group, r->Y, s->Z, p->X, ctx) in ec_GF2m_simple_ladder_step()
755 || !group->meth->field_sqr(group, r->Y, r->Z, ctx) in ec_GF2m_simple_ladder_step()
756 || !group->meth->field_mul(group, r->Z, r->Z, s->Y, ctx) in ec_GF2m_simple_ladder_step()
757 || !group->meth->field_sqr(group, s->Y, s->Y, ctx) in ec_GF2m_simple_ladder_step()
758 || !group->meth->field_mul(group, s->Y, s->Y, group->b, ctx) in ec_GF2m_simple_ladder_step()
772 int ec_GF2m_simple_ladder_post(const EC_GROUP *group, in ec_GF2m_simple_ladder_post() argument
780 return EC_POINT_set_to_infinity(group, r); in ec_GF2m_simple_ladder_post()
784 || !EC_POINT_invert(group, r, ctx)) { in ec_GF2m_simple_ladder_post()
800 if (!group->meth->field_mul(group, t0, r->Z, s->Z, ctx) in ec_GF2m_simple_ladder_post()
801 || !group->meth->field_mul(group, t1, p->X, r->Z, ctx) in ec_GF2m_simple_ladder_post()
803 || !group->meth->field_mul(group, t2, p->X, s->Z, ctx) in ec_GF2m_simple_ladder_post()
804 || !group->meth->field_mul(group, r->Z, r->X, t2, ctx) in ec_GF2m_simple_ladder_post()
806 || !group->meth->field_mul(group, t1, t1, t2, ctx) in ec_GF2m_simple_ladder_post()
807 || !group->meth->field_sqr(group, t2, p->X, ctx) in ec_GF2m_simple_ladder_post()
809 || !group->meth->field_mul(group, t2, t2, t0, ctx) in ec_GF2m_simple_ladder_post()
811 || !group->meth->field_mul(group, t2, p->X, t0, ctx) in ec_GF2m_simple_ladder_post()
812 || !group->meth->field_inv(group, t2, t2, ctx) in ec_GF2m_simple_ladder_post()
813 || !group->meth->field_mul(group, t1, t1, t2, ctx) in ec_GF2m_simple_ladder_post()
814 || !group->meth->field_mul(group, r->X, r->Z, t2, ctx) in ec_GF2m_simple_ladder_post()
816 || !group->meth->field_mul(group, t2, t2, t1, ctx) in ec_GF2m_simple_ladder_post()
835 int ec_GF2m_simple_points_mul(const EC_GROUP *group, EC_POINT *r, in ec_GF2m_simple_points_mul() argument
858 if (num > 1 || BN_is_zero(group->order) || BN_is_zero(group->cofactor)) in ec_GF2m_simple_points_mul()
859 return ec_wNAF_mul(group, r, scalar, num, points, scalars, ctx); in ec_GF2m_simple_points_mul()
863 return ec_scalar_mul_ladder(group, r, scalar, NULL, ctx); in ec_GF2m_simple_points_mul()
867 return ec_scalar_mul_ladder(group, r, scalars[0], points[0], ctx); in ec_GF2m_simple_points_mul()
874 if ((t = EC_POINT_new(group)) == NULL) { in ec_GF2m_simple_points_mul()
879 if (!ec_scalar_mul_ladder(group, t, scalar, NULL, ctx) in ec_GF2m_simple_points_mul()
880 || !ec_scalar_mul_ladder(group, r, scalars[0], points[0], ctx) in ec_GF2m_simple_points_mul()
881 || !EC_POINT_add(group, r, t, r, ctx)) in ec_GF2m_simple_points_mul()
896 static int ec_GF2m_simple_field_inv(const EC_GROUP *group, BIGNUM *r, in ec_GF2m_simple_field_inv() argument
901 if (!(ret = BN_GF2m_mod_inv(r, a, group->field, ctx))) in ec_GF2m_simple_field_inv()