10#include <botan/ecdh.h>
11#include <botan/numthry.h>
12#include <botan/internal/pk_ops_impl.h>
21class ECDH_KA_Operation
final :
public PK_Ops::Key_Agreement_with_KDF
25 ECDH_KA_Operation(
const ECDH_PrivateKey& key,
const std::string& kdf, RandomNumberGenerator& rng) :
26 PK_Ops::Key_Agreement_with_KDF(kdf),
27 m_group(key.domain()),
30 m_l_times_priv = m_group.inverse_mod_order(m_group.get_cofactor()) * key.private_value();
33 size_t agreed_value_size()
const override {
return m_group.get_p_bytes(); }
35 secure_vector<uint8_t> raw_agree(
const uint8_t w[],
size_t w_len)
override
37 PointGFp input_point = m_group.get_cofactor() * m_group.OS2ECP(w, w_len);
38 input_point.randomize_repr(m_rng);
40 const PointGFp S = m_group.blinded_var_point_multiply(
41 input_point, m_l_times_priv, m_rng, m_ws);
43 if(S.on_the_curve() ==
false)
48 const EC_Group m_group;
49 BigInt m_l_times_priv;
50 RandomNumberGenerator& m_rng;
51 std::vector<BigInt> m_ws;
56std::unique_ptr<PK_Ops::Key_Agreement>
58 const std::string& params,
59 const std::string& provider)
const
61 if(provider ==
"base" || provider.empty())
62 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 *)