7#include <botan/internal/dl_scheme.h>
9#include <botan/assert.h>
10#include <botan/ber_dec.h>
11#include <botan/der_enc.h>
17BigInt decode_single_bigint(std::span<const uint8_t> key_bits) {
24 if(group.has_q() && group.q_bits() >= 160 && group.q_bits() <= 384) {
27 return BigInt(rng, group.exponent_bits());
32 BOTAN_ARG_CHECK(group.verify_private_element(x),
"Invalid discrete logarithm private key value");
42 std::span<const uint8_t> key_bits,
44 m_group(alg_id.parameters(), format), m_public_key(decode_single_bigint(key_bits)) {}
47 return m_public_key.serialize(m_group.p_bytes());
51 std::vector<uint8_t> output;
57 return m_group.verify_group(rng, strong) && m_group.verify_public_element(m_public_key);
61 return m_group.estimated_strength();
65 return m_group.p_bits();
70 m_private_key(check_dl_private_key_input(
private_key, m_group)),
71 m_public_key(m_group.power_g_p(m_private_key, m_private_key.bits())) {}
75 m_private_key(generate_private_dl_key(
group, rng)),
76 m_public_key(m_group.power_g_p(m_private_key, m_private_key.bits())) {}
79 std::span<const uint8_t> key_bits,
81 m_group(alg_id.parameters(), format),
82 m_private_key(check_dl_private_key_input(decode_single_bigint(key_bits), m_group)),
83 m_public_key(m_group.power_g_p(m_private_key, m_private_key.bits())) {}
94 return m_group.verify_group(rng, strong) && m_group.verify_private_element(m_private_key);
98 return std::make_shared<DL_PublicKey>(m_group, m_public_key);
103 return m_group.get_p();
104 }
else if(field ==
"q") {
105 return m_group.get_q();
106 }
else if(field ==
"g") {
107 return m_group.get_g();
108 }
else if(field ==
"y") {
117 return m_group.get_p();
118 }
else if(field ==
"q") {
119 return m_group.get_q();
120 }
else if(field ==
"g") {
121 return m_group.get_g();
122 }
else if(field ==
"x") {
123 return m_private_key;
124 }
else if(field ==
"y") {
#define BOTAN_ARG_CHECK(expr, msg)
BER_Decoder & decode(bool &out)
static BigInt random_integer(RandomNumberGenerator &rng, const BigInt &min, const BigInt &max)
secure_vector< uint8_t > get_contents()
DER_Encoder & encode(bool b)
DL_PrivateKey(const DL_Group &group, const BigInt &private_key)
const BigInt & private_key() const
secure_vector< uint8_t > DER_encode() const
const BigInt & get_int_field(std::string_view algo_name, std::string_view field) const
secure_vector< uint8_t > raw_private_key_bits() const
const DL_Group & group() const
std::shared_ptr< DL_PublicKey > public_key() const
bool check_key(RandomNumberGenerator &rng, bool strong) const
std::vector< uint8_t > public_key_as_bytes() const
const BigInt & get_int_field(std::string_view algo_name, std::string_view field) const
size_t estimated_strength() const
std::vector< uint8_t > DER_encode() const
bool check_key(RandomNumberGenerator &rng, bool strong) const
const BigInt & public_key() const
DL_PublicKey(const DL_Group &group, const BigInt &public_key)
const DL_Group & group() const
std::vector< T, secure_allocator< T > > secure_vector