10#include <botan/ecdh.h>
12#include <botan/internal/pk_ops_impl.h>
28 PK_Ops::Key_Agreement_with_KDF(kdf),
29 m_group(key.domain()),
30 m_l_times_priv(mul_cofactor_inv(m_group, key._private_key())),
33 size_t agreed_value_size()
const override {
return m_group.get_p_bytes(); }
36 if(m_group.has_cofactor()) {
37#if defined(BOTAN_HAS_LEGACY_EC_POINT)
38 EC_AffinePoint input_point(m_group, m_group.get_cofactor() * m_group.OS2ECP(w, w_len));
39 return input_point.mul_x_only(m_l_times_priv, m_rng, m_ws);
41 throw Not_Implemented(
"Support for DH with cofactor adjustment not available in this build configuration");
45 return input_point->mul_x_only(m_l_times_priv, m_rng, m_ws);
47 throw Decoding_Error(
"ECDH - Invalid elliptic curve point");
53 static EC_Scalar mul_cofactor_inv(
const EC_Group& group,
const EC_Scalar& x) {
57 if(group.has_cofactor()) {
65 const EC_Group m_group;
66 const EC_Scalar m_l_times_priv;
67 RandomNumberGenerator& m_rng;
68 std::vector<BigInt> m_ws;
74 return std::make_unique<ECDH_PrivateKey>(rng,
domain());
82 std::string_view params,
83 std::string_view provider)
const {
84 if(provider ==
"base" || provider.empty()) {
85 return std::make_unique<ECDH_KA_Operation>(*
this, params, rng);
std::unique_ptr< Public_Key > public_key() const override
std::unique_ptr< PK_Ops::Key_Agreement > create_key_agreement_op(RandomNumberGenerator &rng, std::string_view params, std::string_view provider) const override
std::vector< uint8_t > public_value() const
std::string algo_name() const override
std::unique_ptr< Private_Key > generate_another(RandomNumberGenerator &rng) const final
static std::optional< EC_AffinePoint > deserialize(const EC_Group &group, std::span< const uint8_t > bytes)
std::vector< uint8_t > serialize(EC_Point_Format format) const
Return an encoding depending on the requested format.
const EC_Group & domain() const
const EC_AffinePoint & _public_ec_point() const
static EC_Scalar from_bigint(const EC_Group &group, const BigInt &bn)
EC_Scalar invert_vartime() const
int(* final)(unsigned char *, CTX *)
std::vector< T, secure_allocator< T > > secure_vector