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) {
19 BER_Decoder(key_bits).decode(x);
23BigInt generate_private_dl_key(
const DL_Group& group, RandomNumberGenerator& rng) {
24 if(group.has_q() && group.q_bits() >= 160 && group.q_bits() <= 384) {
27 return BigInt(rng, group.exponent_bits());
31BigInt check_dl_private_key_input(
const BigInt& x,
const DL_Group& group) {
32 BOTAN_ARG_CHECK(group.verify_private_element(x),
"Invalid discrete logarithm private key value");
39 m_group(group), m_public_key(public_key) {}
42 std::span<const uint8_t> key_bits,
44 m_group(alg_id.parameters(), format), m_public_key(decode_single_bigint(key_bits)) {}
51 std::vector<uint8_t> output;
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_group.p_bits())) {}
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)
static BigInt random_integer(RandomNumberGenerator &rng, const BigInt &min, const BigInt &max)
T serialize(size_t len) const
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