10#include <botan/internal/blinding.h>
11#include <botan/internal/ct_utils.h>
12#include <botan/internal/dl_scheme.h>
13#include <botan/internal/pk_ops_impl.h>
14#include <botan/internal/pk_options_impl.h>
23 m_public_key = std::make_shared<DL_PublicKey>(
group, y);
27 return m_public_key->estimated_strength();
31 return m_public_key->p_bits();
35 return m_public_key->get_int_field(
algo_name(), field);
39 return m_public_key->group();
47 return m_public_key->public_key_as_bytes();
51 return m_public_key->DER_encode();
55 return m_public_key->check_key(rng, strong);
59 return std::make_unique<DH_PrivateKey>(rng,
group());
63 m_private_key = std::make_shared<DL_PrivateKey>(
group, rng);
64 m_public_key = m_private_key->public_key();
68 m_private_key = std::make_shared<DL_PrivateKey>(
group, x);
69 m_public_key = m_private_key->public_key();
74 m_public_key = m_private_key->public_key();
78 return m_private_key->check_key(rng, strong);
82 return std::unique_ptr<DH_PublicKey>(
new DH_PublicKey(m_public_key));
90 return m_private_key->DER_encode();
94 return m_private_key->raw_private_key_bits();
98 return m_private_key->get_int_field(
algo_name(), field);
108 DH_KA_Operation(
const std::shared_ptr<const DL_PrivateKey>& key,
111 PK_Ops::Key_Agreement_with_KDF(options),
113 m_key_bits(m_key->max_private_key_bits()),
115 m_key->group()._reducer_mod_p(),
117 [](const
BigInt& k) {
return k; },
118 [
this](
const BigInt& k) {
return powermod_x_p(group().inverse_mod_p(k)); }) {}
120 size_t agreed_value_size()
const override {
return group().p_bytes(); }
125 const DL_Group& group()
const {
return m_key->group(); }
127 BigInt powermod_x_p(
const BigInt& v)
const {
return group().power_b_p(v, m_key->private_key(), m_key_bits); }
129 std::shared_ptr<const DL_PrivateKey> m_key;
130 const size_t m_key_bits;
135 BigInt v = BigInt::from_bytes(std::span{w, w_len});
137 if(v <= 1 || v >= group().get_p() - 1) {
138 throw Invalid_Argument(
"DH agreement - invalid key provided");
141 const auto scope = CT::scoped_poison(m_key->private_key(), m_blinder);
143 v = m_blinder.
blind(v);
150 return v.serialize<secure_vector<uint8_t>>(group().p_bytes());
159 return std::make_unique<DH_KA_Operation>(this->m_private_key, options, rng);
virtual OID object_identifier() const
BigInt blind(const BigInt &x) const
BigInt unblind(const BigInt &x) const
std::vector< uint8_t > public_value() const override
bool check_key(RandomNumberGenerator &rng, bool strong) const override
std::unique_ptr< PK_Ops::Key_Agreement > _create_key_agreement_op(RandomNumberGenerator &rng, const PK_Key_Agreement_Options_Reader &options) 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
size_t key_length() const override
bool check_key(RandomNumberGenerator &rng, bool strong) const override
DH_PublicKey(const AlgorithmIdentifier &alg_id, std::span< const uint8_t > key_bits)
std::unique_ptr< Private_Key > generate_another(RandomNumberGenerator &rng) const final
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
void require_software_provider(const OptionsT &options, std::string_view algo_name)
std::vector< T, secure_allocator< T > > secure_vector