Lines Matching refs:group

131 int ec_GFp_simple_group_init(EC_GROUP *group)
133 BN_init(&group->field);
134 BN_init(&group->a);
135 BN_init(&group->b);
136 group->a_is_minus3 = 0;
140 void ec_GFp_simple_group_finish(EC_GROUP *group)
142 BN_free(&group->field);
143 BN_free(&group->a);
144 BN_free(&group->b);
147 void ec_GFp_simple_group_clear_finish(EC_GROUP *group)
149 BN_clear_free(&group->field);
150 BN_clear_free(&group->a);
151 BN_clear_free(&group->b);
168 int ec_GFp_simple_group_set_curve(EC_GROUP *group,
193 /* group->field */
194 if (!BN_copy(&group->field, p))
196 BN_set_negative(&group->field, 0);
198 /* group->a */
201 if (group->meth->field_encode) {
202 if (!group->meth->field_encode(group, &group->a, tmp_a, ctx))
204 } else if (!BN_copy(&group->a, tmp_a))
207 /* group->b */
208 if (!BN_nnmod(&group->b, b, p, ctx))
210 if (group->meth->field_encode)
211 if (!group->meth->field_encode(group, &group->b, &group->b, ctx))
214 /* group->a_is_minus3 */
217 group->a_is_minus3 = (0 == BN_cmp(tmp_a, &group->field));
228 int ec_GFp_simple_group_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a,
235 if (!BN_copy(p, &group->field))
240 if (group->meth->field_decode) {
247 if (!group->meth->field_decode(group, a, &group->a, ctx))
251 if (!group->meth->field_decode(group, b, &group->b, ctx))
256 if (!BN_copy(a, &group->a))
260 if (!BN_copy(b, &group->b))
274 int ec_GFp_simple_group_get_degree(const EC_GROUP *group)
276 return BN_num_bits(&group->field);
279 int ec_GFp_simple_group_check_discriminant(const EC_GROUP *group, BN_CTX *ctx)
283 const BIGNUM *p = &group->field;
303 if (group->meth->field_decode) {
304 if (!group->meth->field_decode(group, a, &group->a, ctx))
306 if (!group->meth->field_decode(group, b, &group->b, ctx))
309 if (!BN_copy(a, &group->a))
311 if (!BN_copy(b, &group->b))
391 int ec_GFp_simple_point_set_to_infinity(const EC_GROUP *group,
399 int ec_GFp_simple_set_Jprojective_coordinates_GFp(const EC_GROUP *group,
416 if (!BN_nnmod(&point->X, x, &group->field, ctx))
418 if (group->meth->field_encode) {
419 if (!group->meth->field_encode(group, &point->X, &point->X, ctx))
425 if (!BN_nnmod(&point->Y, y, &group->field, ctx))
427 if (group->meth->field_encode) {
428 if (!group->meth->field_encode(group, &point->Y, &point->Y, ctx))
436 if (!BN_nnmod(&point->Z, z, &group->field, ctx))
439 if (group->meth->field_encode) {
440 if (Z_is_one && (group->meth->field_set_to_one != 0)) {
441 if (!group->meth->field_set_to_one(group, &point->Z, ctx))
444 if (!group->
445 meth->field_encode(group, &point->Z, &point->Z, ctx))
460 int ec_GFp_simple_get_Jprojective_coordinates_GFp(const EC_GROUP *group,
468 if (group->meth->field_decode != 0) {
476 if (!group->meth->field_decode(group, x, &point->X, ctx))
480 if (!group->meth->field_decode(group, y, &point->Y, ctx))
484 if (!group->meth->field_decode(group, z, &point->Z, ctx))
510 int ec_GFp_simple_point_set_affine_coordinates(const EC_GROUP *group,
524 return EC_POINT_set_Jprojective_coordinates_GFp(group, point, x, y,
528 int ec_GFp_simple_point_get_affine_coordinates(const EC_GROUP *group,
538 if (EC_POINT_is_at_infinity(group, point)) {
560 if (group->meth->field_decode) {
561 if (!group->meth->field_decode(group, Z, &point->Z, ctx))
569 if (group->meth->field_decode) {
571 if (!group->meth->field_decode(group, x, &point->X, ctx))
575 if (!group->meth->field_decode(group, y, &point->Y, ctx))
589 if (!BN_mod_inverse(Z_1, Z_, &group->field, ctx)) {
595 if (group->meth->field_encode == 0) {
597 if (!group->meth->field_sqr(group, Z_2, Z_1, ctx))
600 if (!BN_mod_sqr(Z_2, Z_1, &group->field, ctx))
609 if (!group->meth->field_mul(group, x, &point->X, Z_2, ctx))
614 if (group->meth->field_encode == 0) {
618 if (!group->meth->field_mul(group, Z_3, Z_2, Z_1, ctx))
621 if (!BN_mod_mul(Z_3, Z_2, Z_1, &group->field, ctx))
629 if (!group->meth->field_mul(group, y, &point->Y, Z_3, ctx))
643 int ec_GFp_simple_set_compressed_coordinates(const EC_GROUP *group,
678 if (!BN_nnmod(x, x_, &group->field, ctx))
680 if (group->meth->field_decode == 0) {
682 if (!group->meth->field_sqr(group, tmp2, x_, ctx))
684 if (!group->meth->field_mul(group, tmp1, tmp2, x_, ctx))
687 if (!BN_mod_sqr(tmp2, x_, &group->field, ctx))
689 if (!BN_mod_mul(tmp1, tmp2, x_, &group->field, ctx))
694 if (group->a_is_minus3) {
695 if (!BN_mod_lshift1_quick(tmp2, x, &group->field))
697 if (!BN_mod_add_quick(tmp2, tmp2, x, &group->field))
699 if (!BN_mod_sub_quick(tmp1, tmp1, tmp2, &group->field))
702 if (group->meth->field_decode) {
703 if (!group->meth->field_decode(group, tmp2, &group->a, ctx))
705 if (!BN_mod_mul(tmp2, tmp2, x, &group->field, ctx))
709 if (!group->meth->field_mul(group, tmp2, &group->a, x, ctx))
713 if (!BN_mod_add_quick(tmp1, tmp1, tmp2, &group->field))
718 if (group->meth->field_decode) {
719 if (!group->meth->field_decode(group, tmp2, &group->b, ctx))
721 if (!BN_mod_add_quick(tmp1, tmp1, tmp2, &group->field))
724 if (!BN_mod_add_quick(tmp1, tmp1, &group->b, &group->field))
728 if (!BN_mod_sqrt(y, tmp1, &group->field, ctx)) {
746 kron = BN_kronecker(x, &group->field, ctx);
761 if (!BN_usub(y, &group->field, y))
770 if (!EC_POINT_set_affine_coordinates_GFp(group, point, x, y, ctx))
782 size_t ec_GFp_simple_point2oct(const EC_GROUP *group, const EC_POINT *point,
799 if (EC_POINT_is_at_infinity(group, point)) {
812 field_len = BN_num_bytes(&group->field);
837 if (!EC_POINT_get_affine_coordinates_GFp(group, point, x, y, ctx))
899 int ec_GFp_simple_oct2point(const EC_GROUP *group, EC_POINT *point,
933 return EC_POINT_set_to_infinity(group, point);
936 field_len = BN_num_bytes(&group->field);
960 if (BN_ucmp(x, &group->field) >= 0) {
967 (group, point, x, y_bit, ctx))
972 if (BN_ucmp(y, &group->field) >= 0) {
983 if (!EC_POINT_set_affine_coordinates_GFp(group, point, x, y, ctx))
988 if (EC_POINT_is_on_curve(group, point, ctx) <= 0) {
1002 int ec_GFp_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a,
1014 return EC_POINT_dbl(group, r, a, ctx);
1015 if (EC_POINT_is_at_infinity(group, a))
1017 if (EC_POINT_is_at_infinity(group, b))
1020 field_mul = group->meth->field_mul;
1021 field_sqr = group->meth->field_sqr;
1022 p = &group->field;
1056 if (!field_sqr(group, n0, &b->Z, ctx))
1058 if (!field_mul(group, n1, &a->X, n0, ctx))
1062 if (!field_mul(group, n0, n0, &b->Z, ctx))
1064 if (!field_mul(group, n2, &a->Y, n0, ctx))
1078 if (!field_sqr(group, n0, &a->Z, ctx))
1080 if (!field_mul(group, n3, &b->X, n0, ctx))
1084 if (!field_mul(group, n0, n0, &a->Z, ctx))
1086 if (!field_mul(group, n4, &b->Y, n0, ctx))
1103 ret = EC_POINT_dbl(group, r, a, ctx);
1135 if (!field_mul(group, n0, &a->Z, &b->Z, ctx))
1138 if (!field_mul(group, &r->Z, n0, n5, ctx))
1145 if (!field_sqr(group, n0, n6, ctx))
1147 if (!field_sqr(group, n4, n5, ctx))
1149 if (!field_mul(group, n3, n1, n4, ctx))
1163 if (!field_mul(group, n0, n0, n6, ctx))
1165 if (!field_mul(group, n5, n4, n5, ctx))
1167 if (!field_mul(group, n1, n2, n5, ctx))
1189 int ec_GFp_simple_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a,
1200 if (EC_POINT_is_at_infinity(group, a)) {
1206 field_mul = group->meth->field_mul;
1207 field_sqr = group->meth->field_sqr;
1208 p = &group->field;
1232 if (!field_sqr(group, n0, &a->X, ctx))
1238 if (!BN_mod_add_quick(n1, n0, &group->a, p))
1241 } else if (group->a_is_minus3) {
1242 if (!field_sqr(group, n1, &a->Z, ctx))
1248 if (!field_mul(group, n1, n0, n2, ctx))
1259 if (!field_sqr(group, n0, &a->X, ctx))
1265 if (!field_sqr(group, n1, &a->Z, ctx))
1267 if (!field_sqr(group, n1, n1, ctx))
1269 if (!field_mul(group, n1, n1, &group->a, ctx))
1281 if (!field_mul(group, n0, &a->Y, &a->Z, ctx))
1290 if (!field_sqr(group, n3, &a->Y, ctx))
1292 if (!field_mul(group, n2, &a->X, n3, ctx))
1301 if (!field_sqr(group, &r->X, n1, ctx))
1308 if (!field_sqr(group, n0, n3, ctx))
1317 if (!field_mul(group, n0, n1, n0, ctx))
1332 int ec_GFp_simple_invert(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx)
1334 if (EC_POINT_is_at_infinity(group, point) || BN_is_zero(&point->Y))
1338 return BN_usub(&point->Y, &group->field, &point->Y);
1341 int ec_GFp_simple_is_at_infinity(const EC_GROUP *group, const EC_POINT *point)
1346 int ec_GFp_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point,
1357 if (EC_POINT_is_at_infinity(group, point))
1360 field_mul = group->meth->field_mul;
1361 field_sqr = group->meth->field_sqr;
1362 p = &group->field;
1389 if (!field_sqr(group, rh, &point->X, ctx))
1393 if (!field_sqr(group, tmp, &point->Z, ctx))
1395 if (!field_sqr(group, Z4, tmp, ctx))
1397 if (!field_mul(group, Z6, Z4, tmp, ctx))
1401 if (group->a_is_minus3) {
1408 if (!field_mul(group, rh, rh, &point->X, ctx))
1411 if (!field_mul(group, tmp, Z4, &group->a, ctx))
1415 if (!field_mul(group, rh, rh, &point->X, ctx))
1420 if (!field_mul(group, tmp, &group->b, Z6, ctx))
1428 if (!BN_mod_add_quick(rh, rh, &group->a, p))
1430 if (!field_mul(group, rh, rh, &point->X, ctx))
1433 if (!BN_mod_add_quick(rh, rh, &group->b, p))
1438 if (!field_sqr(group, tmp, &point->Y, ctx))
1450 int ec_GFp_simple_cmp(const EC_GROUP *group, const EC_POINT *a,
1468 if (EC_POINT_is_at_infinity(group, a)) {
1469 return EC_POINT_is_at_infinity(group, b) ? 0 : 1;
1472 if (EC_POINT_is_at_infinity(group, b))
1480 field_mul = group->meth->field_mul;
1481 field_sqr = group->meth->field_sqr;
1505 if (!field_sqr(group, Zb23, &b->Z, ctx))
1507 if (!field_mul(group, tmp1, &a->X, Zb23, ctx))
1513 if (!field_sqr(group, Za23, &a->Z, ctx))
1515 if (!field_mul(group, tmp2, &b->X, Za23, ctx))
1528 if (!field_mul(group, Zb23, Zb23, &b->Z, ctx))
1530 if (!field_mul(group, tmp1, &a->Y, Zb23, ctx))
1536 if (!field_mul(group, Za23, Za23, &a->Z, ctx))
1538 if (!field_mul(group, tmp2, &b->Y, Za23, ctx))
1560 int ec_GFp_simple_make_affine(const EC_GROUP *group, EC_POINT *point,
1567 if (point->Z_is_one || EC_POINT_is_at_infinity(group, point))
1582 if (!EC_POINT_get_affine_coordinates_GFp(group, point, x, y, ctx))
1584 if (!EC_POINT_set_affine_coordinates_GFp(group, point, x, y, ctx))
1600 int ec_GFp_simple_points_make_affine(const EC_GROUP *group, size_t num,
1642 if (group->meth->field_set_to_one != 0) {
1643 if (!group->meth->field_set_to_one(group, prod_Z[0], ctx))
1653 if (!group->meth->field_mul(group, prod_Z[i], prod_Z[i - 1],
1667 if (!BN_mod_inverse(tmp, prod_Z[num - 1], &group->field, ctx)) {
1671 if (group->meth->field_encode != 0) {
1677 if (!group->meth->field_encode(group, tmp, tmp, ctx))
1679 if (!group->meth->field_encode(group, tmp, tmp, ctx))
1693 if (!group->
1694 meth->field_mul(group, tmp_Z, prod_Z[i - 1], tmp, ctx))
1699 if (!group->meth->field_mul(group, tmp, tmp, &points[i]->Z, ctx))
1721 if (!group->meth->field_sqr(group, tmp, &p->Z, ctx))
1723 if (!group->meth->field_mul(group, &p->X, &p->X, tmp, ctx))
1726 if (!group->meth->field_mul(group, tmp, tmp, &p->Z, ctx))
1728 if (!group->meth->field_mul(group, &p->Y, &p->Y, tmp, ctx))
1731 if (group->meth->field_set_to_one != 0) {
1732 if (!group->meth->field_set_to_one(group, &p->Z, ctx))
1759 int ec_GFp_simple_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a,
1762 return BN_mod_mul(r, a, b, &group->field, ctx);
1765 int ec_GFp_simple_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a,
1768 return BN_mod_sqr(r, a, &group->field, ctx);