10#include <botan/ecdh.h>
12#include <botan/bigint.h>
13#include <botan/ec_group.h>
14#include <botan/internal/ct_utils.h>
15#include <botan/internal/pk_ops_impl.h>
16#include <botan/internal/pk_options_impl.h>
34 PK_Ops::Key_Agreement_with_KDF(options),
35 m_group(key.domain()),
36 m_l_times_priv(mul_cofactor_inv(m_group, key._private_key())),
39 size_t agreed_value_size()
const override {
return m_group.get_p_bytes(); }
42 const auto input_point = [&] {
43 if(m_group.has_cofactor()) {
44#if defined(BOTAN_HAS_LEGACY_EC_POINT)
45 return EC_AffinePoint(m_group, m_group.get_cofactor() * m_group.OS2ECP(w, w_len));
47 throw Not_Implemented(
48 "Support for DH with cofactor adjustment not available in this build configuration");
54 throw Decoding_Error(
"ECDH - Invalid elliptic curve point: not on curve");
64 if(input_point.is_identity()) {
65 throw Decoding_Error(
"ECDH - Invalid elliptic curve point: identity");
74 static EC_Scalar mul_cofactor_inv(
const EC_Group& group,
const EC_Scalar& x) {
78 if(group.has_cofactor()) {
86 const EC_Group m_group;
87 const EC_Scalar m_l_times_priv;
88 RandomNumberGenerator& m_rng;
94 return std::make_unique<ECDH_PrivateKey>(rng,
domain());
105 return std::make_unique<ECDH_KA_Operation>(*
this, options, rng);
std::unique_ptr< Public_Key > public_key() const override
std::unique_ptr< PK_Ops::Key_Agreement > _create_key_agreement_op(RandomNumberGenerator &rng, const PK_Key_Agreement_Options_Reader &options) 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
constexpr decltype(auto) driveby_unpoison(T &&v)
constexpr auto scoped_poison(const Ts &... xs)
void require_software_provider(const OptionsT &options, std::string_view algo_name)
std::vector< T, secure_allocator< T > > secure_vector