Lines Matching refs:group

135 int ec_GFp_simple_group_init(EC_GROUP *group) {
136 BN_init(&group->field);
137 BN_init(&group->a);
138 BN_init(&group->b);
139 group->a_is_minus3 = 0;
143 void ec_GFp_simple_group_finish(EC_GROUP *group) {
144 BN_free(&group->field);
145 BN_free(&group->a);
146 BN_free(&group->b);
149 void ec_GFp_simple_group_clear_finish(EC_GROUP *group) {
150 BN_clear_free(&group->field);
151 BN_clear_free(&group->a);
152 BN_clear_free(&group->b);
166 int ec_GFp_simple_group_set_curve(EC_GROUP *group, const BIGNUM *p,
192 /* group->field */
193 if (!BN_copy(&group->field, p)) {
196 BN_set_negative(&group->field, 0);
198 /* group->a */
202 if (group->meth->field_encode) {
203 if (!group->meth->field_encode(group, &group->a, tmp_a, ctx)) {
206 } else if (!BN_copy(&group->a, tmp_a)) {
210 /* group->b */
211 if (!BN_nnmod(&group->b, b, p, ctx)) {
214 if (group->meth->field_encode &&
215 !group->meth->field_encode(group, &group->b, &group->b, ctx)) {
219 /* group->a_is_minus3 */
223 group->a_is_minus3 = (0 == BN_cmp(tmp_a, &group->field));
233 int ec_GFp_simple_group_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a,
238 if (p != NULL && !BN_copy(p, &group->field)) {
243 if (group->meth->field_decode) {
250 if (a != NULL && !group->meth->field_decode(group, a, &group->a, ctx)) {
253 if (b != NULL && !group->meth->field_decode(group, b, &group->b, ctx)) {
257 if (a != NULL && !BN_copy(a, &group->a)) {
260 if (b != NULL && !BN_copy(b, &group->b)) {
273 int ec_GFp_simple_group_get_degree(const EC_GROUP *group) {
274 return BN_num_bits(&group->field);
277 int ec_GFp_simple_group_check_discriminant(const EC_GROUP *group, BN_CTX *ctx) {
280 const BIGNUM *p = &group->field;
301 if (group->meth->field_decode) {
302 if (!group->meth->field_decode(group, a, &group->a, ctx) ||
303 !group->meth->field_decode(group, b, &group->b, ctx)) {
307 if (!BN_copy(a, &group->a) || !BN_copy(b, &group->b)) {
381 int ec_GFp_simple_point_set_to_infinity(const EC_GROUP *group,
389 const EC_GROUP *group, EC_POINT *point, const BIGNUM *x, const BIGNUM *y,
402 if (!BN_nnmod(&point->X, x, &group->field, ctx)) {
405 if (group->meth->field_encode &&
406 !group->meth->field_encode(group, &point->X, &point->X, ctx)) {
412 if (!BN_nnmod(&point->Y, y, &group->field, ctx)) {
415 if (group->meth->field_encode &&
416 !group->meth->field_encode(group, &point->Y, &point->Y, ctx)) {
424 if (!BN_nnmod(&point->Z, z, &group->field, ctx)) {
428 if (group->meth->field_encode) {
429 if (Z_is_one && (group->meth->field_set_to_one != 0)) {
430 if (!group->meth->field_set_to_one(group, &point->Z, ctx)) {
433 } else if (!group->meth->field_encode(group, &point->Z, &point->Z, ctx)) {
447 int ec_GFp_simple_get_Jprojective_coordinates_GFp(const EC_GROUP *group,
454 if (group->meth->field_decode != 0) {
462 if (x != NULL && !group->meth->field_decode(group, x, &point->X, ctx)) {
465 if (y != NULL && !group->meth->field_decode(group, y, &point->Y, ctx)) {
468 if (z != NULL && !group->meth->field_decode(group, z, &point->Z, ctx)) {
490 int ec_GFp_simple_point_set_affine_coordinates(const EC_GROUP *group,
500 return ec_point_set_Jprojective_coordinates_GFp(group, point, x, y,
504 int ec_GFp_simple_point_get_affine_coordinates(const EC_GROUP *group,
512 if (EC_POINT_is_at_infinity(group, point)) {
536 if (group->meth->field_decode) {
537 if (!group->meth->field_decode(group, Z, &point->Z, ctx)) {
546 if (group->meth->field_decode) {
547 if (x != NULL && !group->meth->field_decode(group, x, &point->X, ctx)) {
550 if (y != NULL && !group->meth->field_decode(group, y, &point->Y, ctx)) {
562 if (!BN_mod_inverse(Z_1, Z_, &group->field, ctx)) {
568 if (group->meth->field_encode == 0) {
570 if (!group->meth->field_sqr(group, Z_2, Z_1, ctx)) {
573 } else if (!BN_mod_sqr(Z_2, Z_1, &group->field, ctx)) {
579 if (x != NULL && !group->meth->field_mul(group, x, &point->X, Z_2, ctx)) {
584 if (group->meth->field_encode == 0) {
586 if (!group->meth->field_mul(group, Z_3, Z_2, Z_1, ctx)) {
589 } else if (!BN_mod_mul(Z_3, Z_2, Z_1, &group->field, ctx)) {
595 if (!group->meth->field_mul(group, y, &point->Y, Z_3, ctx)) {
609 int ec_GFp_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a,
620 return EC_POINT_dbl(group, r, a, ctx);
622 if (EC_POINT_is_at_infinity(group, a)) {
625 if (EC_POINT_is_at_infinity(group, b)) {
629 field_mul = group->meth->field_mul;
630 field_sqr = group->meth->field_sqr;
631 p = &group->field;
665 if (!field_sqr(group, n0, &b->Z, ctx) ||
666 !field_mul(group, n1, &a->X, n0, ctx)) {
671 if (!field_mul(group, n0, n0, &b->Z, ctx) ||
672 !field_mul(group, n2, &a->Y, n0, ctx)) {
686 if (!field_sqr(group, n0, &a->Z, ctx) ||
687 !field_mul(group, n3, &b->X, n0, ctx)) {
692 if (!field_mul(group, n0, n0, &a->Z, ctx) ||
693 !field_mul(group, n4, &b->Y, n0, ctx)) {
711 ret = EC_POINT_dbl(group, r, a, ctx);
745 } else if (!field_mul(group, n0, &a->Z, &b->Z, ctx)) {
748 if (!field_mul(group, &r->Z, n0, n5, ctx)) {
756 if (!field_sqr(group, n0, n6, ctx) ||
757 !field_sqr(group, n4, n5, ctx) ||
758 !field_mul(group, n3, n1, n4, ctx) ||
772 if (!field_mul(group, n0, n0, n6, ctx) ||
773 !field_mul(group, n5, n4, n5, ctx)) {
776 if (!field_mul(group, n1, n2, n5, ctx) ||
800 int ec_GFp_simple_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a,
810 if (EC_POINT_is_at_infinity(group, a)) {
816 field_mul = group->meth->field_mul;
817 field_sqr = group->meth->field_sqr;
818 p = &group->field;
843 if (!field_sqr(group, n0, &a->X, ctx) ||
846 !BN_mod_add_quick(n1, n0, &group->a, p)) {
850 } else if (group->a_is_minus3) {
851 if (!field_sqr(group, n1, &a->Z, ctx) ||
854 !field_mul(group, n1, n0, n2, ctx) ||
862 if (!field_sqr(group, n0, &a->X, ctx) ||
865 !field_sqr(group, n1, &a->Z, ctx) ||
866 !field_sqr(group, n1, n1, ctx) ||
867 !field_mul(group, n1, n1, &group->a, ctx) ||
879 } else if (!field_mul(group, n0, &a->Y, &a->Z, ctx)) {
889 if (!field_sqr(group, n3, &a->Y, ctx) ||
890 !field_mul(group, n2, &a->X, n3, ctx) ||
898 !field_sqr(group, &r->X, n1, ctx) ||
905 if (!field_sqr(group, n0, n3, ctx) ||
913 !field_mul(group, n0, n1, n0, ctx) ||
927 int ec_GFp_simple_invert(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx) {
928 if (EC_POINT_is_at_infinity(group, point) || BN_is_zero(&point->Y)) {
933 return BN_usub(&point->Y, &group->field, &point->Y);
936 int ec_GFp_simple_is_at_infinity(const EC_GROUP *group, const EC_POINT *point) {
940 int ec_GFp_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point,
950 if (EC_POINT_is_at_infinity(group, point)) {
954 field_mul = group->meth->field_mul;
955 field_sqr = group->meth->field_sqr;
956 p = &group->field;
985 if (!field_sqr(group, rh, &point->X, ctx)) {
990 if (!field_sqr(group, tmp, &point->Z, ctx) ||
991 !field_sqr(group, Z4, tmp, ctx) ||
992 !field_mul(group, Z6, Z4, tmp, ctx)) {
997 if (group->a_is_minus3) {
1001 !field_mul(group, rh, rh, &point->X, ctx)) {
1005 if (!field_mul(group, tmp, Z4, &group->a, ctx) ||
1007 !field_mul(group, rh, rh, &point->X, ctx)) {
1013 if (!field_mul(group, tmp, &group->b, Z6, ctx) ||
1021 if (!BN_mod_add_quick(rh, rh, &group->a, p) ||
1022 !field_mul(group, rh, rh, &point->X, ctx)) {
1026 if (!BN_mod_add_quick(rh, rh, &group->b, p)) {
1032 if (!field_sqr(group, tmp, &point->Y, ctx)) {
1044 int ec_GFp_simple_cmp(const EC_GROUP *group, const EC_POINT *a,
1060 if (EC_POINT_is_at_infinity(group, a)) {
1061 return EC_POINT_is_at_infinity(group, b) ? 0 : 1;
1064 if (EC_POINT_is_at_infinity(group, b)) {
1072 field_mul = group->meth->field_mul;
1073 field_sqr = group->meth->field_sqr;
1098 if (!field_sqr(group, Zb23, &b->Z, ctx) ||
1099 !field_mul(group, tmp1, &a->X, Zb23, ctx)) {
1107 if (!field_sqr(group, Za23, &a->Z, ctx) ||
1108 !field_mul(group, tmp2, &b->X, Za23, ctx)) {
1124 if (!field_mul(group, Zb23, Zb23, &b->Z, ctx) ||
1125 !field_mul(group, tmp1, &a->Y, Zb23, ctx)) {
1133 if (!field_mul(group, Za23, Za23, &a->Z, ctx) ||
1134 !field_mul(group, tmp2, &b->Y, Za23, ctx)) {
1157 int ec_GFp_simple_make_affine(const EC_GROUP *group, EC_POINT *point,
1163 if (point->Z_is_one || EC_POINT_is_at_infinity(group, point)) {
1181 if (!EC_POINT_get_affine_coordinates_GFp(group, point, x, y, ctx) ||
1182 !EC_POINT_set_affine_coordinates_GFp(group, point, x, y, ctx)) {
1198 int ec_GFp_simple_points_make_affine(const EC_GROUP *group, size_t num,
1244 if (group->meth->field_set_to_one != 0) {
1245 if (!group->meth->field_set_to_one(group, prod_Z[0], ctx)) {
1257 if (!group->meth->field_mul(group, prod_Z[i], prod_Z[i - 1],
1271 if (!BN_mod_inverse(tmp, prod_Z[num - 1], &group->field, ctx)) {
1276 if (group->meth->field_encode != NULL) {
1280 if (!group->meth->field_encode(group, tmp, tmp, ctx) ||
1281 !group->meth->field_encode(group, tmp, tmp, ctx)) {
1295 if (!group->meth->field_mul(group, tmp_Z, prod_Z[i - 1], tmp, ctx) ||
1297 !group->meth->field_mul(group, tmp, tmp, &points[i]->Z, ctx) ||
1315 if (!group->meth->field_sqr(group, tmp, &p->Z, ctx) ||
1316 !group->meth->field_mul(group, &p->X, &p->X, tmp, ctx) ||
1317 !group->meth->field_mul(group, tmp, tmp, &p->Z, ctx) ||
1318 !group->meth->field_mul(group, &p->Y, &p->Y, tmp, ctx)) {
1322 if (group->meth->field_set_to_one != NULL) {
1323 if (!group->meth->field_set_to_one(group, &p->Z, ctx)) {
1353 int ec_GFp_simple_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a,
1355 return BN_mod_mul(r, a, b, &group->field, ctx);
1358 int ec_GFp_simple_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a,
1360 return BN_mod_sqr(r, a, &group->field, ctx);