Lines Matching refs:group

304 static void ec_group_set0_generator(EC_GROUP *group, EC_POINT *generator) {  in ec_group_set0_generator()  argument
305 assert(group->generator == NULL); in ec_group_set0_generator()
306 assert(group == generator->group); in ec_group_set0_generator()
310 group->generator = generator; in ec_group_set0_generator()
311 int is_zero = CRYPTO_refcount_dec_and_test_zero(&group->references); in ec_group_set0_generator()
341 int EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator, in EC_GROUP_set_generator() argument
343 if (group->curve_name != NID_undef || group->generator != NULL || in EC_GROUP_set_generator()
344 generator->group != group) { in EC_GROUP_set_generator()
376 if (BN_cmp(tmp, &group->field) <= 0) { in EC_GROUP_set_generator()
381 copy = EC_POINT_new(group); in EC_GROUP_set_generator()
384 !BN_copy(&group->order, order)) { in EC_GROUP_set_generator()
388 bn_set_minimal_width(&group->order); in EC_GROUP_set_generator()
390 BN_MONT_CTX_free(group->order_mont); in EC_GROUP_set_generator()
391 group->order_mont = BN_MONT_CTX_new_for_modulus(&group->order, NULL); in EC_GROUP_set_generator()
392 if (group->order_mont == NULL) { in EC_GROUP_set_generator()
396 group->field_greater_than_order = BN_cmp(&group->field, &group->order) > 0; in EC_GROUP_set_generator()
397 if (group->field_greater_than_order) { in EC_GROUP_set_generator()
398 if (!BN_sub(tmp, &group->field, &group->order) || in EC_GROUP_set_generator()
399 !bn_copy_words(group->field_minus_order.words, group->field.width, in EC_GROUP_set_generator()
405 ec_group_set0_generator(group, copy); in EC_GROUP_set_generator()
416 EC_GROUP *group = NULL; in ec_group_new_from_data() local
437 group = ec_group_new(curve->method); in ec_group_new_from_data()
438 if (group == NULL || in ec_group_new_from_data()
439 !group->meth->group_set_curve(group, p, a, b, ctx)) { in ec_group_new_from_data()
444 if ((P = EC_POINT_new(group)) == NULL) { in ec_group_new_from_data()
455 if (!EC_POINT_set_affine_coordinates_GFp(group, P, x, y, ctx)) { in ec_group_new_from_data()
459 if (!BN_bin2bn(params + 5 * param_len, param_len, &group->order)) { in ec_group_new_from_data()
464 group->field_greater_than_order = BN_cmp(&group->field, &group->order) > 0; in ec_group_new_from_data()
465 if (group->field_greater_than_order) { in ec_group_new_from_data()
466 if (!BN_sub(p, &group->field, &group->order) || in ec_group_new_from_data()
467 !bn_copy_words(group->field_minus_order.words, group->field.width, p)) { in ec_group_new_from_data()
472 group->order_mont = BN_MONT_CTX_new_for_modulus(&group->order, ctx); in ec_group_new_from_data()
473 if (group->order_mont == NULL) { in ec_group_new_from_data()
478 ec_group_set0_generator(group, P); in ec_group_new_from_data()
484 EC_GROUP_free(group); in ec_group_new_from_data()
485 group = NULL; in ec_group_new_from_data()
494 return group; in ec_group_new_from_data()
552 void EC_GROUP_free(EC_GROUP *group) { in EC_GROUP_free() argument
553 if (group == NULL || in EC_GROUP_free()
555 group->curve_name != NID_undef || in EC_GROUP_free()
556 !CRYPTO_refcount_dec_and_test_zero(&group->references)) { in EC_GROUP_free()
560 if (group->meth->group_finish != NULL) { in EC_GROUP_free()
561 group->meth->group_finish(group); in EC_GROUP_free()
564 ec_point_free(group->generator, 0 /* don't free group */); in EC_GROUP_free()
565 BN_free(&group->order); in EC_GROUP_free()
566 BN_MONT_CTX_free(group->order_mont); in EC_GROUP_free()
568 OPENSSL_free(group); in EC_GROUP_free()
580 EC_GROUP *group = (EC_GROUP *)a; in EC_GROUP_dup() local
581 CRYPTO_refcount_inc(&group->references); in EC_GROUP_dup()
582 return group; in EC_GROUP_dup()
612 const EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *group) { in EC_GROUP_get0_generator() argument
613 return group->generator; in EC_GROUP_get0_generator()
616 const BIGNUM *EC_GROUP_get0_order(const EC_GROUP *group) { in EC_GROUP_get0_order() argument
617 assert(!BN_is_zero(&group->order)); in EC_GROUP_get0_order()
618 return &group->order; in EC_GROUP_get0_order()
621 int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx) { in EC_GROUP_get_order() argument
622 if (BN_copy(order, EC_GROUP_get0_order(group)) == NULL) { in EC_GROUP_get_order()
628 int EC_GROUP_order_bits(const EC_GROUP *group) { in EC_GROUP_order_bits() argument
629 return BN_num_bits(&group->order); in EC_GROUP_order_bits()
632 int EC_GROUP_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor, in EC_GROUP_get_cofactor() argument
638 int EC_GROUP_get_curve_GFp(const EC_GROUP *group, BIGNUM *out_p, BIGNUM *out_a, in EC_GROUP_get_curve_GFp() argument
640 return ec_GFp_simple_group_get_curve(group, out_p, out_a, out_b); in EC_GROUP_get_curve_GFp()
643 int EC_GROUP_get_curve_name(const EC_GROUP *group) { return group->curve_name; } in EC_GROUP_get_curve_name() argument
645 unsigned EC_GROUP_get_degree(const EC_GROUP *group) { in EC_GROUP_get_degree() argument
646 return BN_num_bits(&group->field); in EC_GROUP_get_degree()
679 EC_POINT *EC_POINT_new(const EC_GROUP *group) { in EC_POINT_new() argument
680 if (group == NULL) { in EC_POINT_new()
691 ret->group = EC_GROUP_dup(group); in EC_POINT_new()
701 EC_GROUP_free(point->group); in ec_point_free()
713 if (EC_GROUP_cmp(dest->group, src->group, NULL) != 0) { in EC_POINT_copy()
724 EC_POINT *EC_POINT_dup(const EC_POINT *a, const EC_GROUP *group) { in EC_POINT_dup() argument
729 EC_POINT *ret = EC_POINT_new(group); in EC_POINT_dup()
739 int EC_POINT_set_to_infinity(const EC_GROUP *group, EC_POINT *point) { in EC_POINT_set_to_infinity() argument
740 if (EC_GROUP_cmp(group, point->group, NULL) != 0) { in EC_POINT_set_to_infinity()
744 ec_GFp_simple_point_set_to_infinity(group, &point->raw); in EC_POINT_set_to_infinity()
748 int EC_POINT_is_at_infinity(const EC_GROUP *group, const EC_POINT *point) { in EC_POINT_is_at_infinity() argument
749 if (EC_GROUP_cmp(group, point->group, NULL) != 0) { in EC_POINT_is_at_infinity()
753 return ec_GFp_simple_is_at_infinity(group, &point->raw); in EC_POINT_is_at_infinity()
756 int EC_POINT_is_on_curve(const EC_GROUP *group, const EC_POINT *point, in EC_POINT_is_on_curve() argument
758 if (EC_GROUP_cmp(group, point->group, NULL) != 0) { in EC_POINT_is_on_curve()
762 return ec_GFp_simple_is_on_curve(group, &point->raw); in EC_POINT_is_on_curve()
765 int EC_POINT_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b, in EC_POINT_cmp() argument
767 if (EC_GROUP_cmp(group, a->group, NULL) != 0 || in EC_POINT_cmp()
768 EC_GROUP_cmp(group, b->group, NULL) != 0) { in EC_POINT_cmp()
772 return ec_GFp_simple_cmp(group, &a->raw, &b->raw); in EC_POINT_cmp()
775 int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group, in EC_POINT_get_affine_coordinates_GFp() argument
778 if (group->meth->point_get_affine_coordinates == 0) { in EC_POINT_get_affine_coordinates_GFp()
782 if (EC_GROUP_cmp(group, point->group, NULL) != 0) { in EC_POINT_get_affine_coordinates_GFp()
787 if (!group->meth->point_get_affine_coordinates(group, &point->raw, in EC_POINT_get_affine_coordinates_GFp()
790 (x != NULL && !bn_set_words(x, x_felem.words, group->field.width)) || in EC_POINT_get_affine_coordinates_GFp()
791 (y != NULL && !bn_set_words(y, y_felem.words, group->field.width))) { in EC_POINT_get_affine_coordinates_GFp()
797 int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *group, EC_POINT *point, in EC_POINT_set_affine_coordinates_GFp() argument
800 if (EC_GROUP_cmp(group, point->group, NULL) != 0) { in EC_POINT_set_affine_coordinates_GFp()
804 if (!ec_GFp_simple_point_set_affine_coordinates(group, &point->raw, x, y)) { in EC_POINT_set_affine_coordinates_GFp()
808 if (!EC_POINT_is_on_curve(group, point, ctx)) { in EC_POINT_set_affine_coordinates_GFp()
811 const EC_POINT *generator = EC_GROUP_get0_generator(group); in EC_POINT_set_affine_coordinates_GFp()
825 int EC_POINT_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, in EC_POINT_add() argument
827 if (EC_GROUP_cmp(group, r->group, NULL) != 0 || in EC_POINT_add()
828 EC_GROUP_cmp(group, a->group, NULL) != 0 || in EC_POINT_add()
829 EC_GROUP_cmp(group, b->group, NULL) != 0) { in EC_POINT_add()
833 group->meth->add(group, &r->raw, &a->raw, &b->raw); in EC_POINT_add()
837 int EC_POINT_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, in EC_POINT_dbl() argument
839 if (EC_GROUP_cmp(group, r->group, NULL) != 0 || in EC_POINT_dbl()
840 EC_GROUP_cmp(group, a->group, NULL) != 0) { in EC_POINT_dbl()
844 group->meth->dbl(group, &r->raw, &a->raw); in EC_POINT_dbl()
849 int EC_POINT_invert(const EC_GROUP *group, EC_POINT *a, BN_CTX *ctx) { in EC_POINT_invert() argument
850 if (EC_GROUP_cmp(group, a->group, NULL) != 0) { in EC_POINT_invert()
854 ec_GFp_simple_invert(group, &a->raw); in EC_POINT_invert()
858 static int arbitrary_bignum_to_scalar(const EC_GROUP *group, EC_SCALAR *out, in arbitrary_bignum_to_scalar() argument
860 if (ec_bignum_to_scalar(group, out, in)) { in arbitrary_bignum_to_scalar()
867 const BIGNUM *order = &group->order; in arbitrary_bignum_to_scalar()
872 ec_bignum_to_scalar(group, out, tmp); in arbitrary_bignum_to_scalar()
877 int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *g_scalar, in EC_POINT_mul() argument
888 if (EC_GROUP_cmp(group, r->group, NULL) != 0 || in EC_POINT_mul()
889 (p != NULL && EC_GROUP_cmp(group, p->group, NULL) != 0)) { in EC_POINT_mul()
907 if (!arbitrary_bignum_to_scalar(group, &g_scalar_storage, g_scalar, ctx)) { in EC_POINT_mul()
914 if (!arbitrary_bignum_to_scalar(group, &p_scalar_storage, p_scalar, ctx)) { in EC_POINT_mul()
920 ret = ec_point_mul_scalar(group, &r->raw, g_scalar_arg, in EC_POINT_mul()
930 int ec_point_mul_scalar_public(const EC_GROUP *group, EC_RAW_POINT *r, in ec_point_mul_scalar_public() argument
939 group->meth->mul_public(group, r, g_scalar, p, p_scalar); in ec_point_mul_scalar_public()
943 int ec_point_mul_scalar(const EC_GROUP *group, EC_RAW_POINT *r, in ec_point_mul_scalar() argument
952 group->meth->mul(group, r, g_scalar, p, p_scalar); in ec_point_mul_scalar()
956 int ec_cmp_x_coordinate(const EC_GROUP *group, const EC_RAW_POINT *p, in ec_cmp_x_coordinate() argument
958 return group->meth->cmp_x_coordinate(group, p, r); in ec_cmp_x_coordinate()
961 int ec_get_x_coordinate_as_scalar(const EC_GROUP *group, EC_SCALAR *out, in ec_get_x_coordinate_as_scalar() argument
967 if (!group->meth->point_get_affine_coordinates(group, p, &x, NULL)) { in ec_get_x_coordinate_as_scalar()
990 group->order.width < EC_MAX_WORDS ? x.words[group->order.width] : 0; in ec_get_x_coordinate_as_scalar()
991 bn_reduce_once(out->words, x.words, carry, group->order.d, in ec_get_x_coordinate_as_scalar()
992 group->order.width); in ec_get_x_coordinate_as_scalar()
996 int ec_point_get_affine_coordinate_bytes(const EC_GROUP *group, uint8_t *out_x, in ec_point_get_affine_coordinate_bytes() argument
1000 size_t len = BN_num_bytes(&group->field); in ec_point_get_affine_coordinate_bytes()
1008 if (!group->meth->point_get_affine_coordinates( in ec_point_get_affine_coordinate_bytes()
1009 group, p, out_x == NULL ? NULL : &x, out_y == NULL ? NULL : &y)) { in ec_point_get_affine_coordinate_bytes()
1027 void EC_GROUP_set_asn1_flag(EC_GROUP *group, int flag) {} in EC_GROUP_set_asn1_flag() argument
1029 const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *group) { in EC_GROUP_method_of() argument
1040 void EC_GROUP_set_point_conversion_form(EC_GROUP *group, in EC_GROUP_set_point_conversion_form() argument