10#include <botan/internal/blinding.h>
11#include <botan/internal/dl_scheme.h>
12#include <botan/internal/pk_ops_impl.h>
21 m_public_key = std::make_shared<DL_PublicKey>(
group, y);
25 return m_public_key->public_key_as_bytes();
29 return m_public_key->estimated_strength();
33 return m_public_key->p_bits();
37 return m_public_key->get_int_field(
algo_name(), field);
41 return m_public_key->group();
53 return m_public_key->DER_encode();
57 return m_public_key->check_key(rng, strong);
61 return std::make_unique<DH_PrivateKey>(rng,
group());
65 m_private_key = std::make_shared<DL_PrivateKey>(
group, rng);
66 m_public_key = m_private_key->public_key();
70 m_private_key = std::make_shared<DL_PrivateKey>(
group, x);
71 m_public_key = m_private_key->public_key();
76 m_public_key = m_private_key->public_key();
80 return std::unique_ptr<DH_PublicKey>(
new DH_PublicKey(m_public_key));
88 return m_private_key->DER_encode();
92 return m_private_key->raw_private_key_bits();
96 return m_private_key->get_int_field(
algo_name(), field);
106 DH_KA_Operation(
const std::shared_ptr<const DL_PrivateKey>& key,
107 std::string_view kdf,
109 PK_Ops::Key_Agreement_with_KDF(kdf),
111 m_key_bits(m_key->private_key().bits()),
113 m_key->group().get_p(),
115 [](const
BigInt& k) {
return k; },
116 [
this](
const BigInt& k) {
117 const BigInt inv_k =
inverse_mod(k, group().get_p());
118 return powermod_x_p(inv_k);
121 size_t agreed_value_size()
const override {
return group().p_bytes(); }
126 const DL_Group& group()
const {
return m_key->group(); }
128 BigInt powermod_x_p(
const BigInt& v)
const {
return group().power_b_p(v, m_key->private_key(), m_key_bits); }
130 std::shared_ptr<const DL_PrivateKey> m_key;
131 std::shared_ptr<const Montgomery_Params> m_monty_p;
132 const size_t m_key_bits;
137 BigInt v = BigInt::from_bytes(std::span{w, w_len});
139 if(v <= 1 || v >= group().get_p()) {
140 throw Invalid_Argument(
"DH agreement - invalid key provided");
143 v = m_blinder.
blind(v);
147 return v.
serialize<secure_vector<uint8_t>>(group().p_bytes());
153 std::string_view params,
154 std::string_view provider)
const {
155 if(provider ==
"base" || provider.empty()) {
156 return std::make_unique<DH_KA_Operation>(this->m_private_key, params, rng);
virtual OID object_identifier() const
T serialize(size_t len) const
BigInt blind(const BigInt &x) const
BigInt unblind(const BigInt &x) const
std::vector< uint8_t > public_value() const override
secure_vector< uint8_t > raw_private_key_bits() const override
const BigInt & get_int_field(std::string_view field) const override
secure_vector< uint8_t > private_key_bits() const override
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
size_t key_length() const override
bool check_key(RandomNumberGenerator &rng, bool strong) const override
std::unique_ptr< Private_Key > generate_another(RandomNumberGenerator &rng) const final
std::vector< uint8_t > public_value() const
std::vector< uint8_t > public_key_bits() const override
friend class DH_PrivateKey
AlgorithmIdentifier algorithm_identifier() const override
const BigInt & get_int_field(std::string_view field) const override
std::string algo_name() const override
const DL_Group & group() const
size_t estimated_strength() const override
std::vector< uint8_t > raw_public_key_bits() const override
int(* final)(unsigned char *, CTX *)
std::vector< T, secure_allocator< T > > secure_vector
BigInt inverse_mod(const BigInt &n, const BigInt &mod)