Lines Matching refs:group

139 int ec_GFp_simple_group_init(EC_GROUP *group)
141 BN_init(&group->field);
142 BN_init(&group->a);
143 BN_init(&group->b);
144 group->a_is_minus3 = 0;
148 void ec_GFp_simple_group_finish(EC_GROUP *group)
150 BN_free(&group->field);
151 BN_free(&group->a);
152 BN_free(&group->b);
155 void ec_GFp_simple_group_clear_finish(EC_GROUP *group)
157 BN_clear_free(&group->field);
158 BN_clear_free(&group->a);
159 BN_clear_free(&group->b);
176 int ec_GFp_simple_group_set_curve(EC_GROUP *group,
201 /* group->field */
202 if (!BN_copy(&group->field, p))
204 BN_set_negative(&group->field, 0);
206 /* group->a */
209 if (group->meth->field_encode) {
210 if (!group->meth->field_encode(group, &group->a, tmp_a, ctx))
212 } else if (!BN_copy(&group->a, tmp_a))
215 /* group->b */
216 if (!BN_nnmod(&group->b, b, p, ctx))
218 if (group->meth->field_encode)
219 if (!group->meth->field_encode(group, &group->b, &group->b, ctx))
222 /* group->a_is_minus3 */
225 group->a_is_minus3 = (0 == BN_cmp(tmp_a, &group->field));
236 int ec_GFp_simple_group_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a,
243 if (!BN_copy(p, &group->field))
248 if (group->meth->field_decode) {
255 if (!group->meth->field_decode(group, a, &group->a, ctx))
259 if (!group->meth->field_decode(group, b, &group->b, ctx))
264 if (!BN_copy(a, &group->a))
268 if (!BN_copy(b, &group->b))
282 int ec_GFp_simple_group_get_degree(const EC_GROUP *group)
284 return BN_num_bits(&group->field);
287 int ec_GFp_simple_group_check_discriminant(const EC_GROUP *group, BN_CTX *ctx)
291 const BIGNUM *p = &group->field;
311 if (group->meth->field_decode) {
312 if (!group->meth->field_decode(group, a, &group->a, ctx))
314 if (!group->meth->field_decode(group, b, &group->b, ctx))
317 if (!BN_copy(a, &group->a))
319 if (!BN_copy(b, &group->b))
399 int ec_GFp_simple_point_set_to_infinity(const EC_GROUP *group,
407 int ec_GFp_simple_set_Jprojective_coordinates_GFp(const EC_GROUP *group,
424 if (!BN_nnmod(&point->X, x, &group->field, ctx))
426 if (group->meth->field_encode) {
427 if (!group->meth->field_encode(group, &point->X, &point->X, ctx))
433 if (!BN_nnmod(&point->Y, y, &group->field, ctx))
435 if (group->meth->field_encode) {
436 if (!group->meth->field_encode(group, &point->Y, &point->Y, ctx))
444 if (!BN_nnmod(&point->Z, z, &group->field, ctx))
447 if (group->meth->field_encode) {
448 if (Z_is_one && (group->meth->field_set_to_one != 0)) {
449 if (!group->meth->field_set_to_one(group, &point->Z, ctx))
452 if (!group->
453 meth->field_encode(group, &point->Z, &point->Z, ctx))
468 int ec_GFp_simple_get_Jprojective_coordinates_GFp(const EC_GROUP *group,
476 if (group->meth->field_decode != 0) {
484 if (!group->meth->field_decode(group, x, &point->X, ctx))
488 if (!group->meth->field_decode(group, y, &point->Y, ctx))
492 if (!group->meth->field_decode(group, z, &point->Z, ctx))
518 int ec_GFp_simple_point_set_affine_coordinates(const EC_GROUP *group,
532 return EC_POINT_set_Jprojective_coordinates_GFp(group, point, x, y,
536 int ec_GFp_simple_point_get_affine_coordinates(const EC_GROUP *group,
546 if (EC_POINT_is_at_infinity(group, point)) {
568 if (group->meth->field_decode) {
569 if (!group->meth->field_decode(group, Z, &point->Z, ctx))
577 if (group->meth->field_decode) {
579 if (!group->meth->field_decode(group, x, &point->X, ctx))
583 if (!group->meth->field_decode(group, y, &point->Y, ctx))
597 if (!BN_mod_inverse(Z_1, Z_, &group->field, ctx)) {
603 if (group->meth->field_encode == 0) {
605 if (!group->meth->field_sqr(group, Z_2, Z_1, ctx))
608 if (!BN_mod_sqr(Z_2, Z_1, &group->field, ctx))
617 if (!group->meth->field_mul(group, x, &point->X, Z_2, ctx))
622 if (group->meth->field_encode == 0) {
626 if (!group->meth->field_mul(group, Z_3, Z_2, Z_1, ctx))
629 if (!BN_mod_mul(Z_3, Z_2, Z_1, &group->field, ctx))
637 if (!group->meth->field_mul(group, y, &point->Y, Z_3, ctx))
651 int ec_GFp_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a,
663 return EC_POINT_dbl(group, r, a, ctx);
664 if (EC_POINT_is_at_infinity(group, a))
666 if (EC_POINT_is_at_infinity(group, b))
669 field_mul = group->meth->field_mul;
670 field_sqr = group->meth->field_sqr;
671 p = &group->field;
705 if (!field_sqr(group, n0, &b->Z, ctx))
707 if (!field_mul(group, n1, &a->X, n0, ctx))
711 if (!field_mul(group, n0, n0, &b->Z, ctx))
713 if (!field_mul(group, n2, &a->Y, n0, ctx))
727 if (!field_sqr(group, n0, &a->Z, ctx))
729 if (!field_mul(group, n3, &b->X, n0, ctx))
733 if (!field_mul(group, n0, n0, &a->Z, ctx))
735 if (!field_mul(group, n4, &b->Y, n0, ctx))
752 ret = EC_POINT_dbl(group, r, a, ctx);
784 if (!field_mul(group, n0, &a->Z, &b->Z, ctx))
787 if (!field_mul(group, &r->Z, n0, n5, ctx))
794 if (!field_sqr(group, n0, n6, ctx))
796 if (!field_sqr(group, n4, n5, ctx))
798 if (!field_mul(group, n3, n1, n4, ctx))
812 if (!field_mul(group, n0, n0, n6, ctx))
814 if (!field_mul(group, n5, n4, n5, ctx))
816 if (!field_mul(group, n1, n2, n5, ctx))
838 int ec_GFp_simple_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a,
849 if (EC_POINT_is_at_infinity(group, a)) {
855 field_mul = group->meth->field_mul;
856 field_sqr = group->meth->field_sqr;
857 p = &group->field;
881 if (!field_sqr(group, n0, &a->X, ctx))
887 if (!BN_mod_add_quick(n1, n0, &group->a, p))
890 } else if (group->a_is_minus3) {
891 if (!field_sqr(group, n1, &a->Z, ctx))
897 if (!field_mul(group, n1, n0, n2, ctx))
908 if (!field_sqr(group, n0, &a->X, ctx))
914 if (!field_sqr(group, n1, &a->Z, ctx))
916 if (!field_sqr(group, n1, n1, ctx))
918 if (!field_mul(group, n1, n1, &group->a, ctx))
930 if (!field_mul(group, n0, &a->Y, &a->Z, ctx))
939 if (!field_sqr(group, n3, &a->Y, ctx))
941 if (!field_mul(group, n2, &a->X, n3, ctx))
950 if (!field_sqr(group, &r->X, n1, ctx))
957 if (!field_sqr(group, n0, n3, ctx))
966 if (!field_mul(group, n0, n1, n0, ctx))
981 int ec_GFp_simple_invert(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx)
983 if (EC_POINT_is_at_infinity(group, point) || BN_is_zero(&point->Y))
987 return BN_usub(&point->Y, &group->field, &point->Y);
990 int ec_GFp_simple_is_at_infinity(const EC_GROUP *group, const EC_POINT *point)
995 int ec_GFp_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point,
1006 if (EC_POINT_is_at_infinity(group, point))
1009 field_mul = group->meth->field_mul;
1010 field_sqr = group->meth->field_sqr;
1011 p = &group->field;
1038 if (!field_sqr(group, rh, &point->X, ctx))
1042 if (!field_sqr(group, tmp, &point->Z, ctx))
1044 if (!field_sqr(group, Z4, tmp, ctx))
1046 if (!field_mul(group, Z6, Z4, tmp, ctx))
1050 if (group->a_is_minus3) {
1057 if (!field_mul(group, rh, rh, &point->X, ctx))
1060 if (!field_mul(group, tmp, Z4, &group->a, ctx))
1064 if (!field_mul(group, rh, rh, &point->X, ctx))
1069 if (!field_mul(group, tmp, &group->b, Z6, ctx))
1077 if (!BN_mod_add_quick(rh, rh, &group->a, p))
1079 if (!field_mul(group, rh, rh, &point->X, ctx))
1082 if (!BN_mod_add_quick(rh, rh, &group->b, p))
1087 if (!field_sqr(group, tmp, &point->Y, ctx))
1099 int ec_GFp_simple_cmp(const EC_GROUP *group, const EC_POINT *a,
1117 if (EC_POINT_is_at_infinity(group, a)) {
1118 return EC_POINT_is_at_infinity(group, b) ? 0 : 1;
1121 if (EC_POINT_is_at_infinity(group, b))
1129 field_mul = group->meth->field_mul;
1130 field_sqr = group->meth->field_sqr;
1154 if (!field_sqr(group, Zb23, &b->Z, ctx))
1156 if (!field_mul(group, tmp1, &a->X, Zb23, ctx))
1162 if (!field_sqr(group, Za23, &a->Z, ctx))
1164 if (!field_mul(group, tmp2, &b->X, Za23, ctx))
1177 if (!field_mul(group, Zb23, Zb23, &b->Z, ctx))
1179 if (!field_mul(group, tmp1, &a->Y, Zb23, ctx))
1185 if (!field_mul(group, Za23, Za23, &a->Z, ctx))
1187 if (!field_mul(group, tmp2, &b->Y, Za23, ctx))
1209 int ec_GFp_simple_make_affine(const EC_GROUP *group, EC_POINT *point,
1216 if (point->Z_is_one || EC_POINT_is_at_infinity(group, point))
1231 if (!EC_POINT_get_affine_coordinates_GFp(group, point, x, y, ctx))
1233 if (!EC_POINT_set_affine_coordinates_GFp(group, point, x, y, ctx))
1249 int ec_GFp_simple_points_make_affine(const EC_GROUP *group, size_t num,
1291 if (group->meth->field_set_to_one != 0) {
1292 if (!group->meth->field_set_to_one(group, prod_Z[0], ctx))
1302 if (!group->meth->field_mul(group, prod_Z[i], prod_Z[i - 1],
1316 if (!BN_mod_inverse(tmp, prod_Z[num - 1], &group->field, ctx)) {
1320 if (group->meth->field_encode != 0) {
1326 if (!group->meth->field_encode(group, tmp, tmp, ctx))
1328 if (!group->meth->field_encode(group, tmp, tmp, ctx))
1342 if (!group->
1343 meth->field_mul(group, tmp_Z, prod_Z[i - 1], tmp, ctx))
1348 if (!group->meth->field_mul(group, tmp, tmp, &points[i]->Z, ctx))
1370 if (!group->meth->field_sqr(group, tmp, &p->Z, ctx))
1372 if (!group->meth->field_mul(group, &p->X, &p->X, tmp, ctx))
1375 if (!group->meth->field_mul(group, tmp, tmp, &p->Z, ctx))
1377 if (!group->meth->field_mul(group, &p->Y, &p->Y, tmp, ctx))
1380 if (group->meth->field_set_to_one != 0) {
1381 if (!group->meth->field_set_to_one(group, &p->Z, ctx))
1408 int ec_GFp_simple_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a,
1411 return BN_mod_mul(r, a, b, &group->field, ctx);
1414 int ec_GFp_simple_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a,
1417 return BN_mod_sqr(r, a, &group->field, ctx);