Lines Matching refs:ctx
169 const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
182 if (ctx == NULL)
184 ctx = new_ctx = BN_CTX_new();
185 if (ctx == NULL)
189 BN_CTX_start(ctx);
190 tmp_a = BN_CTX_get(ctx);
198 if (!BN_nnmod(tmp_a, a, p, ctx)) goto err;
200 { if (!group->meth->field_encode(group, &group->a, tmp_a, ctx)) goto err; }
205 if (!BN_nnmod(&group->b, b, p, ctx)) goto err;
207 if (!group->meth->field_encode(group, &group->b, &group->b, ctx)) goto err;
216 BN_CTX_end(ctx);
223 int ec_GFp_simple_group_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)
237 if (ctx == NULL)
239 ctx = new_ctx = BN_CTX_new();
240 if (ctx == NULL)
245 if (!group->meth->field_decode(group, a, &group->a, ctx)) goto err;
249 if (!group->meth->field_decode(group, b, &group->b, ctx)) goto err;
280 int ec_GFp_simple_group_check_discriminant(const EC_GROUP *group, BN_CTX *ctx)
287 if (ctx == NULL)
289 ctx = new_ctx = BN_CTX_new();
290 if (ctx == NULL)
296 BN_CTX_start(ctx);
297 a = BN_CTX_get(ctx);
298 b = BN_CTX_get(ctx);
299 tmp_1 = BN_CTX_get(ctx);
300 tmp_2 = BN_CTX_get(ctx);
301 order = BN_CTX_get(ctx);
306 if (!group->meth->field_decode(group, a, &group->a, ctx)) goto err;
307 if (!group->meth->field_decode(group, b, &group->b, ctx)) goto err;
324 if (!BN_mod_sqr(tmp_1, a, p, ctx)) goto err;
325 if (!BN_mod_mul(tmp_2, tmp_1, a, p, ctx)) goto err;
329 if (!BN_mod_sqr(tmp_2, b, p, ctx)) goto err;
333 if (!BN_mod_add(a, tmp_1, tmp_2, p, ctx)) goto err;
339 if (ctx != NULL)
340 BN_CTX_end(ctx);
395 const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *ctx)
400 if (ctx == NULL)
402 ctx = new_ctx = BN_CTX_new();
403 if (ctx == NULL)
409 if (!BN_nnmod(&point->X, x, &group->field, ctx)) goto err;
412 if (!group->meth->field_encode(group, &point->X, &point->X, ctx)) goto err;
418 if (!BN_nnmod(&point->Y, y, &group->field, ctx)) goto err;
421 if (!group->meth->field_encode(group, &point->Y, &point->Y, ctx)) goto err;
429 if (!BN_nnmod(&point->Z, z, &group->field, ctx)) goto err;
435 if (!group->meth->field_set_to_one(group, &point->Z, ctx)) goto err;
439 if (!group->meth->field_encode(group, &point->Z, &point->Z, ctx)) goto err;
455 BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *ctx)
462 if (ctx == NULL)
464 ctx = new_ctx = BN_CTX_new();
465 if (ctx == NULL)
471 if (!group->meth->field_decode(group, x, &point->X, ctx)) goto err;
475 if (!group->meth->field_decode(group, y, &point->Y, ctx)) goto err;
479 if (!group->meth->field_decode(group, z, &point->Z, ctx)) goto err;
508 const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx)
517 return EC_POINT_set_Jprojective_coordinates_GFp(group, point, x, y, BN_value_one(), ctx);
522 BIGNUM *x, BIGNUM *y, BN_CTX *ctx)
535 if (ctx == NULL)
537 ctx = new_ctx = BN_CTX_new();
538 if (ctx == NULL)
542 BN_CTX_start(ctx);
543 Z = BN_CTX_get(ctx);
544 Z_1 = BN_CTX_get(ctx);
545 Z_2 = BN_CTX_get(ctx);
546 Z_3 = BN_CTX_get(ctx);
553 if (!group->meth->field_decode(group, Z, &point->Z, ctx)) goto err;
567 if (!group->meth->field_decode(group, x, &point->X, ctx)) goto err;
571 if (!group->meth->field_decode(group, y, &point->Y, ctx)) goto err;
588 if (!BN_mod_inverse(Z_1, Z_, &group->field, ctx))
597 if (!group->meth->field_sqr(group, Z_2, Z_1, ctx)) goto err;
601 if (!BN_mod_sqr(Z_2, Z_1, &group->field, ctx)) goto err;
607 if (!group->meth->field_mul(group, x, &point->X, Z_2, ctx)) goto err;
615 if (!group->meth->field_mul(group, Z_3, Z_2, Z_1, ctx)) goto err;
619 if (!BN_mod_mul(Z_3, Z_2, Z_1, &group->field, ctx)) goto err;
623 if (!group->meth->field_mul(group, y, &point->Y, Z_3, ctx)) goto err;
630 BN_CTX_end(ctx);
638 const BIGNUM *x_, int y_bit, BN_CTX *ctx)
647 if (ctx == NULL)
649 ctx = new_ctx = BN_CTX_new();
650 if (ctx == NULL)
656 BN_CTX_start(ctx);
657 tmp1 = BN_CTX_get(ctx);
658 tmp2 = BN_CTX_get(ctx);
659 x = BN_CTX_get(ctx);
660 y = BN_CTX_get(ctx);
669 if (!BN_nnmod(x, x_, &group->field,ctx)) goto err;
673 if (!group->meth->field_sqr(group, tmp2, x_, ctx)) goto err;
674 if (!group->meth->field_mul(group, tmp1, tmp2, x_, ctx)) goto err;
678 if (!BN_mod_sqr(tmp2, x_, &group->field, ctx)) goto err;
679 if (!BN_mod_mul(tmp1, tmp2, x_, &group->field, ctx)) goto err;
693 if (!group->meth->field_decode(group, tmp2, &group->a, ctx)) goto err;
694 if (!BN_mod_mul(tmp2, tmp2, x, &group->field, ctx)) goto err;
699 if (!group->meth->field_mul(group, tmp2, &group->a, x, ctx)) goto err;
708 if (!group->meth->field_decode(group, tmp2, &group->b, ctx)) goto err;
716 if (!BN_mod_sqrt(y, tmp1, &group->field, ctx))
736 kron = BN_kronecker(x, &group->field, ctx);
754 if (!EC_POINT_set_affine_coordinates_GFp(group, point, x, y, ctx)) goto err;
759 BN_CTX_end(ctx);
767 unsigned char *buf, size_t len, BN_CTX *ctx)
812 if (ctx == NULL)
814 ctx = new_ctx = BN_CTX_new();
815 if (ctx == NULL)
819 BN_CTX_start(ctx);
821 x = BN_CTX_get(ctx);
822 y = BN_CTX_get(ctx);
825 if (!EC_POINT_get_affine_coordinates_GFp(group, point, x, y, ctx)) goto err;
878 BN_CTX_end(ctx);
885 BN_CTX_end(ctx);
893 const unsigned char *buf, size_t len, BN_CTX *ctx)
943 if (ctx == NULL)
945 ctx = new_ctx = BN_CTX_new();
946 if (ctx == NULL)
950 BN_CTX_start(ctx);
951 x = BN_CTX_get(ctx);
952 y = BN_CTX_get(ctx);
964 if (!EC_POINT_set_compressed_coordinates_GFp(group, point, x, y_bit, ctx)) goto err;
983 if (!EC_POINT_set_affine_coordinates_GFp(group, point, x, y, ctx)) goto err;
986 if (!EC_POINT_is_on_curve(group, point, ctx)) /* test required by X9.62 */
995 BN_CTX_end(ctx);
1002 int ec_GFp_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx)
1012 return EC_POINT_dbl(group, r, a, ctx);
1022 if (ctx == NULL)
1024 ctx = new_ctx = BN_CTX_new();
1025 if (ctx == NULL)
1029 BN_CTX_start(ctx);
1030 n0 = BN_CTX_get(ctx);
1031 n1 = BN_CTX_get(ctx);
1032 n2 = BN_CTX_get(ctx);
1033 n3 = BN_CTX_get(ctx);
1034 n4 = BN_CTX_get(ctx);
1035 n5 = BN_CTX_get(ctx);
1036 n6 = BN_CTX_get(ctx);
1054 if (!field_sqr(group, n0, &b->Z, ctx)) goto end;
1055 if (!field_mul(group, n1, &a->X, n0, ctx)) goto end;
1058 if (!field_mul(group, n0, n0, &b->Z, ctx)) goto end;
1059 if (!field_mul(group, n2, &a->Y, n0, ctx)) goto end;
1073 if (!field_sqr(group, n0, &a->Z, ctx)) goto end;
1074 if (!field_mul(group, n3, &b->X, n0, ctx)) goto end;
1077 if (!field_mul(group, n0, n0, &a->Z, ctx)) goto end;
1078 if (!field_mul(group, n4, &b->Y, n0, ctx)) goto end;
1093 BN_CTX_end(ctx);
1094 ret = EC_POINT_dbl(group, r, a, ctx);
1095 ctx = NULL;
1126 { if (!field_mul(group, n0, &a->Z, &b->Z, ctx)) goto end; }
1127 if (!field_mul(group, &r->Z, n0, n5, ctx)) goto end;
1133 if (!field_sqr(group, n0, n6, ctx)) goto end;
1134 if (!field_sqr(group, n4, n5, ctx)) goto end;
1135 if (!field_mul(group, n3, n1, n4, ctx)) goto end;
1145 if (!field_mul(group, n0, n0, n6, ctx)) goto end;
1146 if (!field_mul(group, n5, n4, n5, ctx)) goto end; /* now n5 is n5^3 */
1147 if (!field_mul(group, n1, n2, n5, ctx)) goto end;
1158 if (ctx) /* otherwise we already called BN_CTX_end */
1159 BN_CTX_end(ctx);
1166 int ec_GFp_simple_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, BN_CTX *ctx)
1186 if (ctx == NULL)
1188 ctx = new_ctx = BN_CTX_new();
1189 if (ctx == NULL)
1193 BN_CTX_start(ctx);
1194 n0 = BN_CTX_get(ctx);
1195 n1 = BN_CTX_get(ctx);
1196 n2 = BN_CTX_get(ctx);
1197 n3 = BN_CTX_get(ctx);
1208 if (!field_sqr(group, n0, &a->X, ctx)) goto err;
1216 if (!field_sqr(group, n1, &a->Z, ctx)) goto err;
1219 if (!field_mul(group, n1, n0, n2, ctx)) goto err;
1227 if (!field_sqr(group, n0, &a->X, ctx)) goto err;
1230 if (!field_sqr(group, n1, &a->Z, ctx)) goto err;
1231 if (!field_sqr(group, n1, n1, ctx)) goto err;
1232 if (!field_mul(group, n1, n1, &group->a, ctx)) goto err;
1244 if (!field_mul(group, n0, &a->Y, &a->Z, ctx)) goto err;
1251 if (!field_sqr(group, n3, &a->Y, ctx)) goto err;
1252 if (!field_mul(group, n2, &a->X, n3, ctx)) goto err;
1258 if (!field_sqr(group, &r->X, n1, ctx)) goto err;
1263 if (!field_sqr(group, n0, n3, ctx)) goto err;
1269 if (!field_mul(group, n0, n1, n0, ctx)) goto err;
1276 BN_CTX_end(ctx);
1283 int ec_GFp_simple_invert(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx)
1299 int ec_GFp_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX *ctx)
1315 if (ctx == NULL)
1317 ctx = new_ctx = BN_CTX_new();
1318 if (ctx == NULL)
1322 BN_CTX_start(ctx);
1323 rh = BN_CTX_get(ctx);
1324 tmp = BN_CTX_get(ctx);
1325 Z4 = BN_CTX_get(ctx);
1326 Z6 = BN_CTX_get(ctx);
1339 if (!field_sqr(group, rh, &point->X, ctx)) goto err;
1343 if (!field_sqr(group, tmp, &point->Z, ctx)) goto err;
1344 if (!field_sqr(group, Z4, tmp, ctx)) goto err;
1345 if (!field_mul(group, Z6, Z4, tmp, ctx)) goto err;
1353 if (!field_mul(group, rh, rh, &point->X, ctx)) goto err;
1357 if (!field_mul(group, tmp, Z4, &group->a, ctx)) goto err;
1359 if (!field_mul(group, rh, rh, &point->X, ctx
1363 if (!field_mul(group, tmp, &group->b, Z6, ctx)) goto err;
1372 if (!field_mul(group, rh, rh, &point->X, ctx)) goto err;
1378 if (!field_sqr(group, tmp, &point->Y, ctx)) goto err;
1383 BN_CTX_end(ctx);
1390 int ec_GFp_simple_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx)
1418 if (ctx == NULL)
1420 ctx = new_ctx = BN_CTX_new();
1421 if (ctx == NULL)
1425 BN_CTX_start(ctx);
1426 tmp1 = BN_CTX_get(ctx);
1427 tmp2 = BN_CTX_get(ctx);
1428 Za23 = BN_CTX_get(ctx);
1429 Zb23 = BN_CTX_get(ctx);
1440 if (!field_sqr(group, Zb23, &b->Z, ctx)) goto end;
1441 if (!field_mul(group, tmp1, &a->X, Zb23, ctx)) goto end;
1448 if (!field_sqr(group, Za23, &a->Z, ctx)) goto end;
1449 if (!field_mul(group, tmp2, &b->X, Za23, ctx)) goto end;
1465 if (!field_mul(group, Zb23, Zb23, &b->Z, ctx)) goto end;
1466 if (!field_mul(group, tmp1, &a->Y, Zb23, ctx)) goto end;
1473 if (!field_mul(group, Za23, Za23, &a->Z, ctx)) goto end;
1474 if (!field_mul(group, tmp2, &b->Y, Za23, ctx)) goto end;
1491 BN_CTX_end(ctx);
1498 int ec_GFp_simple_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx)
1507 if (ctx == NULL)
1509 ctx = new_ctx = BN_CTX_new();
1510 if (ctx == NULL)
1514 BN_CTX_start(ctx);
1515 x = BN_CTX_get(ctx);
1516 y = BN_CTX_get(ctx);
1519 if (!EC_POINT_get_affine_coordinates_GFp(group, point, x, y, ctx)) goto err;
1520 if (!EC_POINT_set_affine_coordinates_GFp(group, point, x, y, ctx)) goto err;
1530 BN_CTX_end(ctx);
1537 int ec_GFp_simple_points_make_affine(const EC_GROUP *group, size_t num, EC_POINT *points[], BN_CTX *ctx)
1549 if (ctx == NULL)
1551 ctx = new_ctx = BN_CTX_new();
1552 if (ctx == NULL)
1556 BN_CTX_start(ctx);
1557 tmp0 = BN_CTX_get(ctx);
1558 tmp1 = BN_CTX_get(ctx);
1619 heap[2*i], heap[2*i + 1], ctx)) goto err;
1628 if (!BN_mod_inverse(heap[1], heap[1], &group->field, ctx))
1639 if (!group->meth->field_encode(group, heap[1], heap[1], ctx)) goto err;
1640 if (!group->meth->field_encode(group, heap[1], heap[1], ctx)) goto err;
1649 if (!group->meth->field_mul(group, tmp0, heap[i/2], heap[i + 1], ctx)) goto err;
1650 if (!group->meth->field_mul(group, tmp1, heap[i/2], heap[i], ctx)) goto err;
1669 if (!group->meth->field_sqr(group, tmp1, &p->Z, ctx)) goto err;
1670 if (!group->meth->field_mul(group, &p->X, &p->X, tmp1, ctx)) goto err;
1672 if (!group->meth->field_mul(group, tmp1, tmp1, &p->Z, ctx)) goto err;
1673 if (!group->meth->field_mul(group, &p->Y, &p->Y, tmp1, ctx)) goto err;
1677 if (!group->meth->field_set_to_one(group, &p->Z, ctx)) goto err;
1690 BN_CTX_end(ctx);
1707 int ec_GFp_simple_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
1709 return BN_mod_mul(r, a, b, &group->field, ctx);
1713 int ec_GFp_simple_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
1715 return BN_mod_sqr(r, a, &group->field, ctx);