10#include <botan/ecdh.h>
11#include <botan/numthry.h>
12#include <botan/internal/pk_ops_impl.h>
14#if defined(BOTAN_HAS_OPENSSL)
15 #include <botan/internal/openssl.h>
25class ECDH_KA_Operation
final :
public PK_Ops::Key_Agreement_with_KDF
29 ECDH_KA_Operation(
const ECDH_PrivateKey& key,
const std::string& kdf, RandomNumberGenerator& rng) :
30 PK_Ops::Key_Agreement_with_KDF(kdf),
31 m_group(key.domain()),
34 m_l_times_priv = m_group.inverse_mod_order(m_group.get_cofactor()) * key.private_value();
37 size_t agreed_value_size()
const override {
return m_group.get_p_bytes(); }
39 secure_vector<uint8_t> raw_agree(
const uint8_t w[],
size_t w_len)
override
41 PointGFp input_point = m_group.get_cofactor() * m_group.OS2ECP(w, w_len);
42 input_point.randomize_repr(m_rng);
44 const PointGFp S = m_group.blinded_var_point_multiply(
45 input_point, m_l_times_priv, m_rng, m_ws);
47 if(S.on_the_curve() ==
false)
52 const EC_Group m_group;
53 BigInt m_l_times_priv;
54 RandomNumberGenerator& m_rng;
55 std::vector<BigInt> m_ws;
60std::unique_ptr<PK_Ops::Key_Agreement>
62 const std::string& params,
63 const std::string& provider)
const
65#if defined(BOTAN_HAS_OPENSSL)
66 if(provider ==
"openssl" || provider.empty())
70 return make_openssl_ecdh_ka_op(*
this, params);
74 if(provider ==
"openssl")
80 if(provider ==
"base" || provider.empty())
81 return std::unique_ptr<PK_Ops::Key_Agreement>(
new ECDH_KA_Operation(*
this, params, rng));
static secure_vector< uint8_t > encode_1363(const BigInt &n, size_t bytes)
std::unique_ptr< PK_Ops::Key_Agreement > create_key_agreement_op(RandomNumberGenerator &rng, const std::string ¶ms, const std::string &provider) const override
std::string algo_name() const override
int(* final)(unsigned char *, CTX *)