Lines Matching refs:group
28 int ossl_ec_GF2m_simple_group_init(EC_GROUP *group)
30 group->field = BN_new();
31 group->a = BN_new();
32 group->b = BN_new();
34 if (group->field == NULL || group->a == NULL || group->b == NULL) {
35 BN_free(group->field);
36 BN_free(group->a);
37 BN_free(group->b);
47 void ossl_ec_GF2m_simple_group_finish(EC_GROUP *group)
49 BN_free(group->field);
50 BN_free(group->a);
51 BN_free(group->b);
58 void ossl_ec_GF2m_simple_group_clear_finish(EC_GROUP *group)
60 BN_clear_free(group->field);
61 BN_clear_free(group->a);
62 BN_clear_free(group->b);
63 group->poly[0] = 0;
64 group->poly[1] = 0;
65 group->poly[2] = 0;
66 group->poly[3] = 0;
67 group->poly[4] = 0;
68 group->poly[5] = -1;
101 int ossl_ec_GF2m_simple_group_set_curve(EC_GROUP *group,
107 /* group->field */
108 if (!BN_copy(group->field, p))
110 i = BN_GF2m_poly2arr(group->field, group->poly, 6) - 1;
116 /* group->a */
117 if (!BN_GF2m_mod_arr(group->a, a, group->poly))
119 if (bn_wexpand(group->a, (int)(group->poly[0] + BN_BITS2 - 1) / BN_BITS2)
122 bn_set_all_zero(group->a);
124 /* group->b */
125 if (!BN_GF2m_mod_arr(group->b, b, group->poly))
127 if (bn_wexpand(group->b, (int)(group->poly[0] + BN_BITS2 - 1) / BN_BITS2)
130 bn_set_all_zero(group->b);
141 int ossl_ec_GF2m_simple_group_get_curve(const EC_GROUP *group, BIGNUM *p,
147 if (!BN_copy(p, group->field))
152 if (!BN_copy(a, group->a))
157 if (!BN_copy(b, group->b))
171 int ossl_ec_GF2m_simple_group_get_degree(const EC_GROUP *group)
173 return BN_num_bits(group->field) - 1;
180 int ossl_ec_GF2m_simple_group_check_discriminant(const EC_GROUP *group,
201 if (!BN_GF2m_mod_arr(b, group->b, group->poly))
276 int ossl_ec_GF2m_simple_point_set_to_infinity(const EC_GROUP *group,
288 int ossl_ec_GF2m_simple_point_set_affine_coordinates(const EC_GROUP *group,
320 int ossl_ec_GF2m_simple_point_get_affine_coordinates(const EC_GROUP *group,
327 if (EC_POINT_is_at_infinity(group, point)) {
356 int ossl_ec_GF2m_simple_add(const EC_GROUP *group, EC_POINT *r,
365 if (EC_POINT_is_at_infinity(group, a)) {
371 if (EC_POINT_is_at_infinity(group, b)) {
403 if (!EC_POINT_get_affine_coordinates(group, a, x0, y0, ctx))
412 if (!EC_POINT_get_affine_coordinates(group, b, x1, y1, ctx))
421 if (!group->meth->field_div(group, s, s, t, ctx))
423 if (!group->meth->field_sqr(group, x2, s, ctx))
425 if (!BN_GF2m_add(x2, x2, group->a))
433 if (!EC_POINT_set_to_infinity(group, r))
438 if (!group->meth->field_div(group, s, y1, x1, ctx))
443 if (!group->meth->field_sqr(group, x2, s, ctx))
447 if (!BN_GF2m_add(x2, x2, group->a))
453 if (!group->meth->field_mul(group, y2, y2, s, ctx))
460 if (!EC_POINT_set_affine_coordinates(group, r, x2, y2, ctx))
477 int ossl_ec_GF2m_simple_dbl(const EC_GROUP *group, EC_POINT *r,
480 return ossl_ec_GF2m_simple_add(group, r, a, a, ctx);
483 int ossl_ec_GF2m_simple_invert(const EC_GROUP *group, EC_POINT *point,
486 if (EC_POINT_is_at_infinity(group, point) || BN_is_zero(point->Y))
490 if (group->meth->make_affine == NULL
491 || !group->meth->make_affine(group, point, ctx))
497 int ossl_ec_GF2m_simple_is_at_infinity(const EC_GROUP *group,
508 int ossl_ec_GF2m_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point,
520 if (EC_POINT_is_at_infinity(group, point))
523 field_mul = group->meth->field_mul;
524 field_sqr = group->meth->field_sqr;
550 if (!BN_GF2m_add(lh, point->X, group->a))
552 if (!field_mul(group, lh, lh, point->X, ctx))
556 if (!field_mul(group, lh, lh, point->X, ctx))
558 if (!BN_GF2m_add(lh, lh, group->b))
560 if (!field_sqr(group, y2, point->Y, ctx))
581 int ossl_ec_GF2m_simple_cmp(const EC_GROUP *group, const EC_POINT *a,
590 if (EC_POINT_is_at_infinity(group, a)) {
591 return EC_POINT_is_at_infinity(group, b) ? 0 : 1;
594 if (EC_POINT_is_at_infinity(group, b))
617 if (!EC_POINT_get_affine_coordinates(group, a, aX, aY, ctx))
619 if (!EC_POINT_get_affine_coordinates(group, b, bX, bY, ctx))
632 int ossl_ec_GF2m_simple_make_affine(const EC_GROUP *group, EC_POINT *point,
641 if (point->Z_is_one || EC_POINT_is_at_infinity(group, point))
658 if (!EC_POINT_get_affine_coordinates(group, point, x, y, ctx))
681 int ossl_ec_GF2m_simple_points_make_affine(const EC_GROUP *group, size_t num,
687 if (!group->meth->make_affine(group, points[i], ctx))
695 int ossl_ec_GF2m_simple_field_mul(const EC_GROUP *group, BIGNUM *r,
698 return BN_GF2m_mod_mul_arr(r, a, b, group->poly, ctx);
702 int ossl_ec_GF2m_simple_field_sqr(const EC_GROUP *group, BIGNUM *r,
705 return BN_GF2m_mod_sqr_arr(r, a, group->poly, ctx);
709 int ossl_ec_GF2m_simple_field_div(const EC_GROUP *group, BIGNUM *r,
712 return BN_GF2m_mod_div(r, a, b, group->field, ctx);
722 int ec_GF2m_simple_ladder_pre(const EC_GROUP *group,
732 if (!BN_priv_rand_ex(s->Z, BN_num_bits(group->field) - 1,
740 if ((group->meth->field_encode != NULL
741 && !group->meth->field_encode(group, s->Z, s->Z, ctx))
742 || !group->meth->field_mul(group, s->X, p->X, s->Z, ctx))
747 if (!BN_priv_rand_ex(r->Y, BN_num_bits(group->field) - 1,
754 if ((group->meth->field_encode != NULL
755 && !group->meth->field_encode(group, r->Y, r->Y, ctx))
756 || !group->meth->field_sqr(group, r->Z, p->X, ctx)
757 || !group->meth->field_sqr(group, r->X, r->Z, ctx)
758 || !BN_GF2m_add(r->X, r->X, group->b)
759 || !group->meth->field_mul(group, r->Z, r->Z, r->Y, ctx)
760 || !group->meth->field_mul(group, r->X, r->X, r->Y, ctx))
775 int ec_GF2m_simple_ladder_step(const EC_GROUP *group,
779 if (!group->meth->field_mul(group, r->Y, r->Z, s->X, ctx)
780 || !group->meth->field_mul(group, s->X, r->X, s->Z, ctx)
781 || !group->meth->field_sqr(group, s->Y, r->Z, ctx)
782 || !group->meth->field_sqr(group, r->Z, r->X, ctx)
784 || !group->meth->field_sqr(group, s->Z, s->Z, ctx)
785 || !group->meth->field_mul(group, s->X, r->Y, s->X, ctx)
786 || !group->meth->field_mul(group, r->Y, s->Z, p->X, ctx)
788 || !group->meth->field_sqr(group, r->Y, r->Z, ctx)
789 || !group->meth->field_mul(group, r->Z, r->Z, s->Y, ctx)
790 || !group->meth->field_sqr(group, s->Y, s->Y, ctx)
791 || !group->meth->field_mul(group, s->Y, s->Y, group->b, ctx)
805 int ec_GF2m_simple_ladder_post(const EC_GROUP *group,
813 return EC_POINT_set_to_infinity(group, r);
817 || !EC_POINT_invert(group, r, ctx)) {
833 if (!group->meth->field_mul(group, t0, r->Z, s->Z, ctx)
834 || !group->meth->field_mul(group, t1, p->X, r->Z, ctx)
836 || !group->meth->field_mul(group, t2, p->X, s->Z, ctx)
837 || !group->meth->field_mul(group, r->Z, r->X, t2, ctx)
839 || !group->meth->field_mul(group, t1, t1, t2, ctx)
840 || !group->meth->field_sqr(group, t2, p->X, ctx)
842 || !group->meth->field_mul(group, t2, t2, t0, ctx)
844 || !group->meth->field_mul(group, t2, p->X, t0, ctx)
845 || !group->meth->field_inv(group, t2, t2, ctx)
846 || !group->meth->field_mul(group, t1, t1, t2, ctx)
847 || !group->meth->field_mul(group, r->X, r->Z, t2, ctx)
849 || !group->meth->field_mul(group, t2, t2, t1, ctx)
868 int ec_GF2m_simple_points_mul(const EC_GROUP *group, EC_POINT *r,
888 * We also let the default implementation handle degenerate cases like group
891 if (num > 1 || BN_is_zero(group->order) || BN_is_zero(group->cofactor))
892 return ossl_ec_wNAF_mul(group, r, scalar, num, points, scalars, ctx);
896 return ossl_ec_scalar_mul_ladder(group, r, scalar, NULL, ctx);
900 return ossl_ec_scalar_mul_ladder(group, r, scalars[0], points[0], ctx);
907 if ((t = EC_POINT_new(group)) == NULL) {
912 if (!ossl_ec_scalar_mul_ladder(group, t, scalar, NULL, ctx)
913 || !ossl_ec_scalar_mul_ladder(group, r, scalars[0], points[0], ctx)
914 || !EC_POINT_add(group, r, t, r, ctx))
929 static int ec_GF2m_simple_field_inv(const EC_GROUP *group, BIGNUM *r,
934 if (!(ret = BN_GF2m_mod_inv(r, a, group->field, ctx)))