Lines Matching defs:group

138 int ec_GFp_simple_group_init(EC_GROUP *group)
140 BN_init(&group->field);
141 BN_init(&group->a);
142 BN_init(&group->b);
143 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);
156 void ec_GFp_simple_group_clear_finish(EC_GROUP *group)
158 BN_clear_free(&group->field);
159 BN_clear_free(&group->a);
160 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)) goto err;
203 BN_set_negative(&group->field, 0);
205 /* group->a */
207 if (group->meth->field_encode)
208 { if (!group->meth->field_encode(group, &group->a, tmp_a, ctx)) goto err; }
210 if (!BN_copy(&group->a, tmp_a)) goto err;
212 /* group->b */
213 if (!BN_nnmod(&group->b, b, p, ctx)) goto err;
214 if (group->meth->field_encode)
215 if (!group->meth->field_encode(group, &group->b, &group->b, ctx)) goto err;
217 /* group->a_is_minus3 */
219 group->a_is_minus3 = (0 == BN_cmp(tmp_a, &group->field));
231 int ec_GFp_simple_group_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)
238 if (!BN_copy(p, &group->field)) return 0;
243 if (group->meth->field_decode)
253 if (!group->meth->field_decode(group, a, &group->a, ctx)) goto err;
257 if (!group->meth->field_decode(group, b, &group->b, ctx)) goto err;
264 if (!BN_copy(a, &group->a)) goto err;
268 if (!BN_copy(b, &group->b)) goto err;
282 int ec_GFp_simple_group_get_degree(const EC_GROUP *group)
284 return BN_num_bits(&group->field);
288 int ec_GFp_simple_group_check_discriminant(const EC_GROUP *group, BN_CTX *ctx)
292 const BIGNUM *p = &group->field;
312 if (group->meth->field_decode)
314 if (!group->meth->field_decode(group, a, &group->a, ctx)) goto err;
315 if (!group->meth->field_decode(group, b, &group->b, ctx)) goto err;
319 if (!BN_copy(a, &group->a)) goto err;
320 if (!BN_copy(b, &group->b)) goto err;
394 int ec_GFp_simple_point_set_to_infinity(const EC_GROUP *group, EC_POINT *point)
402 int ec_GFp_simple_set_Jprojective_coordinates_GFp(const EC_GROUP *group, EC_POINT *point,
417 if (!BN_nnmod(&point->X, x, &group->field, ctx)) goto err;
418 if (group->meth->field_encode)
420 if (!group->meth->field_encode(group, &point->X, &point->X, ctx)) goto err;
426 if (!BN_nnmod(&point->Y, y, &group->field, ctx)) goto err;
427 if (group->meth->field_encode)
429 if (!group->meth->field_encode(group, &point->Y, &point->Y, ctx)) goto err;
437 if (!BN_nnmod(&point->Z, z, &group->field, ctx)) goto err;
439 if (group->meth->field_encode)
441 if (Z_is_one && (group->meth->field_set_to_one != 0))
443 if (!group->meth->field_set_to_one(group, &point->Z, ctx)) goto err;
447 if (!group->meth->field_encode(group, &point->Z, &point->Z, ctx)) goto err;
462 int ec_GFp_simple_get_Jprojective_coordinates_GFp(const EC_GROUP *group, const EC_POINT *point,
468 if (group->meth->field_decode != 0)
479 if (!group->meth->field_decode(group, x, &point->X, ctx)) goto err;
483 if (!group->meth->field_decode(group, y, &point->Y, ctx)) goto err;
487 if (!group->meth->field_decode(group, z, &point->Z, ctx)) goto err;
515 int ec_GFp_simple_point_set_affine_coordinates(const EC_GROUP *group, EC_POINT *point,
525 return EC_POINT_set_Jprojective_coordinates_GFp(group, point, x, y, BN_value_one(), ctx);
529 int ec_GFp_simple_point_get_affine_coordinates(const EC_GROUP *group, const EC_POINT *point,
537 if (EC_POINT_is_at_infinity(group, point))
559 if (group->meth->field_decode)
561 if (!group->meth->field_decode(group, Z, &point->Z, ctx)) goto err;
571 if (group->meth->field_decode)
575 if (!group->meth->field_decode(group, x, &point->X, ctx)) goto err;
579 if (!group->meth->field_decode(group, y, &point->Y, ctx)) goto err;
596 if (!BN_mod_inverse(Z_1, Z_, &group->field, ctx))
602 if (group->meth->field_encode == 0)
605 if (!group->meth->field_sqr(group, Z_2, Z_1, ctx)) goto err;
609 if (!BN_mod_sqr(Z_2, Z_1, &group->field, ctx)) goto err;
615 if (!group->meth->field_mul(group, x, &point->X, Z_2, ctx)) goto err;
620 if (group->meth->field_encode == 0)
623 if (!group->meth->field_mul(group, Z_3, Z_2, Z_1, ctx)) goto err;
627 if (!BN_mod_mul(Z_3, Z_2, Z_1, &group->field, ctx)) goto err;
631 if (!group->meth->field_mul(group, y, &point->Y, Z_3, ctx)) goto err;
644 int ec_GFp_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx)
654 return EC_POINT_dbl(group, r, a, ctx);
655 if (EC_POINT_is_at_infinity(group, a))
657 if (EC_POINT_is_at_infinity(group, b))
660 field_mul = group->meth->field_mul;
661 field_sqr = group->meth->field_sqr;
662 p = &group->field;
696 if (!field_sqr(group, n0, &b->Z, ctx)) goto end;
697 if (!field_mul(group, n1, &a->X, n0, ctx)) goto end;
700 if (!field_mul(group, n0, n0, &b->Z, ctx)) goto end;
701 if (!field_mul(group, n2, &a->Y, n0, ctx)) goto end;
715 if (!field_sqr(group, n0, &a->Z, ctx)) goto end;
716 if (!field_mul(group, n3, &b->X, n0, ctx)) goto end;
719 if (!field_mul(group, n0, n0, &a->Z, ctx)) goto end;
720 if (!field_mul(group, n4, &b->Y, n0, ctx)) goto end;
736 ret = EC_POINT_dbl(group, r, a, ctx);
768 { if (!field_mul(group, n0, &a->Z, &b->Z, ctx)) goto end; }
769 if (!field_mul(group, &r->Z, n0, n5, ctx)) goto end;
775 if (!field_sqr(group, n0, n6, ctx)) goto end;
776 if (!field_sqr(group, n4, n5, ctx)) goto end;
777 if (!field_mul(group, n3, n1, n4, ctx)) goto end;
787 if (!field_mul(group, n0, n0, n6, ctx)) goto end;
788 if (!field_mul(group, n5, n4, n5, ctx)) goto end; /* now n5 is n5^3 */
789 if (!field_mul(group, n1, n2, n5, ctx)) goto end;
808 int ec_GFp_simple_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, BN_CTX *ctx)
817 if (EC_POINT_is_at_infinity(group, a))
824 field_mul = group->meth->field_mul;
825 field_sqr = group->meth->field_sqr;
826 p = &group->field;
850 if (!field_sqr(group, n0, &a->X, ctx)) goto err;
853 if (!BN_mod_add_quick(n1, n0, &group->a, p)) goto err;
856 else if (group->a_is_minus3)
858 if (!field_sqr(group, n1, &a->Z, ctx)) goto err;
861 if (!field_mul(group, n1, n0, n2, ctx)) goto err;
869 if (!field_sqr(group, n0, &a->X, ctx)) goto err;
872 if (!field_sqr(group, n1, &a->Z, ctx)) goto err;
873 if (!field_sqr(group, n1, n1, ctx)) goto err;
874 if (!field_mul(group, n1, n1, &group->a, ctx)) goto err;
886 if (!field_mul(group, n0, &a->Y, &a->Z, ctx)) goto err;
893 if (!field_sqr(group, n3, &a->Y, ctx)) goto err;
894 if (!field_mul(group, n2, &a->X, n3, ctx)) goto err;
900 if (!field_sqr(group, &r->X, n1, ctx)) goto err;
905 if (!field_sqr(group, n0, n3, ctx)) goto err;
911 if (!field_mul(group, n0, n1, n0, ctx)) goto err;
925 int ec_GFp_simple_invert(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx)
927 if (EC_POINT_is_at_infinity(group, point) || BN_is_zero(&point->Y))
931 return BN_usub(&point->Y, &group->field, &point->Y);
935 int ec_GFp_simple_is_at_infinity(const EC_GROUP *group, const EC_POINT *point)
941 int ec_GFp_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX *ctx)
950 if (EC_POINT_is_at_infinity(group, point))
953 field_mul = group->meth->field_mul;
954 field_sqr = group->meth->field_sqr;
955 p = &group->field;
981 if (!field_sqr(group, rh, &point->X, ctx)) goto err;
985 if (!field_sqr(group, tmp, &point->Z, ctx)) goto err;
986 if (!field_sqr(group, Z4, tmp, ctx)) goto err;
987 if (!field_mul(group, Z6, Z4, tmp, ctx)) goto err;
990 if (group->a_is_minus3)
995 if (!field_mul(group, rh, rh, &point->X, ctx)) goto err;
999 if (!field_mul(group, tmp, Z4, &group->a, ctx)) goto err;
1001 if (!field_mul(group, rh, rh, &point->X, ctx)) goto err;
1005 if (!field_mul(group, tmp, &group->b, Z6, ctx)) goto err;
1013 if (!BN_mod_add_quick(rh, rh, &group->a, p)) goto err;
1014 if (!field_mul(group, rh, rh, &point->X, ctx)) goto err;
1016 if (!BN_mod_add_quick(rh, rh, &group->b, p)) goto err;
1020 if (!field_sqr(group, tmp, &point->Y, ctx)) goto err;
1032 int ec_GFp_simple_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx)
1047 if (EC_POINT_is_at_infinity(group, a))
1049 return EC_POINT_is_at_infinity(group, b) ? 0 : 1;
1052 if (EC_POINT_is_at_infinity(group, b))
1060 field_mul = group->meth->field_mul;
1061 field_sqr = group->meth->field_sqr;
1085 if (!field_sqr(group, Zb23, &b->Z, ctx)) goto end;
1086 if (!field_mul(group, tmp1, &a->X, Zb23, ctx)) goto end;
1093 if (!field_sqr(group, Za23, &a->Z, ctx)) goto end;
1094 if (!field_mul(group, tmp2, &b->X, Za23, ctx)) goto end;
1110 if (!field_mul(group, Zb23, Zb23, &b->Z, ctx)) goto end;
1111 if (!field_mul(group, tmp1, &a->Y, Zb23, ctx)) goto end;
1118 if (!field_mul(group, Za23, Za23, &a->Z, ctx)) goto end;
1119 if (!field_mul(group, tmp2, &b->Y, Za23, ctx)) goto end;
1143 int ec_GFp_simple_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx)
1149 if (point->Z_is_one || EC_POINT_is_at_infinity(group, point))
1164 if (!EC_POINT_get_affine_coordinates_GFp(group, point, x, y, ctx)) goto err;
1165 if (!EC_POINT_set_affine_coordinates_GFp(group, point, x, y, ctx)) goto err;
1182 int ec_GFp_simple_points_make_affine(const EC_GROUP *group, size_t num, EC_POINT *points[], BN_CTX *ctx)
1222 if (group->meth->field_set_to_one != 0)
1224 if (!group->meth->field_set_to_one(group, prod_Z[0], ctx)) goto err;
1236 if (!group->meth->field_mul(group, prod_Z[i], prod_Z[i - 1], &points[i]->Z, ctx)) goto err;
1247 if (!BN_mod_inverse(tmp, prod_Z[num - 1], &group->field, ctx))
1252 if (group->meth->field_encode != 0)
1257 if (!group->meth->field_encode(group, tmp, tmp, ctx)) goto err;
1258 if (!group->meth->field_encode(group, tmp, tmp, ctx)) goto err;
1269 if (!group->meth->field_mul(group, tmp_Z, prod_Z[i - 1], tmp, ctx)) goto err;
1271 if (!group->meth->field_mul(group, tmp, tmp, &points[i]->Z, ctx)) goto err;
1293 if (!group->meth->field_sqr(group, tmp, &p->Z, ctx)) goto err;
1294 if (!group->meth->field_mul(group, &p->X, &p->X, tmp, ctx)) goto err;
1296 if (!group->meth->field_mul(group, tmp, tmp, &p->Z, ctx)) goto err;
1297 if (!group->meth->field_mul(group, &p->Y, &p->Y, tmp, ctx)) goto err;
1299 if (group->meth->field_set_to_one != 0)
1301 if (!group->meth->field_set_to_one(group, &p->Z, ctx)) goto err;
1330 int ec_GFp_simple_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
1332 return BN_mod_mul(r, a, b, &group->field, ctx);
1336 int ec_GFp_simple_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
1338 return BN_mod_sqr(r, a, &group->field, ctx);