Lines Matching full:ctx
176 const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
189 if (ctx == NULL)
191 ctx = new_ctx = BN_CTX_new();
192 if (ctx == NULL)
196 BN_CTX_start(ctx);
197 tmp_a = BN_CTX_get(ctx);
205 if (!BN_nnmod(tmp_a, a, p, ctx)) goto err;
207 { if (!group->meth->field_encode(group, &group->a, tmp_a, ctx)) goto err; }
212 if (!BN_nnmod(&group->b, b, p, ctx)) goto err;
214 if (!group->meth->field_encode(group, &group->b, &group->b, ctx)) goto err;
223 BN_CTX_end(ctx);
230 int ec_GFp_simple_group_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)
244 if (ctx == NULL)
246 ctx = new_ctx = BN_CTX_new();
247 if (ctx == NULL)
252 if (!group->meth->field_decode(group, a, &group->a, ctx)) goto err;
256 if (!group->meth->field_decode(group, b, &group->b, ctx)) goto err;
287 int ec_GFp_simple_group_check_discriminant(const EC_GROUP *group, BN_CTX *ctx)
294 if (ctx == NULL)
296 ctx = new_ctx = BN_CTX_new();
297 if (ctx == NULL)
303 BN_CTX_start(ctx);
304 a = BN_CTX_get(ctx);
305 b = BN_CTX_get(ctx);
306 tmp_1 = BN_CTX_get(ctx);
307 tmp_2 = BN_CTX_get(ctx);
308 order = BN_CTX_get(ctx);
313 if (!group->meth->field_decode(group, a, &group->a, ctx)) goto err;
314 if (!group->meth->field_decode(group, b, &group->b, ctx)) goto err;
331 if (!BN_mod_sqr(tmp_1, a, p, ctx)) goto err;
332 if (!BN_mod_mul(tmp_2, tmp_1, a, p, ctx)) goto err;
336 if (!BN_mod_sqr(tmp_2, b, p, ctx)) goto err;
340 if (!BN_mod_add(a, tmp_1, tmp_2, p, ctx)) goto err;
346 if (ctx != NULL)
347 BN_CTX_end(ctx);
402 const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *ctx)
407 if (ctx == NULL)
409 ctx = new_ctx = BN_CTX_new();
410 if (ctx == NULL)
416 if (!BN_nnmod(&point->X, x, &group->field, ctx)) goto err;
419 if (!group->meth->field_encode(group, &point->X, &point->X, ctx)) goto err;
425 if (!BN_nnmod(&point->Y, y, &group->field, ctx)) goto err;
428 if (!group->meth->field_encode(group, &point->Y, &point->Y, ctx)) goto err;
436 if (!BN_nnmod(&point->Z, z, &group->field, ctx)) goto err;
442 if (!group->meth->field_set_to_one(group, &point->Z, ctx)) goto err;
446 if (!group->meth->field_encode(group, &point->Z, &point->Z, ctx)) goto err;
462 BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *ctx)
469 if (ctx == NULL)
471 ctx = new_ctx = BN_CTX_new();
472 if (ctx == NULL)
478 if (!group->meth->field_decode(group, x, &point->X, ctx)) goto err;
482 if (!group->meth->field_decode(group, y, &point->Y, ctx)) goto err;
486 if (!group->meth->field_decode(group, z, &point->Z, ctx)) goto err;
515 const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx)
524 return EC_POINT_set_Jprojective_coordinates_GFp(group, point, x, y, BN_value_one(), ctx);
529 BIGNUM *x, BIGNUM *y, BN_CTX *ctx)
542 if (ctx == NULL)
544 ctx = new_ctx = BN_CTX_new();
545 if (ctx == NULL)
549 BN_CTX_start(ctx);
550 Z = BN_CTX_get(ctx);
551 Z_1 = BN_CTX_get(ctx);
552 Z_2 = BN_CTX_get(ctx);
553 Z_3 = BN_CTX_get(ctx);
560 if (!group->meth->field_decode(group, Z, &point->Z, ctx)) goto err;
574 if (!group->meth->field_decode(group, x, &point->X, ctx)) goto err;
578 if (!group->meth->field_decode(group, y, &point->Y, ctx)) goto err;
595 if (!BN_mod_inverse(Z_1, Z_, &group->field, ctx))
604 if (!group->meth->field_sqr(group, Z_2, Z_1, ctx)) goto err;
608 if (!BN_mod_sqr(Z_2, Z_1, &group->field, ctx)) 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;
626 if (!BN_mod_mul(Z_3, Z_2, Z_1, &group->field, ctx)) goto err;
630 if (!group->meth->field_mul(group, y, &point->Y, Z_3, ctx)) goto err;
637 BN_CTX_end(ctx);
643 int ec_GFp_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx)
653 return EC_POINT_dbl(group, r, a, ctx);
663 if (ctx == NULL)
665 ctx = new_ctx = BN_CTX_new();
666 if (ctx == NULL)
670 BN_CTX_start(ctx);
671 n0 = BN_CTX_get(ctx);
672 n1 = BN_CTX_get(ctx);
673 n2 = BN_CTX_get(ctx);
674 n3 = BN_CTX_get(ctx);
675 n4 = BN_CTX_get(ctx);
676 n5 = BN_CTX_get(ctx);
677 n6 = BN_CTX_get(ctx);
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;
734 BN_CTX_end(ctx);
735 ret = EC_POINT_dbl(group, r, a, ctx);
736 ctx = NULL;
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; /* now n5 is n5^3 */
788 if (!field_mul(group, n1, n2, n5, ctx)) goto end;
799 if (ctx) /* otherwise we already called BN_CTX_end */
800 BN_CTX_end(ctx);
807 int ec_GFp_simple_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, BN_CTX *ctx)
827 if (ctx == NULL)
829 ctx = new_ctx = BN_CTX_new();
830 if (ctx == NULL)
834 BN_CTX_start(ctx);
835 n0 = BN_CTX_get(ctx);
836 n1 = BN_CTX_get(ctx);
837 n2 = BN_CTX_get(ctx);
838 n3 = BN_CTX_get(ctx);
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;
917 BN_CTX_end(ctx);
924 int ec_GFp_simple_invert(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx)
940 int ec_GFp_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX *ctx)
956 if (ctx == NULL)
958 ctx = new_ctx = BN_CTX_new();
959 if (ctx == NULL)
963 BN_CTX_start(ctx);
964 rh = BN_CTX_get(ctx);
965 tmp = BN_CTX_get(ctx);
966 Z4 = BN_CTX_get(ctx);
967 Z6 = BN_CTX_get(ctx);
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;
1024 BN_CTX_end(ctx);
1031 int ec_GFp_simple_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx)
1062 if (ctx == NULL)
1064 ctx = new_ctx = BN_CTX_new();
1065 if (ctx == NULL)
1069 BN_CTX_start(ctx);
1070 tmp1 = BN_CTX_get(ctx);
1071 tmp2 = BN_CTX_get(ctx);
1072 Za23 = BN_CTX_get(ctx);
1073 Zb23 = BN_CTX_get(ctx);
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;
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;
1135 BN_CTX_end(ctx);
1142 int ec_GFp_simple_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx)
1151 if (ctx == NULL)
1153 ctx = new_ctx = BN_CTX_new();
1154 if (ctx == NULL)
1158 BN_CTX_start(ctx);
1159 x = BN_CTX_get(ctx);
1160 y = BN_CTX_get(ctx);
1163 if (!EC_POINT_get_affine_coordinates_GFp(group, point, x, y, ctx)) goto err;
1164 if (!EC_POINT_set_affine_coordinates_GFp(group, point, x, y, ctx)) goto err;
1174 BN_CTX_end(ctx);
1181 int ec_GFp_simple_points_make_affine(const EC_GROUP *group, size_t num, EC_POINT *points[], BN_CTX *ctx)
1193 if (ctx == NULL)
1195 ctx = new_ctx = BN_CTX_new();
1196 if (ctx == NULL)
1200 BN_CTX_start(ctx);
1201 tmp0 = BN_CTX_get(ctx);
1202 tmp1 = BN_CTX_get(ctx);
1263 heap[2*i], heap[2*i + 1], ctx)) goto err;
1272 if (!BN_mod_inverse(heap[1], heap[1], &group->field, ctx))
1283 if (!group->meth->field_encode(group, heap[1], heap[1], ctx)) goto err;
1284 if (!group->meth->field_encode(group, heap[1], heap[1], ctx)) goto err;
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;
1313 if (!group->meth->field_sqr(group, tmp1, &p->Z, ctx)) goto err;
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;
1321 if (!group->meth->field_set_to_one(group, &p->Z, ctx)) goto err;
1334 BN_CTX_end(ctx);
1351 int ec_GFp_simple_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
1353 return BN_mod_mul(r, a, b, &group->field, ctx);
1357 int ec_GFp_simple_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
1359 return BN_mod_sqr(r, a, &group->field, ctx);