-int ec_GF2m_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx)
- {
- BN_CTX *new_ctx = NULL;
- BIGNUM *x0, *y0, *x1, *y1, *x2, *y2, *s, *t;
- int ret = 0;
-
- if (EC_POINT_is_at_infinity(group, a))
- {
- if (!EC_POINT_copy(r, b)) return 0;
- return 1;
- }
-
- if (EC_POINT_is_at_infinity(group, b))
- {
- if (!EC_POINT_copy(r, a)) return 0;
- return 1;
- }
-
- if (ctx == NULL)
- {
- ctx = new_ctx = BN_CTX_new();
- if (ctx == NULL)
- return 0;
- }
-
- BN_CTX_start(ctx);
- x0 = BN_CTX_get(ctx);
- y0 = BN_CTX_get(ctx);
- x1 = BN_CTX_get(ctx);
- y1 = BN_CTX_get(ctx);
- x2 = BN_CTX_get(ctx);
- y2 = BN_CTX_get(ctx);
- s = BN_CTX_get(ctx);
- t = BN_CTX_get(ctx);
- if (t == NULL) goto err;
-
- if (a->Z_is_one)
- {
- if (!BN_copy(x0, &a->X)) goto err;
- if (!BN_copy(y0, &a->Y)) goto err;
- }
- else
- {
- if (!EC_POINT_get_affine_coordinates_GF2m(group, a, x0, y0, ctx)) goto err;
- }
- if (b->Z_is_one)
- {
- if (!BN_copy(x1, &b->X)) goto err;
- if (!BN_copy(y1, &b->Y)) goto err;
- }
- else
- {
- if (!EC_POINT_get_affine_coordinates_GF2m(group, b, x1, y1, ctx)) goto err;
- }
-
-
- if (BN_GF2m_cmp(x0, x1))
- {
- if (!BN_GF2m_add(t, x0, x1)) goto err;
- if (!BN_GF2m_add(s, y0, y1)) goto err;
- if (!group->meth->field_div(group, s, s, t, ctx)) goto err;
- if (!group->meth->field_sqr(group, x2, s, ctx)) goto err;
- if (!BN_GF2m_add(x2, x2, &group->a)) goto err;
- if (!BN_GF2m_add(x2, x2, s)) goto err;
- if (!BN_GF2m_add(x2, x2, t)) goto err;
- }
- else
- {
- if (BN_GF2m_cmp(y0, y1) || BN_is_zero(x1))
- {
- if (!EC_POINT_set_to_infinity(group, r)) goto err;
- ret = 1;
- goto err;
- }
- if (!group->meth->field_div(group, s, y1, x1, ctx)) goto err;
- if (!BN_GF2m_add(s, s, x1)) goto err;
-
- if (!group->meth->field_sqr(group, x2, s, ctx)) goto err;
- if (!BN_GF2m_add(x2, x2, s)) goto err;
- if (!BN_GF2m_add(x2, x2, &group->a)) goto err;
- }
-
- if (!BN_GF2m_add(y2, x1, x2)) goto err;
- if (!group->meth->field_mul(group, y2, y2, s, ctx)) goto err;
- if (!BN_GF2m_add(y2, y2, x2)) goto err;
- if (!BN_GF2m_add(y2, y2, y1)) goto err;
-
- if (!EC_POINT_set_affine_coordinates_GF2m(group, r, x2, y2, ctx)) goto err;
-
- ret = 1;
+int ec_GF2m_simple_point_get_affine_coordinates(const EC_GROUP *group,
+ const EC_POINT *point,
+ BIGNUM *x, BIGNUM *y,
+ BN_CTX *ctx)
+{
+ int ret = 0;
+
+ if (EC_POINT_is_at_infinity(group, point)) {
+ ECerr(EC_F_EC_GF2M_SIMPLE_POINT_GET_AFFINE_COORDINATES,
+ EC_R_POINT_AT_INFINITY);
+ return 0;
+ }
+
+ if (BN_cmp(point->Z, BN_value_one())) {
+ ECerr(EC_F_EC_GF2M_SIMPLE_POINT_GET_AFFINE_COORDINATES,
+ ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
+ return 0;
+ }
+ if (x != NULL) {
+ if (!BN_copy(x, point->X))
+ goto err;
+ BN_set_negative(x, 0);
+ }
+ if (y != NULL) {
+ if (!BN_copy(y, point->Y))
+ goto err;
+ BN_set_negative(y, 0);
+ }
+ ret = 1;