7#include <botan/internal/dl_scheme.h>
8#include <botan/der_enc.h>
9#include <botan/ber_dec.h>
10#include <botan/assert.h>
16BigInt decode_single_bigint(std::span<const uint8_t> key_bits)
19 BER_Decoder(key_bits).decode(x);
23BigInt generate_private_dl_key(
const DL_Group& group, RandomNumberGenerator& rng)
25 if(group.has_q() && group.q_bits() >= 160 && group.q_bits() <= 384)
31 return BigInt(rng, group.exponent_bits());
35BigInt check_dl_private_key_input(
const BigInt& x,
const DL_Group& group)
38 "Invalid discrete logarithm private key value");
45 const BigInt& public_key) :
47 m_public_key(public_key)
52 std::span<const uint8_t> key_bits,
54 m_group(alg_id.parameters(), format),
55 m_public_key(decode_single_bigint(key_bits))
61 std::vector<uint8_t> bits(m_group.
p_bytes());
68 std::vector<uint8_t> output;
90 const BigInt& private_key) :
92 m_private_key(check_dl_private_key_input(private_key, m_group)),
93 m_public_key(m_group.power_g_p(m_private_key, m_private_key.bits()))
100 m_private_key(generate_private_dl_key(group, rng)),
101 m_public_key(m_group.power_g_p(m_private_key, m_private_key.bits()))
106 std::span<const uint8_t> key_bits,
108 m_group(alg_id.parameters(), format),
109 m_private_key(check_dl_private_key_input(decode_single_bigint(key_bits), m_group)),
110 m_public_key(m_group.power_g_p(m_private_key, m_group.p_bits()))
132 return std::make_shared<DL_PublicKey>(m_group, m_public_key);
136 std::string_view field)
const
139 return m_group.
get_p();
140 else if(field ==
"q")
141 return m_group.
get_q();
142 else if(field ==
"g")
143 return m_group.
get_g();
144 else if(field ==
"y")
151 std::string_view field)
const
154 return m_group.
get_p();
155 else if(field ==
"q")
156 return m_group.
get_q();
157 else if(field ==
"g")
158 return m_group.
get_g();
159 else if(field ==
"x")
160 return m_private_key;
161 else if(field ==
"y")
#define BOTAN_ARG_CHECK(expr, msg)
static BigInt random_integer(RandomNumberGenerator &rng, const BigInt &min, const BigInt &max)
static secure_vector< uint8_t > encode_locked(const BigInt &n)
static secure_vector< uint8_t > encode_1363(const BigInt &n, size_t bytes)
secure_vector< uint8_t > get_contents()
DER_Encoder & encode(bool b)
bool verify_private_element(const BigInt &x) const
const BigInt & get_p() const
bool verify_public_element(const BigInt &y) const
size_t estimated_strength() const
bool verify_group(RandomNumberGenerator &rng, bool strong=true) const
const BigInt & get_g() const
const BigInt & get_q() const
DL_PrivateKey(const DL_Group &group, const BigInt &private_key)
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
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
DL_PublicKey(const DL_Group &group, const BigInt &public_key)
std::vector< T, secure_allocator< T > > secure_vector