181 explicit EC_Group(std::span<const uint8_t> ber);
205 static
EC_Group from_PEM(std::string_view pem);
218 return EC_Group::from_PEM(pem);
234 bool initialized()
const {
return (m_data !=
nullptr); }
250 static bool supports_application_specific_group();
255 static bool supports_named_group(std::string_view
name);
279 static const std::set<std::string>& known_named_groups();
293 std::vector<uint8_t> DER_encode() const;
299 std::
string PEM_encode() const;
304 size_t get_p_bits() const;
309 size_t get_p_bytes() const;
314 size_t get_order_bits() const;
319 size_t get_order_bytes() const;
338 std::optional<EC_AffinePoint> mul2_vartime(
const EC_Scalar& x,
const EC_Scalar& y)
const;
360 bool mul2_vartime_x_mod_order_eq(
const EC_Scalar& v,
368 std::unique_ptr<EC_Mul2Table_Data> m_tbl;
375 const OID& get_curve_oid()
const;
380 const BigInt& get_p()
const;
385 const BigInt& get_a()
const;
390 const BigInt& get_b()
const;
395 const BigInt& get_g_x()
const;
400 const BigInt& get_g_y()
const;
406 const BigInt& get_order()
const;
413 const BigInt& get_cofactor()
const;
419 bool has_cofactor()
const;
425 static std::shared_ptr<EC_Group_Data> EC_group_info(
const OID& oid);
431 static size_t clear_registered_curve_data();
437 static OID EC_group_identity_from_order(
const BigInt& order);
442 const std::shared_ptr<EC_Group_Data>&
_data()
const {
return m_data; }
444#if defined(BOTAN_HAS_LEGACY_EC_POINT)
451 bool verify_public_element(
const EC_Point& y)
const;
459 return EC_AffinePoint(*
this, std::span{bits, len}).to_legacy_point();
463 EC_Point OS2ECP(std::span<const uint8_t> encoded_point)
const {
464 return EC_AffinePoint(*
this, encoded_point).to_legacy_point();
471 BOTAN_DEPRECATED(
"Use EC_AffinePoint::generator") const EC_Point& get_base_point() const;
479 BOTAN_DEPRECATED("Use EC_AffinePoint::generator") const EC_Point& generator() const;
486 EC_Point point_multiply(const BigInt& x_bn, const EC_Point& h_pt, const BigInt& y_bn)
const {
487 auto x = EC_Scalar::from_bigint(*
this, x_bn);
488 auto y = EC_Scalar::from_bigint(*
this, y_bn);
489 auto h = EC_AffinePoint(*
this, h_pt);
493 if(
auto r = gh_mul.mul2_vartime(x, y)) {
494 return r->to_legacy_point();
496 return EC_AffinePoint::identity(*this).to_legacy_point();
509 blinded_base_point_multiply(const BigInt& k_bn, RandomNumberGenerator& rng, std::vector<BigInt>& ws)
const {
510 auto k = EC_Scalar::from_bigint(*
this, k_bn);
511 auto pt = EC_AffinePoint::g_mul(k, rng, ws);
512 return pt.to_legacy_point();
526 blinded_base_point_multiply_x(const BigInt& k_bn, RandomNumberGenerator& rng, std::vector<BigInt>& ws)
const {
527 auto k = EC_Scalar::from_bigint(*
this, k_bn);
528 return BigInt(EC_AffinePoint::g_mul(k, rng, ws).x_bytes());
540 EC_Point blinded_var_point_multiply(const EC_Point& point,
542 RandomNumberGenerator& rng,
543 std::vector<BigInt>& ws)
const {
544 auto k = EC_Scalar::from_bigint(*
this, k_bn);
545 auto pt = EC_AffinePoint(*
this, point);
546 return pt.mul(k, rng, ws).to_legacy_point();
552 BOTAN_DEPRECATED(
"Use EC_Scalar::random") BigInt random_scalar(RandomNumberGenerator& rng)
const {
553 return EC_Scalar::random(*
this, rng).to_bigint();
570 EC_Point hash_to_curve(std::string_view hash_fn,
571 const uint8_t input[],
573 const uint8_t domain_sep[],
574 size_t domain_sep_len,
575 bool random_oracle = true)
const {
576 auto inp = std::span{input, input_len};
577 auto dst = std::span{domain_sep, domain_sep_len};
580 return EC_AffinePoint::hash_to_curve_ro(*
this, hash_fn, inp, dst).to_legacy_point();
582 return EC_AffinePoint::hash_to_curve_nu(*
this, hash_fn, inp, dst).to_legacy_point();
599 EC_Point hash_to_curve(std::string_view hash_fn,
600 const uint8_t input[],
602 std::string_view domain_sep,
603 bool random_oracle = true)
const {
604 auto inp = std::span{input, input_len};
605 auto dst = std::span{
reinterpret_cast<const uint8_t*
>(domain_sep.data()), domain_sep.size()};
608 return EC_AffinePoint::hash_to_curve_ro(*
this, hash_fn, inp, dst).to_legacy_point();
610 return EC_AffinePoint::hash_to_curve_nu(*
this, hash_fn, inp, dst).to_legacy_point();
617 BOTAN_DEPRECATED(
"Deprecated - use EC_AffinePoint") EC_Point point(const BigInt& x, const BigInt& y)
const {
618 if(
auto pt = EC_AffinePoint::from_bigint_xy(*
this, x, y)) {
619 return pt->to_legacy_point();
621 throw Decoding_Error(
"Invalid x/y coordinates for elliptic curve point");
629 return EC_AffinePoint::identity(*this).to_legacy_point();
636 BOTAN_DEPRECATED(
"Deprecated no replacement") bool a_is_minus_3()
const {
return get_a() + 3 == get_p(); }
641 BOTAN_DEPRECATED(
"Deprecated no replacement") bool a_is_zero()
const {
return get_a().is_zero(); }
647 return EC_Scalar::from_bytes_mod_order(*
this, x.serialize()).to_bigint();
654 return EC_Scalar::from_bigint(*
this, x).invert().to_bigint();
661 auto xs = EC_Scalar::from_bigint(*
this, x);
663 return xs.to_bigint();
670 auto xs = EC_Scalar::from_bigint(*
this, x);
671 auto ys = EC_Scalar::from_bigint(*
this, y);
672 return (xs * ys).to_bigint();
680 auto xs = EC_Scalar::from_bigint(*
this, x);
681 auto ys = EC_Scalar::from_bigint(*
this, y);
682 auto zs = EC_Scalar::from_bigint(*
this, z);
683 return (xs * ys * zs).to_bigint();
690 auto xs = EC_Scalar::from_bigint(*
this, x);
691 return (xs * xs * xs).to_bigint();
696 if(format == EC_Point_Format::Compressed) {
697 return (1 + get_p_bytes());
699 return (1 + 2 * get_p_bytes());
704 static EC_Group_Data_Map& ec_group_data();
706 EC_Group(std::shared_ptr<EC_Group_Data>&& data);
708 static std::pair<std::shared_ptr<EC_Group_Data>,
bool> BER_decode_EC_group(std::span<const uint8_t> ber,
711 static std::shared_ptr<EC_Group_Data> load_EC_group_info(
const char* p,
722 std::shared_ptr<EC_Group_Data> m_data;
723 bool m_explicit_encoding =
false;