69 #include <openssl/fips.h>
77 return fips_ec_gfp_simple_method();
166 if (!
BN_copy(&dest->
a, &src->
a))
return 0;
167 if (!
BN_copy(&dest->
b, &src->
b))
return 0;
198 if (tmp_a == NULL)
goto err;
205 if (!
BN_nnmod(tmp_a, a, p, ctx))
goto err;
209 if (!
BN_copy(&group->
a, tmp_a))
goto err;
212 if (!
BN_nnmod(&group->
b, b, p, ctx))
goto err;
240 if (a != NULL || b != NULL)
263 if (!
BN_copy(a, &group->
a))
goto err;
267 if (!
BN_copy(b, &group->
b))
goto err;
309 if (order == NULL)
goto err;
318 if (!
BN_copy(a, &group->
a))
goto err;
319 if (!
BN_copy(b, &group->
b))
goto err;
332 if (!
BN_mod_mul(tmp_2, tmp_1, a, p, ctx))
goto err;
333 if (!
BN_lshift(tmp_1, tmp_2, 2))
goto err;
340 if (!
BN_mod_add(a, tmp_1, tmp_2, p, ctx))
goto err;
384 if (!
BN_copy(&dest->
X, &src->
X))
return 0;
385 if (!
BN_copy(&dest->
Y, &src->
Y))
return 0;
386 if (!
BN_copy(&dest->
Z, &src->
Z))
return 0;
493 if (!
BN_copy(x, &point->
X))
goto err;
497 if (!
BN_copy(y, &point->
Y))
goto err;
501 if (!
BN_copy(z, &point->
Z))
goto err;
517 if (x == NULL || y == NULL)
554 if (Z_3 == NULL)
goto err;
585 if (!
BN_copy(x, &point->
X))
goto err;
589 if (!
BN_copy(y, &point->
Y))
goto err;
614 if (!group->
meth->
field_mul(group, x, &point->
X, Z_2, ctx))
goto err;
622 if (!group->
meth->
field_mul(group, Z_3, Z_2, Z_1, ctx))
goto err;
630 if (!group->
meth->
field_mul(group, y, &point->
Y, Z_3, ctx))
goto err;
646 int (*field_sqr)(
const EC_GROUP *, BIGNUM *,
const BIGNUM *,
BN_CTX *);
649 BIGNUM *n0, *n1, *n2, *n3, *n4, *n5, *n6;
678 if (n6 == NULL)
goto end;
695 if (!field_sqr(group, n0, &b->
Z, ctx))
goto end;
696 if (!field_mul(group, n1, &a->
X, n0, ctx))
goto end;
699 if (!field_mul(group, n0, n0, &b->
Z, ctx))
goto end;
700 if (!field_mul(group, n2, &a->
Y, n0, ctx))
goto end;
714 if (!field_sqr(group, n0, &a->
Z, ctx))
goto end;
715 if (!field_mul(group, n3, &b->
X, n0, ctx))
goto end;
718 if (!field_mul(group, n0, n0, &a->
Z, ctx))
goto end;
719 if (!field_mul(group, n4, &b->
Y, n0, ctx))
goto end;
763 {
if (!
BN_copy(n0, &b->
Z))
goto end; }
765 {
if (!
BN_copy(n0, &a->
Z))
goto end; }
767 {
if (!field_mul(group, n0, &a->
Z, &b->
Z, ctx))
goto end; }
768 if (!field_mul(group, &r->
Z, n0, n5, ctx))
goto end;
774 if (!field_sqr(group, n0, n6, ctx))
goto end;
775 if (!field_sqr(group, n4, n5, ctx))
goto end;
776 if (!field_mul(group, n3, n1, n4, ctx))
goto end;
786 if (!field_mul(group, n0, n0, n6, ctx))
goto end;
787 if (!field_mul(group, n5, n4, n5, ctx))
goto end;
788 if (!field_mul(group, n1, n2, n5, ctx))
goto end;
791 if (!
BN_add(n0, n0, p))
goto end;
810 int (*field_sqr)(
const EC_GROUP *, BIGNUM *,
const BIGNUM *,
BN_CTX *);
813 BIGNUM *n0, *n1, *n2, *n3;
839 if (n3 == NULL)
goto err;
849 if (!field_sqr(group, n0, &a->
X, ctx))
goto err;
857 if (!field_sqr(group, n1, &a->
Z, ctx))
goto err;
860 if (!field_mul(group, n1, n0, n2, ctx))
goto err;
868 if (!field_sqr(group, n0, &a->
X, ctx))
goto err;
871 if (!field_sqr(group, n1, &a->
Z, ctx))
goto err;
872 if (!field_sqr(group, n1, n1, ctx))
goto err;
873 if (!field_mul(group, n1, n1, &group->
a, ctx))
goto err;
885 if (!field_mul(group, n0, &a->
Y, &a->
Z, ctx))
goto err;
892 if (!field_sqr(group, n3, &a->
Y, ctx))
goto err;
893 if (!field_mul(group, n2, &a->
X, n3, ctx))
goto err;
899 if (!field_sqr(group, &r->
X, n1, ctx))
goto err;
904 if (!field_sqr(group, n0, n3, ctx))
goto err;
910 if (!field_mul(group, n0, n1, n0, ctx))
goto err;
943 int (*field_sqr)(
const EC_GROUP *, BIGNUM *,
const BIGNUM *,
BN_CTX *);
946 BIGNUM *rh, *tmp, *Z4, *Z6;
968 if (Z6 == NULL)
goto err;
980 if (!field_sqr(group, rh, &point->
X, ctx))
goto err;
984 if (!field_sqr(group, tmp, &point->
Z, ctx))
goto err;
985 if (!field_sqr(group, Z4, tmp, ctx))
goto err;
986 if (!field_mul(group, Z6, Z4, tmp, ctx))
goto err;
994 if (!field_mul(group, rh, rh, &point->
X, ctx))
goto err;
998 if (!field_mul(group, tmp, Z4, &group->
a, ctx))
goto err;
1000 if (!field_mul(group, rh, rh, &point->
X, ctx))
goto err;
1004 if (!field_mul(group, tmp, &group->
b, Z6, ctx))
goto err;
1013 if (!field_mul(group, rh, rh, &point->
X, ctx))
goto err;
1019 if (!field_sqr(group, tmp, &point->
Y, ctx))
goto err;
1021 ret = (0 ==
BN_ucmp(tmp, rh));
1025 if (new_ctx != NULL)
1040 int (*field_sqr)(
const EC_GROUP *, BIGNUM *,
const BIGNUM *,
BN_CTX *);
1042 BIGNUM *tmp1, *tmp2, *Za23, *Zb23;
1043 const BIGNUM *tmp1_, *tmp2_;
1074 if (Zb23 == NULL)
goto end;
1084 if (!field_sqr(group, Zb23, &b->
Z, ctx))
goto end;
1085 if (!field_mul(group, tmp1, &a->
X, Zb23, ctx))
goto end;
1092 if (!field_sqr(group, Za23, &a->
Z, ctx))
goto end;
1093 if (!field_mul(group, tmp2, &b->
X, Za23, ctx))
goto end;
1100 if (
BN_cmp(tmp1_, tmp2_) != 0)
1109 if (!field_mul(group, Zb23, Zb23, &b->
Z, ctx))
goto end;
1110 if (!field_mul(group, tmp1, &a->
Y, Zb23, ctx))
goto end;
1117 if (!field_mul(group, Za23, Za23, &a->
Z, ctx))
goto end;
1118 if (!field_mul(group, tmp2, &b->
Y, Za23, ctx))
goto end;
1125 if (
BN_cmp(tmp1_, tmp2_) != 0)
1136 if (new_ctx != NULL)
1161 if (y == NULL)
goto err;
1175 if (new_ctx != NULL)
1203 if (tmp0 == NULL || tmp1 == NULL)
goto err;
1218 if (heap == NULL)
goto err;
1235 for (i = pow2/2 - 1; i > 0; i--)
1237 for (i = 0; i <
num; i++)
1238 heap[pow2/2 + i] = &points[i]->
Z;
1239 for (i = pow2/2 + num; i < pow2; i++)
1243 for (i = pow2/2 - 1; i > 0; i--)
1246 if (heap[i] == NULL)
goto err;
1248 if (heap[2*i] != NULL)
1250 if ((heap[2*i + 1] == NULL) ||
BN_is_zero(heap[2*i + 1]))
1252 if (!
BN_copy(heap[i], heap[2*i]))
goto err;
1258 if (!
BN_copy(heap[i], heap[2*i + 1]))
goto err;
1263 heap[2*i], heap[2*i + 1], ctx))
goto err;
1288 for (i = 2; i < pow2/2 +
num; i += 2)
1291 if ((heap[i + 1] != NULL) && !
BN_is_zero(heap[i + 1]))
1293 if (!group->
meth->
field_mul(group, tmp0, heap[i/2], heap[i + 1], ctx))
goto err;
1294 if (!group->
meth->
field_mul(group, tmp1, heap[i/2], heap[i], ctx))
goto err;
1295 if (!
BN_copy(heap[i], tmp0))
goto err;
1296 if (!
BN_copy(heap[i + 1], tmp1))
goto err;
1300 if (!
BN_copy(heap[i], heap[i/2]))
goto err;
1305 for (i = 0; i <
num; i++)
1314 if (!group->
meth->
field_mul(group, &p->
X, &p->
X, tmp1, ctx))
goto err;
1316 if (!group->
meth->
field_mul(group, tmp1, tmp1, &p->
Z, ctx))
goto err;
1317 if (!group->
meth->
field_mul(group, &p->
Y, &p->
Y, tmp1, ctx))
goto err;
1335 if (new_ctx != NULL)
1340 for (i = pow2/2 - 1; i > 0; i--)
1342 if (heap[i] != NULL)